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


Python MPDClient.search方法代码示例

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


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

示例1: test

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import search [as 别名]
def test():
    """
    ## TODO:     Test qui ne fonctionne que sur mon ancienne instalation
        A refaire
    """
    #pod='http://podcast.college-de-france.fr/xml/histoire.xml'
    pod="http://radiofrance-podcast.net/podcast09/rss_11074.xml"
    w=MPDPodcast(podcast_path="/media/Disque_2/mp3/laurent/Podcast")
    w.add_flux(pod)
    w.print_flux()
    w.remove_item(1)
    #w.remove_flux(1)
    #w.print_items(1)
    path=w.download_item(3)

    #Made the item readed
    path=path.split("/")[-2:]
    path=os.path.join(path[0], path[1])
    client=MPDClient()
    client.connect('localhost', 6600)
    song,=client.search('file', path)
    client.sticker_set('song', song['file'], 'last_up',int(song['time']))
    w.check_item()
    w.purge_readed()
    #    w.remove_dowloaded_item(3)
    w.remove_item(4)

    w.update()
开发者ID:RaoulChartreuse,项目名称:mpd_bookmark,代码行数:30,代码来源:mpd_podcast.py

示例2: stderr_print

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import search [as 别名]
            client.setvol(new_volume)

b = sys.argv[4].find("SEARCH")
if b != -1:
    text = sys.argv[4][b:]

    e = text.find('\n')
    if e != -1:
        text = text[:e]

    text = text.split(' ')
    field = text[1].lower()
    text = ' '.join([ t for t in text[2:]])

    stderr_print("Search results for %s" % text)
    results = client.search(field, text)

    for line in results:
        artist = 'Unknown'
        album = 'Unknown'
        title = 'Unknown'

        try:
            artist = line['artist']
            album = line['album']
            title = line['title']
        except KeyError:
            pass

        stderr_print('%s - %s - %s' % (artist, album, title))
开发者ID:nathan-hoad,项目名称:makeme,代码行数:32,代码来源:mpd-remote.py

示例3: MPDClient

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import search [as 别名]
	host = "localhost"
	port = "6600"
	passwd = "" # Leave blank if no password used.
	
	m  = MPDClient()
	try:
		m.connect(host,port)
	except IOError:
		print "Connection error."
		exit(1)
		
	if passwd:
		try:
			m.password(passwd)
		except CommandError:
			print "Authentication error."
			m.disconnect()
			exit(1)

	for i in tsv(argv[1]):
		results = m.search("artist", i[0], "title", i[1])
		if results != []:
			m.add(results[0]["file"])
		else:
			print "File not in DB: %s" % i

	m.close()
	m.disconnect()
	exit(0)

开发者ID:yimmu,项目名称:Last.fm-mpd-utility,代码行数:31,代码来源:lastfm_mpc.py

示例4: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import search [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()

#.........这里部分代码省略.........
开发者ID:Qalthos,项目名称:groovebot,代码行数:103,代码来源:MPDApi.py


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