LastFM Support
Posted: Sun Nov 06, 2011 7:53 pm
Using the WebService::LastFM CPAN module I have been able to get URLs that working with mpd to stream last.fm playlists. Issue I am running into is that I have to copy the next track url into mpc after every song. Tried to PAR package the perl script that I have to play on my laptop, but the space requirements are about double what is left on the router. I believe that it is possible to get the Last.FM 1.2 api working from a shell script, which should require less space than installing a full perl installation. Has anyone been able to get this to work? Willing to attempt to break down the LastFM.pm module for what web services need to be hit, but don't want to do the work if it has already been done.
Have some working code below. You will need to change the username, password and station variables. Other than that it works like a charm. No issues with this since I got it working a couple days ago.
Have some working code below. You will need to change the username, password and station variables. Other than that it works like a charm. No issues with this since I got it working a couple days ago.
Code: Select all
#!/bin/ash
SESSIONFILE=/tmp/session.xml;
PLAYLISTFILE=/tmp/playlist.xml;
username=${USERNAME};
password=${MD5PASSWORDHASH};
url="http://ws.audioscrobbler.com/radio/handshake.php?username=${username}&version=1.1.1&platform=linux&passwordmd5=${password}";
wget -O ${SESSIONFILE} ${url};
status=`grep FAILED ${SESSIONFILE}`;
if [ "${status}" != "" ]
then
echo "Authentication Failed\n";
exit 0;
fi
station=${STATION};
session=`grep session ${SESSIONFILE} | cut -d= -f2`;
url="http://ws.audioscrobbler.com/radio/adjust.php?session=${session}&url=globaltags/${station}";
wget -O /dev/null ${url};
while [ 1 ]
do
url="http://ws.audioscrobbler.com/radio/xspf.php?sk=${session}&discovery=0&desktop=0";
wget -O ${PLAYLISTFILE} ${url};
for tag in location title album creator duration
do
OUT=`grep "<${tag}>.*</${tag}>" ${PLAYLISTFILE} | sed -e "s/^.*<${tag}/<${tag}/" | cut -d">" -f2 | cut -d"<" -f1 | sed -e "s/^.*$/\{&\}/" | sed -e "s/ /+/g" | sed -e "s/'//g" | sed -e "s/\&//g"`;
eval ${tag}='$(echo ${OUT})';
done
i=1
while [ ${i} -lt 6 ]
do
j=$(expr ${i} + 1);
curLoc=$(echo "${location}" | cut -d'}' -f${i} | cut -d'{' -f2);
curDur=$(echo "${duration}" | cut -d'}' -f${i} | cut -d'{' -f2);
curTitle=$(echo "${title}" | cut -d'}' -f${j} | cut -d'{' -f2);
curArt=$(echo "${creator}" | cut -d'}' -f${j} | cut -d'{' -f2);
mpc del 1;
mpc add ${curLoc};
mpc play;
dur=$(echo ${curDur} | sed 's/...$//');
echo "Title: ${curTitle} Artist: ${curArt} Time: ${curDur} Duration: ${dur}";
k=0;
gr=1;
while [ ${gr} -eq 1 ]
do
sleep 1;
gr=`mpc | grep playing | wc -l`;
k=$(expr ${k} + 1);
done
i=$(expr ${i} + 1);
done
done
exit;
done