use Math::BigInt; use LWP::Simple; ## CONFIG HERE # Url where you post your now playing track my $announce_url = 'YOUR URL HERE'; # This is a bit silly but I added a random parameter to make the url unguessable my $security_code = 'YOU PROBABLY WANT SOME KIND OF AUTH WITH YOUR ANNOUNCE URL'; # Where to find your Spotify configuration - the location below - with username and login replaced should be the default my $spotify_dir = 'C:\Documents and Settings\YOURUSERNAME\Application Data\Spotify\Users\YOURLOGIN-user'; ## Base 62 coding of hexadecimal track IDS my @alphabet = split '', '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; my $base = 62; sub base62_encode { my $hex = shift; $h = Math::BigInt->new('0x' . $hex); my @code; foreach (0..21) { push @code , $alphabet[$h % $base]; $h->bdiv($base); } return join('', reverse(@code)); } ## File listener loop my $sfh; my $curtrack = 'none'; chdir($spotify_dir); while(1) { open $sfh, 'guistate'; $state = join('', <$sfh>); close $sfh; if ($state =~ /playing_track_id.:.(\w+)/) { my $track = base62_encode($1); if ($track ne $curtrack) { print "http://open.spotify.com/track/" . $track . "\n"; get $announce_url . '?auth=' . $security_code . '&track=' . $track ; $curtrack = $track; } } sleep(2); }