Skip to content

Instantly share code, notes, and snippets.

@alexmuller
Created August 13, 2012 10:49
Embed
What would you like to do?
--- poll.rb
+++ (clipboard)
@@ -34,7 +34,7 @@
tokens << token
end
- # Get sessions
+ # Get sessions
tokens.each do |token|
sessions << lastfm.auth.get_session(token)['key']
end
@@ -53,6 +53,12 @@
first_seen = Time.now
scrobbled = false
+sayings = ["It sure sucks without Jon here, doesn't it?","Let's listen to some music!","Hey guys, where's Jon!","It sure is quiet in here.","Don't you guys miss Jon?","Someone should put on some music.","Jon was really great, wasn't he?"]
+sayings_during_song = ["Ooo ooo ooo ooo oo oo ooo, I like this part.","This music is moreish!","This song really gets me in the zone."]
+said_during_song = false
+
while true do
ps_output = `ps x | grep "Airfoil Speakers" | grep -v "grep"`
@@ -72,6 +78,12 @@
unless udp_connections[0]
puts "Nothing playing...Sleeping for a while"
sleep(30)
+ rander = Random.rand(19)
+ working_hours = Time.now.wday <= 5 && Time.now.wday >= 1 && Time.now.hour >= 9 && Time.now.hour <= 18
+ if rander == 9 && working_hours
+ to_say = sayings.sample
+ prank = `say "#{to_say}"`
+ end
next
end
@@ -125,25 +137,39 @@
rescue JSON::ParserError => e
puts "Problem parsing JSON...data follows:"
puts responses.first
+ petey_pops = `say "lololololololololololo"`
sleep(1)
next
end
- song = data.metadata.title + " " + data.metadata.artist
+ next unless data.metadata.title and data.metadata.title
+ song = "#{data.metadata.title} #{data.metadata.artist}"
if !scrobbled and song == current_song and first_seen <= Time.now - 30
# Scrobble
puts "Scrobbling: #{data.metadata.artist} - #{data.metadata.title}"
+ rander = Random.rand(3)
+ if rander == 3
+ pranker = `say "Nice... I like #{data.metadata.artist}."`
+ end
sessions.each do |session|
lastfm.session = session
lastfm.track.scrobble data.metadata.artist, data.metadata.title, first_seen.utc.to_i, data.metadata.album
end
scrobbled = true
next
+ elsif !said_during_song && (Time.now - first_seen) >= (90 + Random.rand(60))
+ rander = Random.rand(3)
+ if rander == 1
+ playing_prank = sayings_during_song.sample
+ pranking = `say "#{playing_prank}"`
+ said_during_song = true
+ end
end
if song != current_song
current_song = song
scrobbled = false
+ said_during_song = false
first_seen = Time.now
puts "Started playing: #{data.metadata.artist} - #{data.metadata.title}"
end
@@ -158,4 +184,4 @@
# Wait a while.
sleep(10)
-end
+end
\ No newline at end of file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment