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


Python MPDClient.sticker_get方法代码示例

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


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

示例1: main

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_get [as 别名]
def main(action, uri, name, value):
    client = MPDClient()
    client.connect(HOST, PORT)
    if PASS:
        client.password(PASS)

    if action == "get":
        print client.sticker_get("song", uri, name)
    if action == "set":
        client.sticker_set("song", uri, name, value)
    if action == "delete":
        client.sticker_delete("song", uri, name)
    if action == "list":
        stickers = client.sticker_list("song", uri)
        for sticker in stickers:
            print sticker
    if action == "find":
        matches = client.sticker_find("song", uri, name)
        for match in matches:
            if "file" in match:
                print match["file"]
开发者ID:abednarski79,项目名称:mpd-lirc,代码行数:23,代码来源:GoodCommandExample.py

示例2: get_mpd_library_dir

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_get [as 别名]
	libdir = get_mpd_library_dir(MPD_CONF)

	total_files_updated = 0
	total_files_skipped = 0
	total_image_size    = 0

	for song in client.listallinfo(''):
		if not 'file' in song:
			continue

		file_rel = song['file']

		if skip_tagged:
			# Awful, I know. But the sticker_find() function did not do much.
			try:
				client.sticker_get('song', file_rel, 'image-nchunks')
				# Track has art, skip it.
				total_files_skipped += 1
				continue
			except:
				# Track has no art.
				pass

		file_abs = os.path.join(libdir, file_rel)
		img_data = get_art_base64(file_abs, IMG_SIZE)

		if img_data is None:
			total_files_skipped += 1
			continue
		print('Updating %s, size=%s' % (file_rel, len(img_data)))
开发者ID:polyfloyd,项目名称:trollibox,代码行数:32,代码来源:mpd-artwork.py

示例3: __init__

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_get [as 别名]
class TestBookmark:
    
    def __init__(self):
        #Fill there
        self.testHost="localhost"
        self.testPort=6600
        self.testPass=None
        self.testMotif=""
        self.testField="file"
        #Test songs must last more than 30s
        self.song1="Jacques Brel/Album/11-Vierson.mp3"
        self.song2="Cream/Cream - 2000 - The Millenium Collection - [V2]/07 - Tales Of Brave Ulysses.mp3"

    #Before every test
    def setup(self):
        print "Connection to MPD .........",
        self.client=MPDClient()
        self.client.connect(self.testHost,self.testPort)
        if self.testPass:
            self.client.password(self.testPass)
        print "Done"
        self.client.clear()
        self.volume=self.client.status()['volume']
        self.client.setvol(0)
        self.client.consume(0)
        self.client.sticker_set('song', self.song1, 
                                'last_up', 0)
        self.client.sticker_set('song', self.song2, 
                                'last_up', 0)
        self.launch_bookmark()


    #After every test
    def teardown(self):
        self.client.clear()
        self.client.setvol(self.volume)
        print "Disconect MPD .............",
        self.client.disconnect() 
        print "Done"
        self.kill_bookmark()
       

    def launch_bookmark(self):
        self._thread=threading.Thread(None, MPDBookmark, None, (),
                                      {'host':self.testHost,
                                       'port':self.testPort,
                                       'password':self.testPass,
                                       'motif':self.testMotif,
                                       'field':self.testField})
        self._thread.start()
        print "Launch done"

    def kill_bookmark(self):
        self._thread._Thread__stop()
        print "kill done"

    def test_Version(self):
        print "Version :    ",
        print self.client.mpd_version
        #assert self.client.mpd_version=='0.18.0'
 
        
    def test_cold_start(self):
        print "cold start"
        self.client.add(self.song1)
        Ti=time.time()
        self.client.play()
        time.sleep(6)
        self.client.pause()
        Tf=time.time()
        time.sleep(2)#Wait a bit the writing in MPD sticker
        read_time=int(self.client.sticker_get('song',  self.song1, 'last_up'))
        real_time=Tf-Ti
        print "abs(read_time-real_time) ",
        print "read time :", read_time,
        print "real time :", real_time,
        print "  = ",abs(read_time-real_time)
        assert abs(read_time-6)<=2.
        assert abs(read_time-real_time)<=2.



    def test_pause(self):
        p1=5
        p2=2
        print "pause"
        self.client.add(self.song1)
        self.client.play()
        time.sleep(p1)
        self.client.pause()
        time.sleep(2)
        self.client.play()
        time.sleep(p2)
        self.client.stop()
        time.sleep(2)#Wait a bit the writing in MPD sticker
        read_time=int(self.client.sticker_get('song',  self.song1, 'last_up'))
        print read_time, "vs", p1+p2
        assert abs(read_time-(p1+p2))<=2.

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

示例4: MPDBookmark

# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_get [as 别名]
class MPDBookmark(object):
    def __init__(self, host="localhost", port=6600, password=None,
                 motif="Podcast", field="album"):
        self.client = MPDClient()
        try:
            self.client.connect(host, port)
            if password:
               self.client.password(password) 
            
        except :
            print "merde"
            print "host = ", host
            print "port = ", port
            print "pass = ", password
            assert False
        self.motif=motif
        self.field=field
        self.boucle()

    def stats(self):
        print "==========================================="
        print "                Version :"
        print self.client.mpd_version
        print "==========================================="
        print "fin du test"
        print self.client.status()


    def wait_action(self):
        self.client.send_idle('player')
        select([self.client], [], [], 60)
        return self.client.fetch_idle()

    
    def verif_motif(self, song):
        return  self.field in song and re.match(self.motif, song[self.field])

    
    def update_song(self, song, ts):
        new_ts=time.time()
        if 'title' in song :
            print "Update song : ", song['title'],
            print "( ",int(new_ts-ts),
            print "/",song['time']," )"
        if self.verif_motif(song):
            last_up=int(new_ts-ts)
            self.client.sticker_set('song', song['file'], 
                                    'last_up', last_up)
    
    def start_song(self, new_song):
        if ('file' in new_song) and 'last_up' in self.client.sticker_list('song', new_song['file']):
            last_up=int(self.client.sticker_get('song', 
                                                new_song['file'], 
                                                'last_up'))
            if abs(int(new_song['time'])-last_up)<=4 :
                last_up=0
            self.client.seekcur(last_up)


    def boucle(self):
        

        state=self.client.status()['state']
        song=self.client.currentsong()
        print "song  :  ", song
        ts=time.time()
        if 'elapsed' in song :
            ts-=float( song['elapsed'])

        while 1 :
            ret=self.wait_action()
            new_state=self.client.status()['state']
            new_song=self.client.currentsong()

            if new_song!=song and new_song!={}:
                self.start_song(new_song)

            if song !={}:
                print "update  ",
                self.update_song(song, ts)

            state= new_state
            song= new_song
            if 'elapsed' in self.client.status():
                ts=time.time()-float( self.client.status()['elapsed'])
开发者ID:RaoulChartreuse,项目名称:mpd_bookmark,代码行数:87,代码来源:mpd_bookmark.py


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