This took a while, but finally I got it setup. Yes, now I have it setup to scrobble and post all the music I am listening to on my system both to Last.fm and to Twitter at the same time. I have been scrobbling music to Last.fm for a while now (since August 29, 2006) and have well over 10,000 tracks on my Last.fm page. You can check out more about my Last.fm profile here.

I have only recently started twittering from 12:43 pm March 13, 2008, and while it’s fun to post a tweet off and on about what I am doing, tweeting music I am listening to every few minutes or so is a taxing and time consuming chore and it serves my purpose much better if tracks are automatically scrobbled and submitted to Twitter just like at Last.fm without any input from my side and this was a feature I was looking for in submitting my track information to Twitter. There is a good add-on in Firefox, Twitty Tunes which lets you post the music you are listening to Twitter, but then again this too needs intervention from you and you have to click to submit a particular track to Twitter, again not a very feasible option. Apart from this I am more of an Opera person and prefer using Opera as my regular browser and did not look forward to the prospect of switching over to Firefox just so that I could submit tracks to Twitter. Of course Firefox 3 is a lot in the news lately for being low on resources and also faster than Opera 9.5 which is what I currently use, and I did download Firefox 3 Beta to check it out for myself, but never got it to run on my system. You can read up all about it here.

I am not much of a programmer myself, but I do fancy my chances with Google to pull out just about any kind of information and that’s what I set out to do so I could submit and scrobble all my tracks to Twitter in real time just like at Last.fm. To tell the truth, this seems to be an issue that not many are interested in and I could find no software that would automatically scrobble to Twitter. In fact not many people even posted anything on this subject on the World Wide Web. Thankfully, though a few did and were seemingly trying to find an option to do exactly what I was i.e. to post to Twitter and Last.fm at the same time the music they were listening to on their system. Thanks also to Google this information though few and far in between was indexed and could be found by me.
Now to the actual solution itself. If you like me are looking to post your music onto Twitter then this is what you need to do. Go to http://walterhiggins.net/lastfm_to_twitter.html and read up all about it. Next go to http://www.activestate.com/ and download and install Perl on your system. Follow all the instructions at the Walter Higgins link and you are all set to go. Do note though that this script only will take your scrobbling list from Last.fm and submit the same again to Twitter. If you are not setup with Last.fm then it will not work and you will need to register with Last.fm and get that setup first. I for myself will continue to look for something that will submit directly from my music player direct to Twitter just like it does at present to Last.fm. Till then this wonderful script from Walter Higgins will have to do.
The script - Change the $twitter_username and $twitter_password variables to match your own twitter credentials. Change the $lastfm_id variable to match your last.fm username. The script is taken from walterhiggins.net/lastfm_to_twitter.html and all credit is due there.
#!/usr/bin/perl use strict; use LWP::Simple; use LWP::UserAgent; use HTTP::Request::Common; my $twitter_username = "YOUR TWITTER USERNAME HERE"; my $twitter_password = "YOUR TWITTER PASSWORD HERE"; my $lastfm_id = "YOUR LASTFM USER ID HERE"; my $period = 60 * 3; my $lastfm_feed = "http://ws.audioscrobbler.com/1.0/user/$lastfm_id/recenttracks.txt"; my $lastfm_ua = LWP::UserAgent->new(); my $twitter_ua = LWP::UserAgent->new(); $twitter_ua->credentials( "twitter.com:80", "Twitter API", $twitter_username => $twitter_password ); my $last_update = 0; while (1) { my $lastfm_response = $lastfm_ua->request(GET $lastfm_feed); my ($lp, $title) = get_lastfm_recent($lastfm_response->content,$last_update); if ($title) { my $request = POST "http://twitter.com/statuses/update.json", [status => "Listening to $title"]; $twitter_ua->request($request); $last_update = $lp; } sleep $period; } sub get_lastfm_recent { my ($content, $last_update) = @_; my @content = split ‘n’, $content; foreach (0..$#content) { my ($timeplayed,$rest) = $content[$_] =~ /([0-9]+),(.*)/; if ($timeplayed > $last_update){ $rest =~ s/342200223/-/g; return ($timeplayed,$rest); } } return 0; }