gpt4 book ai didi

mpd mpc 查询语言

转载 作者:行者123 更新时间:2023-12-01 23:17:07 25 4
gpt4 key购买 nike

我不知道如何使用 mpc 正确查询 mpd

例如:我知道如何列出所有专辑

mpc list album

但我想要的不仅仅是名字。

如何查询 mpd 的专辑、路径、艺术家、轨道编号、持续时间等?最好在一个查询中,但多个查询也可以。

我尝试阅读 mpc 手册页和 mpd 的官方文档,但无法弄清楚。

最佳答案

 import audioscrobbler
import mpd
import random
import time


lastsong = {}

def timer_control():
get_similar()
time.sleep(10)
timer_control()

def get_similar():
audioscrobbler
client = mpd.MPDClient()
client.connect("localhost", 6600)
mpdstatus = client.status()
prevsonginfo = client.currentsong()
global lastsong
if mpdstatus['state'] == "stop": return
if prevsonginfo == lastsong: return

lastsong = prevsonginfo
similarartists = ""
song = prevsonginfo
#if not song: break #No song, do nothing
prevartist = song['artist']

# Is the info already cached?
similar_cache = {}
if similar_cache.has_key(prevartist):
similarartists = similar_cache[prevartist]
else:
#Not cached so fetch from Audioscrobbler
try:
similarartists = [artist.name for artist in audioscrobbler.AudioScrobblerQuery(artist=prevartist).similar()]
# Cache search results and save some time next search
similar_cache[prevartist] = similarartists
except audioscrobbler.AudioScrobblerError:
similar_cache[prevartist] = None # Empty cache
return # Do nothing!

if not similarartists: return # Empty list

# Split list in half and sort upper half
# this means good matches will have priority
# but makes sure artist A does not always result in artist B
half_idx = len(similarartists)/2
upperhalf = similarartists[:half_idx]
lowerhalf = similarartists[half_idx:]
random.shuffle(upperhalf)
artistlist = upperhalf
artistlist.extend(lowerhalf)
# Try each artist in order
for artist in artistlist:
try:
print "Trying:",artist
songs = client.search("artist", artist)
if not songs: continue
selected_song = random.sample(songs, 1)[0]
client.add(selected_song['file'])
print "Added", selected_song['title'],"by",selected_song['artist']
# Delete old song from playlist?
break
except mpd.MPDError, e:
print "MPDError", e.message
continue
except ValueError, e:
print "ValueError:",e.message
continue


timer_control()

关注这篇文章以获取更多信息 https://bbs.archlinux.org/viewtopic.php?id=49765 http://manpages.ubuntu.com/manpages/intrepid/man1/mpc.1.html

关于mpd mpc 查询语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31471580/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com