The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

WebService::LastFM - Simple interface to Last.FM Web service API

SYNOPSIS

  use WebService::LastFM;


  my $lastfm = WebService::LastFM->new(
      username => $config{username},
      password => $config{password},
  );
  my $stream_info = $lastfm->get_session  || die "Can't get Session\n";
  my $session_key = $stream_info->session;

  $lastfm->change_tag( 'ska+punk' );

  while (1) {

       my $playlist = $lastfm->get_new_playlist();

       while ( my $track = $playlist->get_next_track() ) {

           print "Playing '".$track->title."' by ".$track->creator."\n";

           my @cmd = ( 'mpg123' , $track->location() );
           system( @cmd );

       }
   }

DESCRIPTION

WebService::LastFM provides you a simple interface to Last.FM Web service API. It currently supports Last.FM Stream API 1.2.

CAVEAT

This is NOT A BACKWARDS COMPATIBLE update. LastFM has changed their API enough to warrant an interface change.

METHODS

new(%args)
  $lastfm = WebService::LastFM->new(
      username => $username,
      password => $password,
  );

Creates and returns a new WebService::LastFM object.

get_session()
  $stream_info = $lastfm->get_session;

Returns a session key and stream URL as a WebService::LastFM::Session object.

get_new_playlist()
  $stream_info = $lastfm->get_new_playlist();

Returns a WebService::LastFM::Playlist that contains a list of tracks based on the current station. You can/should use the get_next_track method to retrieve the WS:LFM:Track object. Once the playlist is depleted (right now 5 tracks) just grab a new playlist.

       my $playlist = $lastfm->get_new_playlist();

       while ( my $track = $playlist->get_next_track() ) {

           print "Playing '".$track->title."' by ".$track->creator."\n";

           my @cmd = ( 'mpg123' , $track->location() );
           system( @cmd );

       }
get_nowplaying()
  $current_song = $lastfm->get_nowplaying;

Returns a WebService::LastFM::NowPlaying object to retrieve the information of the song you're now listening.

send_command($command)
  $response = $lastfm->send_command($command);

Sends a command to Last.FM Stream API to control the streaming. $command can be one of the follows: skip, love, ban, rtp, or nortp.

$response which you'll get after issuing a command will be either 'OK' or 'FAILED' as a string.

change_station($friend)
  $response = $lastfm->change_station($friend);

Changes the station of your stream to $friend's one.

$response which you'll get after issuing a command will be either 'OK' or 'FAILED' as a string.

change_tag($tag)
  $response = $lastfm->change_tag($tag);

Change the station of your stream to play music tagged with $tag.

$response which you'll get after issuing a command will be either 'OK' or 'FAILED' as a string.

ua
  $lastfm->ua->timeout(10);

Returns the LWP::UserAgent object which is internally used by $lastfm object. You can set some values to customize its behavior. See the documentation of LWP::UserAgent for more details.

SEE ALSO

AUTHOR

Christian Brink, <grep_pdx@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2008 - 2009 by Christian Brink

Copyright (C) 2005 - 2008 by Kentaro Kuribayashi

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.