This page looks best with JavaScript enabled

D-BUS, Conky and Radiotray-NG

 ·  ☕ 3 min read  ·  🤖 SWU

The D-BUS is part of freedesktop.org that enables process interkommunication at the desktop.
Radiotray-NG is a simple, efficient webradio desktop application.
See entries at the publications at my site.

D-Bus interface of Radiotray-NG

Radiotray-NG’s github website has information about the D-BUS interface of Radiotray-NG and kindly shows, how to use the command line interace (cli) to set up an useful command about it.

Conky’s shell-script interface

Aside Conky’s internal commands there are some calling shell-scripts periodically that you can use to get Radiotray-NG’s state and show it at the conky window.

Objective: Show station, title, artist und volume states of Radiotray-NG at the Conky window

There are two shell-scripts needed, one to gain the state and the other to tell it. The first scipt will be waiting for change of state, being blocked most of the time, so it can’t be used to inform conky constantly. That’s why it has to write new states to a file, the other script reads and tells conky.

Collecting the JSON data from Radiotray-NG

The output of qdbus can be sent to jq, a command line JSON processor to parse it more easily than other, well known parser tools do, that want more complicated methods. To determine data only on state change of Radiotray-NG gdbus is used.

The 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
)

The 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

The entry at the Conky configuration file

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

Example of the file radiotray-NG.txt

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

wüsti
WRITTEN BY
SWU
human