当前位置: 首页>>代码示例>>Python>>正文


Python Library.append方法代码示例

本文整理汇总了Python中Library.append方法的典型用法代码示例。如果您正苦于以下问题:Python Library.append方法的具体用法?Python Library.append怎么用?Python Library.append使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Library的用法示例。


在下文中一共展示了Library.append方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import Library [as 别名]
# 或者: from Library import append [as 别名]
class Tunz:

	def __init__(self):
		self.dir = os.getcwd()
		self.library = Library(self.dir)
		#self.musicPlayer = threading.Thread(target=MusicPlayer.__init__, args = [self.library])
		self.musicPlayer = MusicPlayer(self.library)
		self.musicPlayer.start()
		self.commandList = "download (song) - downloads a song to your library \nlist (songs/playlists) [start] - Lists your songs or playlists, optionally starting with certain character(s) \ncreate playlist (name) - creates a playlist with given name \nadd (song) :: (playlist) - adds given song in your library to given playlist \nshuffle [playlist] - shuffles your main library or a specific playlist \nplay (song/playlist) - plays the current music if no argument give, or plays a song or a playlist \ndelete (song/playlist) - removes a song or a playlist \npause - pauses the music \nrewind - rewinds the music \nskip - skips to the next song\ninfo - gives info about Tünz \nexit - exits Tünz"


	#A method to change directories to the main Tünz directory. It will first check if it is in that directory, and if it's not it cds into it
	def mainDir(self):
		print ""+os.getcwd()
		print self.dir
		if os.cwdir() == self.dir:
			print "in directory"
		else:
			print "changing"
			os.chdir('..')

	#A method to change directories to the Tünz Library directory. It will first check if it is in that directory, and if it's not it cds into it
	def libDir(self):
		print ""+os.getcwd()
		print self.dir
		if os.getcwd() != self.dir:
			print "in directory"
		else:
			print "changing"
			os.chdir('Tünz Library')

	#loads all the songs in your library into an array to be used for playing the songs and displaying them
	def updateLibrary(self):
		self.library = []
		for song in next(os.walk('.'))[1]:
			self.library.append(song)
		self.library.sort()

	def queueSongs(self):
		i = self.library.index(self.currentSong)
		for song in self.library[i:]:
			mixer.music.queue(song+"/"+song+".mp3")

	def queueSong(self,song):
		mixer.music.queue(song+"/"+song+".mp3")

	#download a song based by the name given in the command
	def download(self,command):
		#NOTE check input
		currentDL = Download(command,self.library) #passes reference to library so it can check if things are already in the library and stop the process
		if currentDL.downloadedSuccessfully():
			self.library.addSong(currentDL.getSong())
			print "[!] DONE!"
		else:
			print "[!] ERROR WHILE DOWNLOADING"

	def goto(self,command):
		if len(command) == 2:
			if self.playing:
				mixer.music.play(0,(int(command[1])))
			else:
				print "[x] Nothing playing!"
		else:
			print "[x] format of 'goto' is goto (time)"

	def play(self,command):
		self.musicPlayer.play(command)

	def add(self,command):
		if self.manualQueue:
			if len(command) == 1:
				print ("[x] Syntax for add - 'add (song)")
			else:
				command.remove(command[0])
				command = "_".join(command)
				if command in self.library:
					#try:
					#mixer.music.load(command+"/"+command+".mp3")
					self.queueSong(command)
					print "[+] Song queued!"
					#except:
				else:
					print "[x] Song isn't in your library"
		else:
			print "[x] manual queue is not on. Use 'queue manual' to switch"

	def pause(self):
		self.musicPlayer.pause()

	def stop(self):
		self.musicPlayer.stop()

	def list(self,command):
		if len(command) == 2:
			if command[1] == "songs":
				self.library.listSongs()
			elif command[1] == "playlists":
				self.library.listPlaylists()
			else:
				print "[x] format for 'list' - list (song/playlist) [start/contains]"
#.........这里部分代码省略.........
开发者ID:importUsername,项目名称:Tunz,代码行数:103,代码来源:Tünz2.py


注:本文中的Library.append方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。