Skip to content

Instantly share code, notes, and snippets.

@lindsayevans
Created August 16, 2009 01:03
Show Gist options
  • Save lindsayevans/168513 to your computer and use it in GitHub Desktop.
Save lindsayevans/168513 to your computer and use it in GitHub Desktop.
# Tweets the currently playing song from iTunes
# Requirements:
# Grackle: http://github.com/hayesdavis/grackle/tree/master
# rb-itunes: http://rubyforge.org/projects/rb-itunes/
require 'rubygems'
require 'rb-itunes'
require 'grackle'
@@delay = 1 # in seconds
@@twitter_username = 'YOUR_TWITTER_USERNAME'
@@twitter_password = 'YOUR_TWITTER_PASWORD'
@@current_track = ''
@@itunes = ItunesApp.new
@@twitter_client = Grackle::Client.new(:auth=>{:type=>:basic,:username=>@@twitter_username,:password=>@@twitter_password})
def get_current_track
@@itunes.current_track.name + ' - ' + @@itunes.current_track.artist
end
while true
sleep @@delay
current_track = get_current_track
if current_track != '' && current_track != @@current_track
@@current_track = current_track
puts current_track
@@twitter_client.statuses.update! :status => '"' + current_track + '" ♫'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment