本文整理汇总了Python中mpd.MPDClient.sticker_set方法的典型用法代码示例。如果您正苦于以下问题:Python MPDClient.sticker_set方法的具体用法?Python MPDClient.sticker_set怎么用?Python MPDClient.sticker_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mpd.MPDClient
的用法示例。
在下文中一共展示了MPDClient.sticker_set方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_set [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()
示例2: main
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_set [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"]
示例3: __init__
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_set [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.
#.........这里部分代码省略.........
示例4: len
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_set [as 别名]
total_files_updated += 1
total_image_size += len(img_data)
# If the size of the image is too big, MPD will tell us to fuck off
# when its input buffer is saturated.
# This has been solved by splitting the image data into smaller chunks.
# Alternatives:
# - Compile MPD ourselves with a bigger buffer.
# - Modify MPD's sqlite sticker database without using MPD and hope the
# transmitbuffer is bigger.
# - Start a webserver and just save an URL in the sticker
chunks = []
chunk_size = 6 * 1024
for i in range(0, len(img_data), chunk_size):
if i+chunk_size <= len(img_data):
chunk = img_data[i:i+chunk_size]
else:
chunk = img_data[i:]
chunks.append(chunk)
client.sticker_set('song', file_rel, 'image-nchunks', str(len(chunks)))
for (i, chunk) in enumerate(chunks):
client.sticker_set('song', file_rel, 'image-'+str(i), chunk)
client.close()
client.disconnect()
print('%s files skipped' % total_files_skipped)
print('%s files updated' % total_files_updated)
print('%s KB total image size' % (round(total_image_size / 1024, 2)))
示例5: MPDBookmark
# 需要导入模块: from mpd import MPDClient [as 别名]
# 或者: from mpd.MPDClient import sticker_set [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'])