lastfm12
Get Version
0.0.2What
lastfm12 is a wrapper around the Last.fm protocol version 1.2. This library can manipulate the last.fm radio streams. So, you can implement easily a last.fm radio.
Installing
sudo gem install lastfm12
Demonstration of usage
Example for playing Queen’s similar tracks with mpg123
require "rubygem" require "lastfm12" lastfm = LastFM12.new("lastfm_username", "lastfm_password") lastfm.adjust_station("artist", "Queen") loop do tracks = lastfm.get_tracks puts "*** Got #{tracks.length} track#{tracks.length==1 ? nil : 's'}" tracks.each do |track| puts "-------------------------------------------" puts "artist: #{track.artist}" puts "title: #{track.title}" puts "album: #{track.album}" puts "length: #{track.length/1000}[sec]" `mpg123 #{track.location}` end end
Example for getting mp3 streams
you can use play_loop . this class method is more simpler than the above example.
this example is a download script for tracks tagged as “bossa” on LastFM.
require "rubygems" require "lastfm12" STDOUT.sync = true LastFM12.play_loop("lastfm_username", "lastfm_password", :verbose => true, :station => ["tag","bossa"] ) do |track| puts "Title: #{track.title} \tArtist: #{track.artist}" open("#{track.artist}-#{track.title}.mp3", 'w') do |file| track.play do |segment| file.write segment print "#{file.pos / 1000} KB\r" end end end
ToDo
- implement
play_loop_with_threadmethod: using a thread for getting track infomation.
License
This code is free to use under the terms of the MIT license.
Contact
Links
FIXME full name, 28th December 2008
Theme extended from Paul Battley