More > JRiver Media Center 21 for Linux

MC_Notifier - a simple Linux system notification script for MC (using libnotify)

(1/2) > >>

mwillems:
I cooked this up in another thread, but thought it might be generally useful, at least as a point of departure.

MC_Notifier is a bash script that submits a libnotify notification on track change in MC (which show as a floating window on many linux desktop environments).  It will show the Artist,  Album, and Track title.  By default it runs every two seconds, but you can change that easily by modifying the "sleep" parameter (if you want it to be more responsive or eat fewer cycles).  With a little more work, it might even be able to show album art, but that's a bit more work than I have time for at the moment.  It will run until you kill it, so is suitable to launch with your DE's startup.  

The script is kind of trivial, and it's not perfect; it performs a single very basic data validation step.  So far it seems to cope with some of the usual suspects (ampersands, single quotes, double quotes, and dollar signs) just fine but it may act strangely when encountering strange characters in album titles, etc.  Folks could easily make it more efficient, robust, and/or add more functionality, and I may add a few things myself over time (I have a few optimization ideas that I'll fold in myself time permitting).  This is intended as a proof of concept, and is provided as is with no warranty whatsoever.

The script assumes the MC instance you want to monitor is running locally and that the server is available on the default port; you need to enable media network for it to work (I'm pretty sure the web interface depends on it). I tested on Gnome and Cinnamon, and it ran nicely. If you're running XFCE or LXDE or any of the other DE's without integrated libnotify support, you'll need a plugin/additional package to show the notifications.  See here for more info: https://wiki.archlinux.org/index.php/Desktop_notifications.  The only dependency, other than basic UNIX utilities like sed, wget, and diff (which are likely to be found on any modern Linux installation) is libnotify.


--- Code: ---#!/bin/bash

mkdir -p ~/.MC_Notifier
touch ~/.MC_Notifier/Filekey.Current

while true; do
wget -q localhost\:52199/MCWS/v1/Playback/Info\?Zone\=\-1 -O ~/.MC_Notifier/Info
mv ~/.MC_Notifier/Filekey.Current ~/.MC_Notifier/Filekey.Old
sed -n 's:.*<Item Name="FileKey">\(.*\)</Item>.*:\1:p' ~/.MC_Notifier/Info > ~/.MC_Notifier/Filekey.Current
diff ~/.MC_Notifier/Filekey.Current ~/.MC_Notifier/Filekey.Old > /dev/null
if [[ $? -ne 0 ]]; then
       sed -- 's/\&amp;/\&/g' ~/.MC_Notifier/Info > ~/.MC_Notifier/Info2
   mv ~/.MC_Notifier/Info2 ~/.MC_Notifier/Info
ALBUM=$(sed -n 's:.*<Item Name="Album">\(.*\)</Item>.*:\1:p' ~/.MC_Notifier/Info)
ARTIST=$(sed -n 's:.*<Item Name="Artist">\(.*\)</Item>.*:\1:p' ~/.MC_Notifier/Info)
TRACK=$(sed -n 's:.*<Item Name="Name">\(.*\)</Item>.*:\1:p' ~/.MC_Notifier/Info)
notify-send -i "/usr/lib/jriver/Media Center 21/Data/Default Art/Logo.png" -t 2000 "$ALBUM" "$ARTIST - $TRACK"
fi
sleep 2
done


--- End code ---

Update 08/09/2015 - The code has been updated to now show Mediacenter's Icon; I took a stab at getting it to display cover art instead , but the notification system in Gnome seems to do some kind of aggressive caching so that it won't recheck an icon file once it's loaded once (so it would only ever show the album art from the first loaded album).  I'll keep tinkering with that and see if I can work it out, but for now the Mediacenter icon is better than nothing or a stock icon.  If you're using MC 20, you'll need to change the "21" in the notify-send line to "20"

geier22:
@mwillems :
Thanks for the Logo - Looks nice  :D :D

geier22:
@mwillems :

the script works with MC 20 well. But on the same machine with MC 21, nothing happens.
I guess that the error in this line :


--- Code: ---wget -q localhost\:52199/MCWS/v1/Playback/Info\?Zone\=\-1 -O ~/.MC_Notifier/Info
--- End code ---

How needs to be changed this line to work with MC 21?

BryanC:

--- Quote from: geier22 on August 14, 2015, 10:43:04 am ---@mwillems :

the script works with MC 20 well. But on the same machine with MC 21, nothing happens.
I guess that the error in this line :


--- Code: ---wget -q localhost\:52199/MCWS/v1/Playback/Info\?Zone\=\-1 -O ~/.MC_Notifier/Info
--- End code ---

How needs to be changed this line to work with MC 21?

--- End quote ---


--- Code: ---notify-send -i "/usr/lib/jriver/Media Center 21/Data/Default Art/Logo.png" -t 2000 "$ALBUM" "$ARTIST - $TRACK"
--- End code ---

Probably should change 21 to 22 here. Not sure if it would cause the whole thing to error out but since I don't see any if checking, it likely could.

Edit: Derp. This isn't the first time I've gotten the current Fedora and MC versions mixed up.

mwillems:

--- Quote from: BryanC on August 14, 2015, 11:09:23 am ---
--- Code: ---notify-send -i "/usr/lib/jriver/Media Center 21/Data/Default Art/Logo.png" -t 2000 "$ALBUM" "$ARTIST - $TRACK"
--- End code ---

Probably should change 21 to 22 here. Not sure if it would cause the whole thing to error out but since I don't see any if checking, it likely could.

--- End quote ---

It's supposed to be 21, not 22; if he had MC 20 there he may need to change it to 21 (is that what you meant)?  The icon won't hang the notification (at least it doesn't when I test it here) you just get a notification with no icon.

It's working fine on MC 21 for me so I'm betting on a configuration issue.  If it's erroring on the wget line that means that JRiver is not responding to the web service call.  Did you enable media network after upgrading to MC21?

What happens if you go to this address in a browser?:

--- Code: ---http://localhost:52199/Gizmo/library.html

--- End code ---

Navigation

[0] Message Index

[#] Next page

Go to full version