本文整理汇总了Python中mpd.MPDClient.playlistfind方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.playlistfind方法的具体用法?Python MPDClient.playlistfind怎么用?Python MPDClient.playlistfind使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.playlistfind方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: validate_in_playlist
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistfind [as 别名]
def validate_in_playlist(filename):
c = MPDClient()
c.connect("localhost", 6600)
if not len(c.playlistfind("file", filename)):
raise forms.ValidationError(
"Voted Track is no longer in the playlist."
)
c.disconnect()
示例2: validate_exists_and_is_not_in_playlist
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistfind [as 别名]
def validate_exists_and_is_not_in_playlist(filename):
c = MPDClient()
c.connect("localhost", 6600)
if len(c.playlistfind("file", filename)):
raise forms.ValidationError("Song is already in the playlist.")
elif not len(c.find("file", filename)):
raise forms.ValidationError("Song not found.")
c.disconnect()
示例3: get_track
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistfind [as 别名]
def get_track(filename, in_playlist=True, client=None):
if not client:
c = MPDClient()
c.connect("localhost", 6600)
else:
c = client
if in_playlist:
track = c.playlistfind('file', filename)
else:
track = c.find('file', filename)
track = track[0] if track else None
if track and 'artist' not in track:
track['artist'] = ""
if track and 'title' not in track:
track['title'] = title_from_filename(track['file'])
return track
示例4: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import playlistfind [as 别名]
class MPDApi:
def __init__(self, host='localhost', port='6600'):
self.__api = MPDClient()
self.__api.connect(host, port)
self.__song_db = {}
# If there are songs in the MPD queue, rebuild their info.
for file_ in self.__api.playlist():
file_ = file_[6:]
song = self.playlist_find(file_)
song_dict = self.translate_song(song)
self.__song_db[file_] = song_dict
@property
def queue(self):
queue = []
if self.__api.currentsong():
current_pos = int(self.__api.currentsong()['pos'])
queue = self.__api.playlist()[current_pos:]
return map(lambda x: x[6:], queue)
@property
def current_song(self):
track = self.__api.currentsong()
if track:
return self.song_db.get(track['file'])
return None
@property
def song_db(self):
return self.__song_db.copy()
def __state(self):
return self.__api.status()['state']
def request_song_from_api(self, search):
search_result = self.__api.search('title', search)
result = None
if search_result:
result = self.translate_song(search_result[0])
self.__song_db[result['SongID']] = result
return result
def queue_song(self, file_):
if self.__state == 'stop' and len(self.queue) == 0:
self.__api.playid(self.playlist_find(file_)['id'])
else:
self.__api.add(file_)
def auto_play(self):
if self.__state() == 'stop' and not len(self.queue) == 0:
while True:
random_song = 'file: %s' % choice(self.__api.list('file'))
if random_song not in self.__api.playlist():
self.queue_song(random_song)
break
def remove_queue(self, file_):
song = self.playlist_find(file_)
if song:
self.__api.delete(song['pos'])
return True
return False
def translate_song(self, song_dict):
result = dict(SongID=song_dict['file'])
for key, tag in dict(SongName='title', ArtistName='artist',
AlbumName='album').items():
try:
result[key] = util.asciify(song_dict[tag])
except:
# This song does not have that key. Probably a .wav
pass
return result
def playlist_find(self, filename):
song = self.__api.playlistfind('file', filename)
if song:
return song[0]
return None
###### API CALLS #######
def api_pause(self):
"""
Pauses the current song
Does nothing if no song is playing
"""
self.__api.pause()
def api_play(self):
"""
Plays the current song
If the current song is paused it resumes the song
If no songs are in the queue, it does nothing
"""
if self.__state() == 'pause':
self.__api.play()
else:
self.auto_play()
#.........这里部分代码省略.........