bashを使用してトラック変更のためにRhythmboxを継続的に監視する方法

StackOverflow https://stackoverflow.com/questions/5344390

  •  27-10-2019
  •  | 
  •  

質問

説明されているのと同じことをしたい ここ, 、しかし、Pythonの代わりにシェルスクリプト(できればBashで)を使用します。そのようなことは使用可能であるべきだと思われます 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バージョンがDBUを使用して再生ソング情報を取得することです。 Bashを使用してそれを行う良い方法を見つけることができませんでしたが rhythmbox-client --print-playing うまく機能しているようです。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top