Skip to content

Instantly share code, notes, and snippets.

@closer
Created April 4, 2009 18:04
Show Gist options
  • Save closer/90271 to your computer and use it in GitHub Desktop.
Save closer/90271 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
# iTunes
require "rubygems"
require "rbosa"
class ControlliTunes
@@app = OSA.app('iTunes')
def initialize
end
def search _from
list = @@app.sources.first.playlists.first.search _from
list.first
end
def search_and_play _from
item = search(_from)
if item
@@app.play item
item
else
false
end
end
def play
@@app.play
end
def stop
@@app.stop
end
def next
@@app.next_track
end
def vol_up
@@app.sound_volume = @@app.sound_volume + 5
end
def vol_down
@@app.sound_volume = @@app.sound_volume - 5
end
def shuffle_on
@@app.sources.first.playlists.first.shuffle = true
end
def shuffle_off
@@app.sources.first.playlists.first.shuffle = false
end
end
require "yaml"
require "twitter"
config = YAML::load_file(ENV['HOME'] + "/misc/twitter.yml")['nerdhouse']
twit = Twitter::Base.new(config['user'], config['pass'])
replies_file_path = ENV['HOME'] + "/misc/replies.txt"
cnt = ControlliTunes.new
ids = []
replies = File.open(replies_file_path).read.split("\n")
twit.replies.each do |r|
text = r.text.gsub(/&#(\d*?);/) { [$1.to_i].pack('U') }
unless replies.include? r.id
puts text
if text.match(/@nerdhouse (次|つぎ)(の曲)?/) then #next
cnt.next
elsif text.match(/@nerdhouse (音量|ボリューム)?((下|さ)げて)/) then
cnt.vol_down
elsif text.match(/@nerdhouse (音楽|ボリューム)?((上|あ)げて)/) then
cnt.vol_up
elsif text.match(/@nerdhouse (シャッフル|ランダム)(やめ|(止|と)め)て/) then
cnt.shuffle_off
elsif text.match(/@nerdhouse (シャッフル|ランダム)/) then
cnt.shuffle_on
elsif text.match(/@nerdhouse (音楽)?かけて/) then #play
cnt.play
r_text = "音楽かけたよ"
elsif text.match(/@nerdhouse (.*)(かけて|(き|聴|聞)(きたい|かせて))/) then #search
result = cnt.search_and_play $1
if result then
r_text = result.artist + "の" + result.name + "かけます"
else
r_text = $1 + "ないみたい"
end
elsif text.match(/@nerdhouse (音楽)?(止|と)めて/) then #stop
cnt.stop
r_text = "音楽止めた"
else
babels = %w(はい え? あー はいはい)
r_text = babels[rand(babels.size)]
end
puts r_text
twit.update "@" + r.user.screen_name + " " + r_text
ids.push r.id
file = File.open(replies_file_path, 'a')
file.write r.id + "\n"
file.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment