如何使用python从pianobar检索当前歌曲名称和剩余时间?
我正在raspberry pi上使用TKinter和python创建一个带有gui的闹钟。当闹钟响的时候,我想让它开始演奏钢琴。我可以很容易地做到这一点,但我还想在GUI上显示歌曲的名称,我不知道如何播放当前歌曲。我曾尝试使用管道“|”,并使用“>”重定向,但我一无所获。任何建议都会有帮助。您需要使用事件命令界面。从手册页: 在pianobar的源发行版的contrib/目录中可以找到一个示例脚本 ~/.config/pianobar:如何使用python从pianobar检索当前歌曲名称和剩余时间?,python,unix,tkinter,raspberry-pi,pandora,Python,Unix,Tkinter,Raspberry Pi,Pandora,我正在raspberry pi上使用TKinter和python创建一个带有gui的闹钟。当闹钟响的时候,我想让它开始演奏钢琴。我可以很容易地做到这一点,但我还想在GUI上显示歌曲的名称,我不知道如何播放当前歌曲。我曾尝试使用管道“|”,并使用“>”重定向,但我一无所获。任何建议都会有帮助。您需要使用事件命令界面。从手册页: 在pianobar的源发行版的contrib/目录中可以找到一个示例脚本 ~/.config/pianobar: user = <username> passw
user = <username>
password = <password> (although I'd suggest password_command)
event_command = ~/.config/pianobar/event_command.py
这将在新歌开始时将歌曲信息写入~/.config/pianobar/nowplaying(手册页中还有其他可用事件)。然后,您可以使用您选择的工具来解析它,以获取歌曲标题
#!/usr/bin/env python
import os
import sys
from os.path import expanduser, join
path = os.environ.get('XDG_CONFIG_HOME')
if not path:
path = expanduser("~/.config")
else:
path = expanduser(path)
fn = join(path, 'pianobar', 'nowplaying')
info = sys.stdin.readlines()
cmd = sys.argv[1]
if cmd == 'songstart':
with open(fn, 'w') as f:
f.write("".join(info))