Diese Seite ist statisches HTML und am besten betrachtet mit Java-Script eingeschaltet!

D-BUS, Conky und Radiotray-NG

 ·  ☕ 3 Min. Lesen  ·  🤖 SWU

Der D-BUS ist Bestandteil von freedesktop.org und dient der Prozessinterkommunikation im Desktop.
Radiotray-NG ist eine simple, effiziente Webradio Desktop Applikation.
Siehe dazu auch Einträge in den Publikationen auf meiner Seite.

D-Bus Schnittstelle bei Radiotray-NG

Die github Webseite von Radiotray-NG gibt Informationen über das D-BUS Interface von Radiotray-NG an und freundlicherweise auch gleich ein Beispiel, wie man auf dem command line interface (CLI) einen informativen Befehl absetzt.

Conky’s Schnittstelle zu shell-scripten

Conky hat neben eigenen Schnittstellen außerdem die Möglichkeit, über periodische Aufrufe von Shellscripten Informationen zu erhalten. Mit diesen Informationen lässt sich einrichten, Conky über Radiotray-NG Zustände zu informieren und anzuzeigen.

Ziel: Conky station, title, artist und volume Informationen von Radiotray-NG anzeigen lassen

Es sind zwei shellscripte notwendig, damit zum einen die Informationen ermittelt werden und zum anderen, um sie auszugeben. Das erste Script wird auf Änderungen warten und ist deswegen überwiegend blockiert, weswegen es ausscheidet, kontinuierlich Informationen an Conky weiterzugeben. Daher schreibt es seine jeweils neuen Informationen in eine Textdatei, die von einem anderen Script ausgelesen und an Conky weitergegeben wird.

Einsammeln der JSON Daten von Radiotray-NG

Die Ausgabe von qdbus kann durch jq, einem Kommandozeilen JSON Prozessor geparst werden und erspart die Verwendung von anderen, vergleichsweise aufwändigeren Methoden. Damit wir nur dann Daten ermitteln, wenn Radiotray-NG eine Status-Wechsel mitteilt, wird gdbus verwendet.

Das Bash-Script radiotray.ng.watch.sh

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/bash
INTERFACE='com.github.radiotray_ng'
DIRPATH='/com/github/radiotray_ng'
MEMBER='org.freedesktop.DBus.Properties signal PropertiesChanged'

SIGNAL="/var/tmp/radiotray-NG.txt"

action() {
        echo $line | grep -q 4 && work || return 
}

work() {
        STATE=`qdbus com.github.radiotray_ng /com/github/radiotray_ng com.github.radiotray_ng.get_player_state`
        STATION=` echo $STATE | jq --args -r '.station'| fmt --width 29 - `
        ARTIST=` echo $STATE | jq --args -r '.artist'| fmt --width 29 - `
        TITLE=` echo $STATE | jq --args -r '.title'| fmt --width 29 - `
        VOLUME=` echo $STATE | jq --args -r '.volume'| fmt --width 29 - `
        OUT="♪$STATION:\nT: $TITLE\nA: $ARTIST\nV: $VOLUME%♪"

        if [[ $line =~ "*Stopped*" ]]
        then 
                $TITLE="Stopped"; 
                OUT="♪$STATION:\nT: $TITLE\nA: $ARTIST\nV: $VOLUME%♪"
        fi
        if [[ $line =~ "*Playing*" ]]
        then
                $TITLE="Playing"; 
                OUT="♪$STATION:\nT: $TITLE\nA: $ARTIST\nV: $VOLUME%♪"
        fi

        echo -e $OUT > $SIGNAL
}

gdbus monitor --session --dest $INTERFACE $DIRPATH $MEMBER | \
(               while read line; do 
                        action $line
                done
)

Das Shell-Script radiotray.ng.conky.sh

1
2
3
4
#!/bin/sh
SIGNAL="/var/tmp/radiotray-NG.txt"
pgrep -fl "radiotry-ng.watcher.sh" >/dev/null || nohup bin/radiotry-ng.watcher.sh > /var/tmp/radiotray.ng.conky.out &
cat $SIGNAL

Der Eintrag in der Conky-Datei

1
${execp ~/bin/radiotray.ng.conky.sh}

Ausgabebeispiel der Datei radiotray-NG.txt

1
2
3
4
♪  DubStep Beyond:
T: Onoff (Original Mix)
A: Nibe
V: 3% ♪

wüsti
Author
SWU
human