<?xml version="1.0" encoding="utf-8"?>
        <?xml-stylesheet type="text/css" href="http://www.linuxevolution.org/styles/feed.css"?>
<rss version="2.0"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:admin="http://webns.net/mvcb/"
 xmlns:atom="http://www.w3.org/2005/Atom"
>
<channel>
<title>Filed under: Last_FM | Linux Evolution dot org and the NSLU2</title>
<atom:link href="http://linuxevolution.org/archives/last_fm/index-rss.xml" rel="self" type="application/rss+xml" />
<link>http://linuxevolution.org</link>
<description></description>
<dc:language>en-us</dc:language>
<dc:creator>orvtech</dc:creator>
<dc:date>2010-12-26T18:58:30-05:00</dc:date>
<admin:generatorAgent rdf:resource="http://nanoblogger.sourceforge.net" />

<item>
<link>http://linuxevolution.org/archives/2009/11/30/the_nslu2_as_a_last_fm_to_twitter_bridge/index.html</link>
<guid isPermaLink="true">http://linuxevolution.org/archives/2009/11/30/the_nslu2_as_a_last_fm_to_twitter_bridge/index.html</guid>
<title>The NSLU2 as a last.fm to twitter bridge.</title>
<dc:date>2009-11-30T16:57:10-05:00</dc:date>
<dc:creator>orvtech</dc:creator>
<dc:subject> Scripts, Last_FM, NSLU2, Linux, Twitter</dc:subject>
<description><![CDATA[<p>This simple script came from the need of updating <a href="http://twitter.com/m1n1m3">my twitter</a> 
status with the songs that I am playing, the trick is that it will only update my profile 
if the song has been tagged as 'loved' on last.fm. It will also detect if it is Monday 
and will add the <a href="http://twitter.com/#search?q=%23mm"><i>#mm</i> hash</a>.</p>

<textarea class="bashcode" readonly wrap="off">twitter_user="<your_twitter_user_here>"
twitter_passwd="your_twitter_password_here"
URL="http://twitter.com/statuses/update.xml"
tags="#lastfm"
lastfm_api="<your_api_from_lastfm_here>"
lastfm_user="<your_lastfm_user_here>"
bit_ly_user="<your_bit.ly_user_here>"
bit_ly_apikey="<your_bit.ly_api_key_here>"

fmtwitted=`cat /tmp/lastfm2twitter.tmp | \
sed -e 's/status=Just played: //g' -e 's/#.*//g' | \
grep '[a-z]'|sed -e 's/\ //g' -e 's/\-/./g'`

fmcurrent=`curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=1&user=$lastfm_user&api_key=$lastfm_api" | \
grep -E '<name>|</name>|<artist\ |</artist>' |\
head -n2| sed -e 's/<[^>]*>//g' | tr '\n' '.' |\
sed -e 's/\ //g' -e 's/.$//g'`


lastfm_song_url=`curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=1&user=$lastfm_user&api_key=$lastfm_api" |\
grep -E '<url>|</url>' | sed -e 's/<[^>]*>//g' |\
head -n1| tr '\n' '.' | sed -e 's/\ //g' -e 's/.$//g'`
bit_ly_url=`curl -s "http://api.bit.ly/shorten?version=2.0.1&longUrl=$lastfm_song_url&login=$bit_ly_user&apiKey=$bit_ly_apikey" | \
grep shortUrl | sed -e 's/\"/\ /g' | awk '{print $3}'`

today_mm=`date +%A`
if [[ $today_mm == "Monday"  ]] 
  then tags="$tags #mm"
fi


if grep $fmcurrent /tmp/lastfm_loved.tmp  > /dev/null
  then if [[ "$fmtwitted" == "$fmcurrent" ]]
      then exit 0
        else curl -s "http://ws.audioscrobbler.com/2.0/?method=user.getrecenttracks&limit=1&user=$lastfm_user&api_key=$lastfm_api" | \
	grep -E '<name>|</name>|<artist\ |</artist>' |\
	head -n2| sed -e 's/<[^>]*>//g' | tr '\n' '-' | \
	sed -e 's/^[ \t]*//' -e 's/-/\ -\ /g' -e 's/- $//g' -e 's/\ $//g' |\
	awk '{print "status=Just played: "$0}' > /tmp/lastfm2twitter.tmp
	lastfm2twitter=`cat /tmp/lastfm2twitter.tmp; 
	echo $bit_ly_url 
	echo $tags | tr '\n' ' '`
	echo $lastfm2twitter > /tmp/lastfm2twitter.tmp
	curl -s -u $twitter_user:$twitter_passwd -d @/tmp/lastfm2twitter.tmp $URL > /dev/null
	  fi
	  else exit 0
fi</textarea>
<br />
<p>As you can see I am using bit.ly to shorten the urls of the song, you will need a bit.ly API for this to work. 
I think what is left is to optimize the script storing the curl requests in a file sort of like a cache 
and add a routine to detect if it is longer than the 140 charaters allowed by twitte and shorten the text 
to be posted as the status.r</p> 
<br />
<p><i>
<b>Spanish version:</b> <a href="http://orvtech.com/howto/el-nslu2-como-un-puente-de-last-fm-a-twitter/" rel="friend" hreflang="es">El NSLU2 como un puente de last.fm a twitter.</a>
</i></p>]]></description>

</item>
</channel>
</rss>

