-
Notifications
You must be signed in to change notification settings - Fork 1
/
skifftunes.rb
executable file
·65 lines (54 loc) · 1.5 KB
/
skifftunes.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/usr/bin/env ruby
require 'rubygems'
require 'tweetstream'
require 'meta-spotify'
require "config.rb"
# queuing
# now playing
$my_pwd = Dir.pwd
def play_track(uri)
`open -a /Applications/Spotify.app #{uri}`
if uri.include? "playlist"
sleep 1
`osascript #{$my_pwd}/enter.applescript`
end
end
def play_pause
`osascript #{$my_pwd}/play.applescript`
end
def skip
`osascript #{$my_pwd}/next.applescript`
end
def vol(i)
`osascript -e 'set volume #{i}'`
end
TweetStream::Daemon.new(TWITTER_USER, TWITTER_PASS).track(TWITTER_USER) do |status|
txt = status.text.gsub /[@]{0,1}#{TWITTER_USER}/i, ''
puts txt
if txt.include?('!play') || txt.include?('!stop') || txt.include?('!start') || txt.include?('!pause')
play_pause
elsif txt.include?('!quiet')
vol(4)
elsif txt.include?('!loud')
vol(7)
elsif v = txt.match(/!vol ([0-9]{1,2})/)
v = [11.0, v[1].to_i].min
vol((v / 11.0) * 7.0)
elsif txt.include?('!skip') || txt.include?('!next')
skip
else
uri = txt.match(/(http:\/\/open\.spotify\.com\/[a-zA-Z0-9_\/]+)/) || txt.match(/(spotify:[a-zA-Z0-9_:]+)/)
if !uri.nil?
play_track(uri)
return
end
# no urls or commands by now, try a search
search = MetaSpotify::Track.search(txt)[:tracks]
# find top result that's available in the uk
search.each do |track|
next if !track.album.available_territories.include?('gb') && !track.album.available_territories.include?('worldwide')
play_track(track.uri)
return
end
end
end