Skip to content

Commit

Permalink
Replace rb-appscript with rubyosa19 fork.
Browse files Browse the repository at this point in the history
Fixes iTunes 10.6.3 compatibility. Should be stable going forward. Oh
and we get Ruby 1.9 compatibility on the iTunes bridge shit for free.

Airfoil support currently disabled while debugging rubyosa19 bridge for
that.
  • Loading branch information
wfarr committed Jul 15, 2012
1 parent f0b04c0 commit c562f30
Show file tree
Hide file tree
Showing 11 changed files with 84 additions and 81 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -15,7 +15,7 @@ gem 'foreman'
gem 'thin'

if RUBY_PLATFORM.downcase.include?("darwin")
gem 'rb-appscript'
gem 'rubyosa19', :git => 'git://github.com/pbosetti/rubyosa.git'
end

group :test do
Expand All @@ -25,4 +25,4 @@ end

group :development do
gem 'shotgun'
end
end
11 changes: 9 additions & 2 deletions Gemfile.lock
@@ -1,3 +1,10 @@
GIT
remote: git://github.com/pbosetti/rubyosa.git
revision: 2a78143ebd1520d953be4ec3c0618f7690f06f9c
specs:
rubyosa19 (0.5.4)
libxml-ruby (>= 1.1.3)

GEM
remote: http://rubygems.org/
specs:
Expand All @@ -21,6 +28,7 @@ GEM
hashie (1.2.0)
hike (1.2.1)
json (1.7.3)
libxml-ruby (2.3.3)
metaclass (0.0.1)
mime-types (1.18)
mocha (0.11.1)
Expand All @@ -47,7 +55,6 @@ GEM
rack-test (0.6.1)
rack (>= 1.0)
rake (0.9.2.2)
rb-appscript (0.6.1)
redis (2.2.2)
rest-client (1.6.7)
mime-types (>= 1.16)
Expand Down Expand Up @@ -102,8 +109,8 @@ DEPENDENCIES
rack (~> 1.3.0)
rack-test
rake (~> 0.9.2.1)
rb-appscript
redis
rubyosa19!
sass (~> 3.1)
shotgun
sinatra
Expand Down
6 changes: 3 additions & 3 deletions app/boot.rb
Expand Up @@ -11,7 +11,7 @@
require 'sinatra_auth_github'
require 'yajl'
require 'sass'
require 'appscript' if RUBY_PLATFORM.downcase.include?("darwin") && !ENV['CI']
require 'rbosa' if RUBY_PLATFORM.downcase.include?("darwin") && !ENV['CI']
require 'pusher'

require 'play'
Expand All @@ -30,5 +30,5 @@
require 'app'
require 'views/layout'

REDIS_URL = 'redis://127.0.0.1'
$redis = Redis.connect(:url => REDIS_URL, :thread_safe => true)
REDIS_URL = "redis://127.0.0.1:#{ENV['GH_REDIS_PORT']}"
$redis = Redis.connect(:url => REDIS_URL, :thread_safe => true)
30 changes: 15 additions & 15 deletions app/models/airfoil.rb
Expand Up @@ -25,7 +25,7 @@ def self.enabled=(setting)
# Returns an Appscript instance of the airfoil app.
def self.app
return false if ENV['RACK_ENV'] == 'test'
Appscript.app('Airfoil')
OSA.app('Airfoil')
end

# Check if Airfoil is installed.
Expand All @@ -42,16 +42,16 @@ def self.installed?
#
# Returns Array of Speakers.
def self.get_speakers
app.speakers.id_.get.map { |id|
Speaker.new id
}
#app.speakers.id_.get.map { |id|
# Speaker.new id
#}
end

# Get the current Airfoil audio source name.
#
# Returns String Airfoil audio source name.
def self.audio_source
app.current_audio_source.name.get
#app.current_audio_source.name.get
end

# Set audio source for Airfoil.
Expand All @@ -60,20 +60,20 @@ def self.audio_source
#
# Returns String audio source name.
def self.audio_source=(setting)
app.application_sources.id_.get.each do |id|
name = app.application_sources.ID(id).name.get
if name.eql?(setting)
app.current_audio_source.set(app.application_sources.get[id])
end
end
audio_source
#app.application_sources.id_.get.each do |id|
# name = app.application_sources.ID(id).name.get
# if name.eql?(setting)
# app.current_audio_source.set(app.application_sources.get[id])
# end
#end
#audio_source
end

# Get volume for all speakers.
#
# Returns Array of Floats speaker volumefrom 0.0 to 1.0.
def self.speakers_volume
app.speakers.volume.get
#app.speakers.volume.get
end

# Set the volume for all speakers.
Expand All @@ -82,8 +82,8 @@ def self.speakers_volume
#
# Returns Float volume level.
def self.speakers_volume=(setting)
app.speakers.volume.set setting
speakers_volume
#app.speakers.volume.set setting
#speakers_volume
end

end
Expand Down
15 changes: 8 additions & 7 deletions app/models/album.rb
Expand Up @@ -22,19 +22,20 @@ def initialize(name,artist)
#
# Returns an Array of Songs.
def self.songs_by_name(name)
Player.library.file_tracks[Appscript.its.album.eq(name)].get.map do |record|
Song.new(record.persistent_ID.get)
Player.library.shared_tracks.select { |t| t.album == name }.map do |record|
Song.new(record.persistent_id)
end
end

# The songs attached to this album.
#
# Returns an Array of Songs.
def songs
Player.library.file_tracks[
Appscript.its.album.eq(name).and(Appscript.its.artist.eq(artist))
].get.map do |record|
Song.new(record.persistent_ID.get)
Player.library.shared_tracks.select do |t|
t.album == name &&
t.artist == artist
end.map do |record|
Song.new(record.persistent_id)
end
end

Expand Down Expand Up @@ -70,4 +71,4 @@ def zip_path
"/tmp/play-zips/#{zip_name}"
end
end
end
end
6 changes: 4 additions & 2 deletions app/models/artist.rb
Expand Up @@ -18,7 +18,9 @@ def initialize(name)
# Returns an Array of Songs.
def songs
if name
Player.app.tracks[Appscript.its.artist.contains(name)].get.map do |record|
library.shared_tracks.select do |t|
artists =~ /#{name}/
end.map do | record |
Song.initialize_from_record(record)
end
else
Expand All @@ -27,4 +29,4 @@ def songs
end

end
end
end
35 changes: 12 additions & 23 deletions app/models/player.rb
Expand Up @@ -5,12 +5,14 @@ class Player
#
# Returns an Appscript instance of the music app.
def self.app
Appscript.app('iTunes')
::OSA.app('iTunes')
end

# All songs in the library.
def self.library
app.playlists['Library'].get
app.sources.select { |s|
s.name == 'Library'
}.first.library_playlists.get.first
end

# Play the music.
Expand All @@ -25,7 +27,7 @@ def self.pause

# Is there music currently playing?
def self.paused?
state = app.player_state.get
state = app.player_state.name
state == :paused
end

Expand Down Expand Up @@ -69,7 +71,7 @@ def self.system_volume=(setting)
#
# Returns an Integer from 0-100.
def self.app_volume
app.sound_volume.get
app.sound_volume
end

# Set the app volume.
Expand All @@ -79,7 +81,7 @@ def self.app_volume
#
# Returns the current volume setting.
def self.app_volume=(setting)
app.sound_volume.set(setting)
app.sound_volume = setting
setting
end

Expand All @@ -98,8 +100,8 @@ def self.say(message)
#
# Returns a Song.
def self.now_playing
Song.new(app.current_track.persistent_ID.get)
rescue Appscript::CommandError
Song.new(app.current_track.persistent_id)
rescue
nil
end

Expand All @@ -114,22 +116,9 @@ def self.now_playing
#
# Returns an Array of matching Songs.
def self.search(keyword)
# Exact Artist match.
songs = library.tracks[Appscript.its.artist.eq(keyword)].get
return songs.map{|record| Song.new(record.persistent_ID.get)} if songs.size != 0

# Exact Album match.
songs = library.tracks[Appscript.its.album.eq(keyword)].get
return songs.map{|record| Song.new(record.persistent_ID.get)} if songs.size != 0

# Exact Song match.
songs = library.tracks[Appscript.its.name.eq(keyword)].get
return songs.map{|record| Song.new(record.persistent_ID.get)} if songs.size != 0

# Fuzzy Song match.
songs = library.tracks[Appscript.its.name.contains(keyword)].get
songs.map{|record| Song.new(record.persistent_ID.get)}
songs = library.search(keyword)
return songs.map{|record| Song.new(record.persistent_id)} if songs.size != 0
end

end
end
end
32 changes: 17 additions & 15 deletions app/models/queue.rb
Expand Up @@ -15,7 +15,9 @@ def self.name
#
# Returns an Appscript::Reference to the Playlist.
def self.playlist
Player.app.playlists[name].get
Play::Player.app.sources.first.playlists.select do |p|
p.name == 'iTunes DJ'
end.first
end

# Get the queue start offset for the iTunes DJ playlist.
Expand All @@ -33,7 +35,7 @@ def self.playlist
#
# Returns Integer offset to queued songs.
def self.playlist_offset
Player.app.current_track.index.get
Play::Player.app.current_track.index
end

# Public: Adds a song to the Queue.
Expand All @@ -42,7 +44,7 @@ def self.playlist_offset
#
# Returns a Boolean of whether the song was added.
def self.add_song(song)
Player.app.add(song.record.location.get, :to => playlist.get)
Play::Player.app.duplicate(song.record, :to => self.playlist)
end

# Public: Removes a song from the Queue.
Expand All @@ -51,25 +53,25 @@ def self.add_song(song)
#
# Returns a Boolean of whether the song was removed maybe.
def self.remove_song(song)
Play::Queue.playlist.tracks[
Appscript.its.persistent_ID.eq(song.id)
].first.delete
self.playlist.tracks.select do |t|
t.persistent_id == song.id
end.first.delete
end

# Clear the queue. Shit's pretty destructive.
#
# Returns who the fuck knows.
def self.clear
Play::Queue.playlist.tracks.get.each { |record| record.delete }
self.playlist.tracks.each { |record| record.delete }
end

# Ensure that we're currently playing on the Play playlist. Don't let anyone
# else use iTunes, because fuck 'em.
#
# Returns nil.
def self.ensure_playlist
if Play::Player.app.current_playlist.get.name.get != name
Play::Player.app.playlists[name].get.play
if Play::Player.app.current_playlist.name != name
self.playlist.play
end
rescue Exception => e
# just in case!
Expand All @@ -79,8 +81,8 @@ def self.ensure_playlist
#
# Returns an Array of Songs.
def self.songs
songs = playlist.tracks.get.map do |record|
Song.find(record.persistent_ID.get)
songs = playlist.tracks.map do |record|
Song.find(record.persistent_id)
end
songs.slice(playlist_offset, songs.length - playlist_offset)
rescue Exception => e
Expand All @@ -92,9 +94,9 @@ def self.songs
#
# Returns a Boolean.
def self.queued?(song)
Play::Queue.playlist.tracks[
Appscript.its.persistent_ID.eq(song.id)
].get.size != 0
self.playlist.tracks.select do |t|
t.persistent_id == song.id
end.size > 0
end

# Returns the context of this Queue as JSON. This contains all of the songs
Expand All @@ -109,4 +111,4 @@ def self.to_json
end

end
end
end

0 comments on commit c562f30

Please sign in to comment.