#!/bin/bash # Copyleft 2010 by Bernd Stellwag # use kde/gnome notify system to display information about the song, mpd is currently playing # Changelog: # 0.2: add possibility to specify host and port or print some info how to use this script and check if required notify-send (libnotify-bin) is installed # 0.1: "release" # see if notify-send (libnotify-bin) is installed if ! which notify-send > /dev/null ; then echo "Please install \"libnotify-bin\" with this Command: \"sudo aptitude install libnotify-bin\" or with your favourite Packagemanager" exit fi # check if user needs some help if [ "$1" == "-h" ] || [ "$1" == "--help" ] || [ "$1" == "-help" ] || [ "$1" == "help" ]; then echo "mpdnotify 0.3: Copyleft 2010 by Bernd Stellwag \nUSAGE: mpdnotify [HOST] [PORT]" exit fi # check if host and port are specified if [ "$1" == "" ]; then host="127.0.0.1" else host="$1" fi if [ "$2" == "" ]; then port="6600" else port="$2" fi # fetch info currentsong="$(echo "currentsong" | nc $host $port -q1)" # see if we have an internetstream httpcheck="$(echo "$currentsong" | grep "file: " | grep "http://")" # if it is an internetstream handle it if [ "$httpcheck" != "" ]; then # see if there is a streamtitle streamtitle="$(echo "$currentsong" | grep "Name: " | sed 's/Name: //g')" # if there is no streamtitle we set the url as title if [ "$streamtitle" == "" ]; then streamtitle="$(echo "$currentsong" | grep "file: " | sed 's/file: //g' | sed '/http:\/\///g')" fi # maybe there is some information about the currently playing song songinfo="$(echo "$currentsong" | grep "Title: " | sed 's/Title: //g')" # send info notify-send "$streamtitle" "$songinfo" # exit the script exit fi # set title title="$(echo "$currentsong" | grep "Title: " | awk '{for (i=2;i<=NF;i++) printf ("%s ", $i); print "" }')" # if there is no title set the filename as title if [ "$title" == "" ]; then title="$(echo "$currentsong" | grep "file: " | sed 's/file:\ //g' | sed 's/musik\///g' | awk -F "/" '{for (i=1;i<=NF;i++) printf ("%s\n", $i)}' | perl -e '@line = <>; chomp(@line); print "@line[$#line]"' | sed 's/.mp3//g')" fi # set artist artist="$(echo "$currentsong" | grep "Artist: " | awk '{for (i=2;i<=NF;i++) printf ("%s ", $i); print "" }')" # set album album="$(echo "$currentsong" | grep "Album: " | awk '{for (i=2;i<=NF;i++) printf ("%s ", $i); print "" }')" # set "artist - album" string if possible if ([ "$artist" != "" ] && [ "$album" != "" ]); then artist_album="$artist - $album" elif ([ "$artist" != "" ] && [ "$album" == "" ]); then artist_album="by $artist" elif ([ "$artist" == "" ] && [ "$album" != "" ]); then artist_album="on $album" else artist_album="" fi # if there is no artist/album see what we can get out of the filepath if [ "$artist_album" == "" ]; then filetitle="$(echo "$currentsong" | grep "file: " | sed 's/file:\ //g' | sed 's/musik\///g' | awk -F "/" '{for (i=1;i<=NF;i++) printf ("%s\n", $i)}' | perl -e '@line = <>; chomp(@line); print "@line[$#line]"')" artist_album="$(echo "$currentsong" | grep "file: " | sed 's/file:\ //g' | sed 's/musik\///g' | sed "s/\/$filetitle//g")" fi # set cover cover="$(echo "$currentsong" | grep "file: " | sed 's/file: /\/var\/lib\/mpd\/music\//g' | awk -F "/" '{for (i=1;i<=NF;i++) printf ("%s\n", $i)}' | perl -e '@line = <>; chomp(@line); $dir=""; for($i=1;$i<$#line;$i++){ $dir = "$dir"."/"."@line[$i]" }; print "$dir/cover.jpg"')" # send infos if [ -e "$cover" ]; then notify-send "$title" "$artist_album" -i "$cover" else notify-send "$title" "$artist_album" fi