Class: ItunesController::MacOSXITunesController
- Inherits:
-
BaseITunesController
- Object
- BaseITunesController
- ItunesController::MacOSXITunesController
- Defined in:
- lib/itunesController/macosx_itunescontroller.rb
Overview
This is a iTunes controller class used to talk to itunes. This runs on macosx and makes use of the OSC ruby bindings. It also uses application “osascript” to execute apple scripts.
Instance Method Summary collapse
-
#addFilesToLibrary(files) ⇒ Array[ItunesController::Track]
Used to add a list of files to the itunes library.
-
#getTrackCount ⇒ Number
Used to find the number of tracks in the library.
-
#getTrackDatabaseId(track) ⇒ Object
Used to get the database of a itunes track.
- #getTracks(&b) ⇒ Object
-
#initialize ⇒ MacOSXITunesController
constructor
The constructor.
-
#refreshTracks(tracks) ⇒ Object
Used to tell iTunes to refresh a list of tracks data from the info stored in the files.
-
#removeTracksFromLibrary(tracks) ⇒ Object
Used to remove tracks from the libaray.
-
#searchLibrary(term) ⇒ Array
Used to search the itunes library.
-
#version ⇒ String
Used to get the iTunes version.
Constructor Details
#initialize ⇒ MacOSXITunesController
The constructor
47 48 49 50 51 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 47 def initialize() @iTunes = SBApplication.applicationWithBundleIdentifier:'com.apple.iTunes' library=getSourceLibrary() @libraryPlaylists=library.libraryPlaylists end |
Instance Method Details
#addFilesToLibrary(files) ⇒ Array[ItunesController::Track]
Used to add a list of files to the itunes library
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 80 def addFilesToLibrary(files) tracks=[] files.each do | file | script="tell application \"iTunes\"\n" script=script+" set theTrack to (add POSIX file \"#{file}\")\n" script=script+" return (database ID of theTrack & name of theTrack)\n" script=script+"end tell\n" output=executeScript(script) if (output =~ /(\d+), (.*)/) track=ItunesController::Track.new(file,$1.to_i,$2) tracks.push(track) else ItunesController::ItunesControllerLogging::error("Unable to add file '#{file}': " + output) end end return tracks; end |
#getTrackCount ⇒ Number
Used to find the number of tracks in the library
139 140 141 142 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 139 def getTrackCount() playlist=@libraryPlaylists[0] return playlist.fileTracks.length() end |
#getTrackDatabaseId(track) ⇒ Object
Used to get the database of a itunes track
102 103 104 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 102 def getTrackDatabaseId(track) return track.databaseID end |
#getTracks(&b) ⇒ Object
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 106 def getTracks(&b) ItunesController::ItunesControllerLogging::debug("Retriving track information...") playlist=@libraryPlaylists[0] fileTracks = playlist.fileTracks size = fileTracks.length() count = 1 fileTracks.each do | track | location=track.location path=nil dead=false if (location!=nil && location.isFileURL) path=location.path if (!File.exist?(location.path)) dead = true end else dead = true end if (count % 1000 == 0) ItunesController::ItunesControllerLogging::debug("Found tracks #{count} of #{size}") end if (track.name!=nil) b.call(ItunesController::Track.new(path,track.databaseID,track.name),count,size,dead) end count=count+1 end ItunesController::ItunesControllerLogging::debug("Found tracks #{count-1} of #{size}") return size end |
#refreshTracks(tracks) ⇒ Object
Used to tell iTunes to refresh a list of tracks data from the info stored in the files
61 62 63 64 65 66 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 61 def refreshTracks(tracks) ItunesController::ItunesControllerLogging::debug("refreshing tracks...") tracks.reverse.each do | track | track.refresh end end |
#removeTracksFromLibrary(tracks) ⇒ Object
Used to remove tracks from the libaray
70 71 72 73 74 75 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 70 def removeTracksFromLibrary(tracks) ItunesController::ItunesControllerLogging::debug("removing tracks...") tracks.reverse.each do | track | track.delete end end |
#searchLibrary(term) ⇒ Array
Used to search the itunes library
147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 147 def searchLibrary(term) tracks=[] @libraryPlaylists.each do | playlist | #foundTracks = playlist.searchFor(term,'kSrS') foundTracks = playlist.searchFor_only_(term,1799449708) if (foundTracks!=nil) foundTracks.each do | t | tracks.push(t) end end end return tracks end |
#version ⇒ String
Used to get the iTunes version
55 56 57 |
# File 'lib/itunesController/macosx_itunescontroller.rb', line 55 def version return @iTunes.version.to_s+" (Mac OSX)" end |