This cantata build synchronizes the state of the scrobble button across players connected to the same MPD host. It is implemented using few scripts and two services
-
cantata-mpc (script) - This script is called by cantata when you click the love button. Each click toggles the operation. First click turns on love and next click turns off love. The cantata-script creates a mpd channel named scrobble and sends a message love or unlove depending on the state of the love button. The cantata-mpc script uses the script /usr/bin/karma from the mpdev package and the mpc command from the mpc package as below.
# scrobble love state for the song on last.fm, libre.fm # it is need to set last.fm token one time on the host by # running moc-scrobbler from mpdev package $ MPD_HOST=$MPD_HOST /usr/bin/karma --love || /usr/bin/karma --love # create a mpd channel named scrobble. $ mpc --host="$MPD_HOST" sendmessage scrobble love || mpc sendmessage scrobble love
-
cantata modifications - Cantata has been modified to achieve love syncronization.
i) The first modification is fixing the love button state bug where the button remains in love state once you click it. You cannot unlove the song. Now when you click the button the first time, cantata changes the color of the button to solid white and runs the script $HOME/bin/cantata-mpc with the argument love. When you click it again to change the state to unlove, the script cantata-mpc is called with the argument unlove). ii) Second modification that has been done is that cantata writes the mpd host to which it is connected in the file $HOME/.config/MPD_HOST. iii) Third modification is addition of signal handlers SIGUSR1 and SIGUSR2. The signal SIGUSR1 toggles the state of love button to love and SIGUSR2 turns on the state to unlove.
-
scrobble-button service - This service is setup as a supervised service using supervise(8). You need to install the daemontools package to have supervise(8) installed. This service runs a script named $HOME/bin/scrobble-button. The run file for supervise is as below. The scrobble-button service is implemented by the scrobble-button shell script in the aux-scripts directory. You need to replace mbhangui with your login name in the supervise run file.
#!/bin/sh user=mbhangui exec 2>&1 home=$(getent passwd $user | awk -F: '{print $6}') exec /usr/bin/setuidgid -s $user env HOME=$home $home/bin/scrobble-button
The scrobble-button script runs tcpclient to connect to port 6600 of the host in $HOME/.config/MPD_HOST and subscribes to the mpd channel named scrobble and waits for love, unlove message on the channel. When it sees the love message on the channel, it sends SIGUSR1 to cantata. When it sees the unlove message on the channel, it sends SIGUSR2 to cantata. You can run scrobble-button in the background using your own favourite method instead of using supervise.
When you play a song, it invokes emotions. For many, these emotions can be enhanced by simple things like displaying Album artwork, song information like the Title, Artist, Album name, Song Duration, date when you added the song to the collections, date when you last played the song, how many times have you played the song and how much you love or hate the song. Cantata doesn't display many of the mentioned information. Partly it is because many of this information is not stored by both cantata and mpd. If you install the mpdev package, lot of this missing information gets stored in a sqlite database when you play a song using mpd. However cantata doesn't have the ability to display all this information. This service supplements what is being displayed in the cantata screen by creating a popup for few seconds to display information like last played, play count, date added, rating, etc. This is implemented by a supervise(8) service named notify-screen. This service uses the mpc idle command to detect song change. Whenever a new song starts getting played, this service fetches all information about the song from mpd database, mpd sqlite sticker.db database and mpdev sqlite stats.db database, It also connects to last.fm and fetches the 'love' status for the song. If the song is loved, it sends a message to the mpd channel named scrobble. The scrobble-button service mentioned above is subscribed to the mpd channel scrobble. When it sees the 'love' message, it sends SIGUSR1 to cantata to turn on the 'love' button.
The information displayed in the popup is like below
title = There's A Boat Dat's Leavin' Soon For New York
play_count = 3
Last Played = Tuesday 08 February 2022 11:14:04 PM IST
Last Played = 2 years 342 days 1 hr 12 min 52 sec ago
rating = 6
karma = 50
Duration = 4 min 55 sec (295)
artist = Ella Fitzgerald and Louis Armstrong
album = Porgy & Bess
track = 13
genre = Vocal Jazz
date = 1958
composer =
performer =
disc =
Date Added = 2021-04-23 19:27:56
Last Updated = 2021-04-23 19:27:56
The notify-send service is implemented by the notify-send shell script in the aux-scripts directory. The supervise run file for notify-send service is as below. You need to replace mbhangui with your login name in the supervise run file.
#!/bin/sh
#
# This requires yad to be installed.
# Look at $home/bin/notify-screen
#
user=mbhangui
exec 2>&1
mkdir -p /run/notify-screen
home=$(getent passwd $user | awk -F: '{print $6}')
if [ ! -f $home/.config/cantata/MPD_HOST ] ; then
echo "MPD_HOST not defined" 1>&2
sleep 30
exit 1
fi
chown $user /run/notify-screen
if [ -d /run/svscan/scrobble-button/supervise ] ; then
chown -R $user /run/svscan/scrobble-button/supervise
elif [ -d /svscan/scrobble-button/supervise ] ; then
chown -R $user /svscan/scrobble-button/supervise
fi
if [ -d /run/svscan/notify-screen/supervise ] ; then
chown -R $user /run/svscan/notify-screen/supervise
elif [ -d /svscan/notify-screen/supervise ] ; then
chown -R $user /svscan/notify-screen/supervise
fi
/usr/bin/setuidgid -s $user /usr/bin/envdir variables xhost +
exec /usr/bin/setuidgid -s $user /usr/bin/envdir variables $home/bin/notify-screen
If you install the daemontools, ucspi-tcp package from open build service using dnf, yum, apt, etc you just need to execute create_service script in the aux-scripts directory.
NOTE:
- install mpc, sqlite3, imagemagick, yad, xmllint, mpdev, daemontools
- update /etc/ImageMagick-6/policy.xml the following line to have read|write
<policy domain="path" rights="read|write" pattern="@*"/>