我想做
here所描述的相同的事情,但使用shell脚本(最好是在bash中)而不是python.看起来这样的事情应该可以使用dbus-monitor,但我对dbus并不是很熟悉,而且我不清楚如何将解决方案中描述的概念应用于python问题并将它们应用于dbus-监控工具.
这是我能找到的最简单的方法:
#!/bin/bash interface=org.gnome.RhythmBox.Player member=playingUriChanged # listen for playingUriChanged DBus events,# each time we enter the loop,we just got an event # so handle the event,e.g. by printing the artist and title # see rhythmBox-client --print-playing-format for more output options dbus-monitor --profile "interface='$interface',member='$member'" | while read -r line; do printf "Now playing: " rhythmBox-client --print-playing done
它产生如下输出:
Now playing: Daft Punk - Overture Now playing: Daft Punk - The Grid
它还会在启动时打印当前正在播放的歌曲.如果那不是您想要的,请查看$line的内容,看看它是否包含NameAcquired或playingUriChanged.如果它包含NameAcquired,请跳过它.
Python版本和这个bash版本之间的主要区别在于Python版本使用DBus来获取播放歌曲信息.我找不到使用bash做到这一点的好方法,但是rhythmBox-client –print-playing似乎运行良好.
原文地址:https://www.jb51.cc/bash/383937.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。