Skip to content

Instantly share code, notes, and snippets.

@kristianfreeman
Created September 1, 2013 17:44
Show Gist options
  • Select an option

  • Save kristianfreeman/6406054 to your computer and use it in GitHub Desktop.

Select an option

Save kristianfreeman/6406054 to your computer and use it in GitHub Desktop.
getting most recently played artists using last.fm
require 'rss'
require 'open-uri'
url = 'http://ws.audioscrobbler.com/1.0/user/kristianfr/recenttracks.rss'
file = '/Users/kristian/.bin/artist.txt'
loop do
begin
open(url) do |rss|
feed = RSS::Parser.parse(rss)
music = feed.items.first.title
File.open(file, 'w') { |f| f.write(music) }
end
rescue
`osascript /Users/kristian/.bin/itunes.scpt > #{ file }`
end
sleep(10)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment