Happy with the discovery, I come back home and spend the next few hours in finding the songs I had been looking for since ages now. Make a playlist, all set to go... But... the playlist wont play... !!!! Googling around seemed futile after killing a lot of time.. I guessed that it was time to do some scripting :) Skip the dinner and now I have this script which downloads the songs in the playlist :) Thought it might be of some use to someone out there.
esnips-playlist-save
******************
#!/bin/sh
if [ $# -lt 3 ]
then
echo "Usage: $0"
exit 1
fi
EMAIL="$1"
PASSWD="$2"
PLAYLIST="$3"
ESNIPS='http://www.esnips.com'
LOGIN_URL=$ESNIPS'/UserSignInAction.ns?action=signin'
PLAYLIST_ID=`echo $PLAYLIST | sed 's/.*\///g'`
PLAYLIST_URL=$ESNIPS'/plxml/'$PLAYLIST_ID
# Log in to the server.
rm -f cookies.txt
echo "Logging in to eSnips"
wget --keep-session-cookies --save-cookies cookies.txt \
--post-data "ns_EventTarget=&ns_EventArgument=&referrer=&rememberMe=off&email=$EMAIL&password=$PASSWD" \
--output-document 'junk.html' \
-q \
-p $LOGIN_URL
# Now grab the page or pages we care about.
echo "Loading the playlist"
wget --load-cookies cookies.txt \
--output-document 'playlist.xml' \
-q \
-p $PLAYLIST_URL
# Get the commands for downloading the files
mkdir -p downloads
xsltproc --nodtdattr esnips.xslt playlist.xml | grep -v "
cat esnips.xslt
**************
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/playlist/trackList">
<xsl:for-each select="track">
echo "Downloading <xsl:value-of select="title"/>";ext=`wget -O '<xsl:value-of select="title"/>' --load-cookies cookies.txt <xsl:value-of select="location"/> <xsl:text disable-output-escaping="yes"> 2>&1| grep audio | sed 's/.*audio\///;s/]//'`;mv '</xsl:text><xsl:value-of select="title"/>' downloads/'<xsl:value-of select="title"/>'.$ext
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I am impressed with myself... As I usually am..
No comments:
Post a Comment