加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

如何使用bash连续监控rhythmbox的音轨变化

发布时间:2020-12-16 01:23:12 所属栏目:安全 来源:网络整理
导读:我想做 here所描述的相同的事情,但使用shell脚本(最好是在bash中)而不是python.看起来这样的事情应该可以使用dbus-monitor,但我对dbus并不是很熟悉,而且我不清楚如何将解决方案中描述的概念应用于python问题并将它们应用于dbus-监控工具. 这是我能找到的最简
我想做 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似乎运行良好.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读