Skip to content

Instantly share code, notes, and snippets.

@rayning0
Created September 30, 2013 10:29
Show Gist options
  • Select an option

  • Save rayning0/6761941 to your computer and use it in GitHub Desktop.

Select an option

Save rayning0/6761941 to your computer and use it in GitHub Desktop.
Jukebox (talks to you with computer voice, plus it opens up YouTube video for each song you play)
# Raymond Gan - Jukebox
songs = [
"The Phoenix - 1901",
"Tokyo Police Club - Wait Up",
"Sufjan Stevens - Too Much",
"The Naked and the Famous - Young Blood",
"(Far From) Home - Tiga",
"The Cults - Abducted",
"The Phoenix - Consolation Prizes"
]
def check(song, songs)
index = -1
songs.each_with_index do |s, i|
index = i if song == s.split(' - ')[1].downcase
end
index
end
def list(songs)
songs.each_with_index do |s, i|
puts "#{i + 1}. #{s}"
end
puts
end
def playYouTube(song)
case song[0..3] # only check first 4 characters
when "1", "1901"
system("say playing 1901 by the phoenix 2>/dev/null")
system("open -g https://www.youtube.com/watch?v=gvss3uhSKjw")
when "2", "wait"
system("say playing wait up by tokyo police club 2>/dev/null")
system("open -g https://www.youtube.com/watch?v=ZAxRozTgoXM")
when "3", "too"
system("say playing too much by sufjan stevens 2>/dev/null")
system("open -g https://www.youtube.com/watch?v=K0g7R3xqdcM")
when "4", "youn"
system("say playing young blood by the naked and the famous 2>/dev/null")
system("open -g https://www.youtube.com/watch?v=0YuSg4mts9E")
when "5", "tiga"
system("say playing tiga by far from home 2>/dev/null")
system("open -g https://www.youtube.com/watch?v=jTwQbc9kkUc")
when "6", "abdu"
system("say playing abducted by the cults 2>/dev/null")
system("open -g https://www.youtube.com/watch?v=9i1MXHGB8g0")
when "7", "cons"
system("say playing consolation prizes by the phoenix 2>/dev/null")
system("open -g https://www.youtube.com/watch?v=gnkVUReUVpQ")
end
puts "Hit Enter to stop song. This will also close all your Google Chrome tabs."
system("say hit enter to stop song 2>/dev/null")
gets
system("killall 'Google Chrome'")
end
def play(songs)
list(songs)
while true
index = -1
puts "Enter number or name of song."
system("say Enter number or name of song 2>/dev/null")
print "(Ex: 4 or 'Young Blood'). Type 'e' to exit: "
song = gets.chomp.downcase.strip
break if song == 'e' || song == 'E'
if song.to_i.between?(1, songs.size)
puts "Playing #{songs[song.to_i - 1]}..."
playYouTube(song)
else
index = check(song, songs)
puts "Playing #{songs[index]}..." if index.between?(0, songs.size - 1)
playYouTube(song)
end
end
end
while true
print "Hi! I'm your jukebox. Enter 1) list, 2) play, 3) help, or 4) exit: "
system("say Hi, Im a poor mans Ryan Seacrest. 2>/dev/null")
input = gets.chomp.downcase.strip
case input
when '1', 'list'
list(songs)
when '2', 'play'
play(songs)
when '3', 'help'
puts "The 'list' command gives you a list of songs I'll play."
puts "The 'play' command accepts a song, either by number/index or name."
puts "To exit, enter any other key/message besides the first 3 choices.\n\n"
system("say The list command gives you a list of songs I will play. 2>/dev/null")
system("say The play command accepts a song, either by number/index or name. 2>/dev/null")
system("say To exit, enter any other key or message besides the first 3 choices. 2>/dev/null")
else
puts 'Goodbye!'
system("say Goodbye 2>/dev/null")
exit
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment