itunes-controller 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/.buildpath +5 -0
  2. data/.gitignore +3 -0
  3. data/.project +17 -0
  4. data/.rvmrc +81 -0
  5. data/LICENSE +674 -0
  6. data/README +27 -0
  7. data/Rakefile +27 -0
  8. data/TODO +8 -0
  9. data/bin/addFiles.rb +35 -0
  10. data/bin/dummyiTunesController.rb +109 -0
  11. data/bin/itunesController.rb +78 -0
  12. data/bin/listDeadTracks.rb +45 -0
  13. data/bin/listNewTracks.rb +88 -0
  14. data/bin/recreateTrackCache.rb +31 -0
  15. data/bin/refreshFiles.rb +42 -0
  16. data/bin/removeDeadTracks.rb +31 -0
  17. data/bin/removeFiles.rb +42 -0
  18. data/bin/trackInfo.rb +50 -0
  19. data/itunes-controller.gemspec +24 -0
  20. data/jar-stuff.sh +24 -0
  21. data/lib/itunesController/application.rb +127 -0
  22. data/lib/itunesController/cachedcontroller.rb +188 -0
  23. data/lib/itunesController/config.rb +95 -0
  24. data/lib/itunesController/controller_creator.rb +29 -0
  25. data/lib/itunesController/controllserver.rb +583 -0
  26. data/lib/itunesController/database/backend.rb +41 -0
  27. data/lib/itunesController/database/database.rb +166 -0
  28. data/lib/itunesController/database/sqlite3_backend.rb +67 -0
  29. data/lib/itunesController/debug.rb +124 -0
  30. data/lib/itunesController/dummy_itunes_track.rb +40 -0
  31. data/lib/itunesController/dummy_itunescontroller.rb +142 -0
  32. data/lib/itunesController/itunescontroller.rb +90 -0
  33. data/lib/itunesController/itunescontroller_factory.rb +51 -0
  34. data/lib/itunesController/kinds.rb +138 -0
  35. data/lib/itunesController/logging.rb +119 -0
  36. data/lib/itunesController/macosx_itunescontroller.rb +204 -0
  37. data/lib/itunesController/platform.rb +53 -0
  38. data/lib/itunesController/sqlite_creator.rb +35 -0
  39. data/lib/itunesController/track.rb +39 -0
  40. data/lib/itunesController/version.rb +25 -0
  41. data/lib/itunesController/windows_itunescontroller.rb +145 -0
  42. data/test/base_server_test_case.rb +125 -0
  43. data/test/dummy_client.rb +44 -0
  44. data/test/test_server.rb +312 -0
  45. metadata +185 -0
@@ -0,0 +1,41 @@
1
+ # Copyright (C) 2011-2012 John-Paul.Stanford <dev@stanwood.org.uk>
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ # Author:: John-Paul Stanford <dev@stanwood.org.uk>
17
+ # Copyright:: Copyright (C) 2011 John-Paul.Stanford <dev@stanwood.org.uk>
18
+ # License:: GNU General Public License v3 <http://www.gnu.org/licenses/>
19
+ #
20
+
21
+ module ItunesController
22
+
23
+ class DatabaseConstraintException < Exception
24
+ end
25
+
26
+ class DatabaseBackend
27
+
28
+ def prepare(sql)
29
+ end
30
+
31
+ def execute(sql)
32
+ end
33
+
34
+ def close()
35
+ end
36
+
37
+ def executeStatement(stmt,*args)
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,166 @@
1
+ # Copyright (C) 2011-2012 John-Paul.Stanford <dev@stanwood.org.uk>
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ # Author:: John-Paul Stanford <dev@stanwood.org.uk>
17
+ # Copyright:: Copyright (C) 2011 John-Paul.Stanford <dev@stanwood.org.uk>
18
+ # License:: GNU General Public License v3 <http://www.gnu.org/licenses/>
19
+ #
20
+ require 'itunesController/logging'
21
+ require 'itunesController/itunescontroller'
22
+
23
+ require 'fileutils'
24
+
25
+ module ItunesController
26
+
27
+ class Database
28
+
29
+ PARAM_KEY_EXPECTED_TRACKS=1
30
+ PARAM_KEY_TRACK_COUNT=2
31
+
32
+ # The constructor
33
+ def initialize(controller,backend)
34
+ @controller = controller
35
+ @backend = backend
36
+ createTables()
37
+ end
38
+
39
+ def addDeadTrack(track)
40
+ stmt = @backend.prepare("insert into dead_tracks(databaseId,location,name) values(?,?,?)")
41
+ id=track.databaseId.to_i
42
+ title=track.title.to_s
43
+ loc = nil
44
+ if (track.location!=nil)
45
+ loc = track.location.to_s
46
+ end
47
+ @backend.executeStatement(stmt,id,loc,title)
48
+ end
49
+
50
+ def addTrack(track)
51
+ stmt = @backend.prepare("insert into tracks(databaseId,location,name) values(?,?,?)")
52
+ id=track.databaseId.to_i
53
+ title=track.title.to_s
54
+ loc=track.location.to_s
55
+ #ItunesController::ItunesControllerLogging::debug("Adding track to database with id=#{id}, title='#{title}' and location='#{loc}'")
56
+ begin
57
+ @backend.executeStatement(stmt,id,loc,title)
58
+ rescue ItunesController::DatabaseConstraintException
59
+ stmt2 = @backend.prepare("select * from tracks where location = ?")
60
+ rows=@backend.executeStatement(stmt2,loc)
61
+ if (rows.next!=nil)
62
+ ItunesController::ItunesControllerLogging::warn("Duplicate track reference detected with databaseId #{id}, title '#{title}' and location '#{loc}'")
63
+ stmt3 = @backend.prepare("insert into dupe_tracks(databaseId,location,name) values(?,?,?)")
64
+ @backend.executeStatement(stmt3,id,loc,title)
65
+ else
66
+ ItunesController::ItunesControllerLogging::warn("Unable to add track to database with #{id}, title '#{title}' and location '#{loc}'")
67
+ end
68
+ end
69
+ end
70
+
71
+ def removeTrack(track)
72
+ ItunesController::ItunesControllerLogging::debug("Removing track from database with id=#{track.databaseId.to_i}'")
73
+ stmt = @backend.prepare("delete from tracks where databaseId=?")
74
+ @backend.executeStatement(stmt,track.databaseId.to_i)
75
+ stmt = @backend.prepare("delete from dead_tracks where databaseId=?")
76
+ @backend.executeStatement(stmt,track.databaseId.to_i)
77
+ stmt = @backend.prepare("delete from dupe_tracks where databaseId=?")
78
+ @backend.executeStatement(stmt,track.databaseId.to_i)
79
+ end
80
+
81
+ def removeTracks()
82
+ ItunesController::ItunesControllerLogging::debug("Removing all tracks")
83
+ @backend.execute("delete from tracks")
84
+ @backend.execute("delete from dead_tracks")
85
+ @backend.execute("delete from dupe_tracks")
86
+ end
87
+
88
+ def setParam(key,value)
89
+ stmt = @backend.prepare("delete from params where key=?")
90
+ @backend.executeStatement(stmt,key)
91
+ stmt = @backend.prepare("insert into params(key,value) values(?,?)")
92
+ @backend.executeStatement(stmt,key,value)
93
+ end
94
+
95
+ def getParam(key,default)
96
+ stmt=@backend.prepare("select value from params where key = ?")
97
+ rows = @backend.executeStatement(stmt,key)
98
+ row=rows.next
99
+ if (row!=nil)
100
+ return row[0]
101
+ end
102
+
103
+ return default
104
+ end
105
+
106
+ def getTrack(path)
107
+ stmt=@backend.prepare("select databaseId,location,name from tracks where location=?")
108
+ rows = @backend.executeStatement(stmt,path)
109
+ row=rows.next
110
+ if (row!=nil)
111
+ return ItunesController::Track.new(row[1],row[0].to_i,row[2])
112
+ end
113
+ return nil
114
+ end
115
+
116
+ def getDeadTracks()
117
+ result=[]
118
+ stmt=@backend.prepare("select databaseId,location,name from dead_tracks")
119
+ rows = @backend.executeStatement(stmt)
120
+ while ((row = rows.next)!=nil)
121
+ result.push(ItunesController::Track.new(row[1],row[0].to_i,row[2]))
122
+ end
123
+ return result
124
+ end
125
+
126
+ def getTrackById(id)
127
+ stmt=@backend.prepare("select databaseId,location,name from tracks where databaseId=?")
128
+ rows = @backend.executeStatement(stmt,id)
129
+ row=rows.next
130
+ if (row!=nil)
131
+ return ItunesController::Track.new(row[1],row[0].to_i,row[2])
132
+ end
133
+ return nil
134
+ end
135
+
136
+ def close()
137
+ @backend.close()
138
+ end
139
+
140
+ def getTrackCount()
141
+ return @backend.execute("select count(*) from tracks")
142
+ end
143
+
144
+ private
145
+ def createTables()
146
+ ItunesController::ItunesControllerLogging::debug("Checking database tables exist")
147
+ @backend.execute("create table if not exists tracks ( databaseId INTEGER PRIMARY KEY, "+
148
+ "location TEXT NOT NULL, "+
149
+ "name TEXT NOT NULL) ")
150
+
151
+ @backend.execute("create table if not exists dead_tracks ( databaseId INTEGER NOT NULL, "+
152
+ "location TEXT, "+
153
+ "name TEXT NOT NULL) ")
154
+
155
+ @backend.execute("create table if not exists dupe_tracks ( databaseId INTEGER NOT NULL, "+
156
+ "location TEXT, "+
157
+ "name TEXT NOT NULL) ")
158
+
159
+ @backend.execute("create unique index if not exists 'loction_index' on tracks (location)")
160
+
161
+ @backend.execute("create table if not exists params ( key INTEGER PRIMARY KEY, "+
162
+ "value TEXT NOT NULL) ")
163
+ end
164
+ end
165
+ end
166
+
@@ -0,0 +1,67 @@
1
+ # Copyright (C) 2011-2012 John-Paul.Stanford <dev@stanwood.org.uk>
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ # Author:: John-Paul Stanford <dev@stanwood.org.uk>
17
+ # Copyright:: Copyright (C) 2011 John-Paul.Stanford <dev@stanwood.org.uk>
18
+ # License:: GNU General Public License v3 <http://www.gnu.org/licenses/>
19
+ #
20
+
21
+ require 'itunesController/logging'
22
+ require 'itunesController/platform'
23
+ require 'itunesController/database/backend'
24
+
25
+ require 'rubygems'
26
+ require 'sqlite3'
27
+
28
+ module ItunesController
29
+
30
+ class SQLite3DatabaseBackend < DatabaseBackend
31
+
32
+ def initialize(dbPath=nil)
33
+ if (dbPath==nil)
34
+ dbPath=ItunesController::Platform::getUserHomeDir()+"/.itunesController/database.db"
35
+ end
36
+ if (!File.directory?(File.dirname(dbPath)))
37
+ FileUtils::mkdir_p(File.dirname(dbPath))
38
+ end
39
+ ItunesController::ItunesControllerLogging::info("Database path #{dbPath}")
40
+ @db=SQLite3::Database.new( dbPath )
41
+ end
42
+
43
+ def prepare(sql)
44
+ return @db.prepare(sql)
45
+ end
46
+
47
+ def executeStatement(stmt,*args)
48
+ begin
49
+ return stmt.execute(*args)
50
+ rescue SQLite3::ConstraintException => e
51
+ raise ItunesController::DatabaseConstraintException, e.message
52
+ end
53
+ end
54
+
55
+ def execute(sql)
56
+ begin
57
+ return @db.execute(sql)
58
+ rescue SQLite3::ConstraintException => e
59
+ raise ItunesController::DatabaseConstraintException, e.message
60
+ end
61
+ end
62
+
63
+ def close()
64
+ @db.close()
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,124 @@
1
+ #
2
+ # Copyright (C) 2011-2012 John-Paul.Stanford <dev@stanwood.org.uk>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+ # Author:: John-Paul Stanford <dev@stanwood.org.uk>
18
+ # Copyright:: Copyright (C) 2011 John-Paul.Stanford <dev@stanwood.org.uk>
19
+ # License:: GNU General Public License v3 <http://www.gnu.org/licenses/>
20
+ #
21
+
22
+ module ItunesController
23
+
24
+ class ItunesControllerDebug
25
+
26
+ ANSI_BOLD = "\033[1m"
27
+ ANSI_RESET = "\033[0m"
28
+ ANSI_LGRAY = "\033[0;37m"
29
+ ANSI_GRAY = "\033[1;30m"
30
+
31
+ # Used to print the methods of a object
32
+ # @param [Object] obj The object
33
+ # @param options
34
+ def self.pm(obj, *options)
35
+ methods = obj.methods
36
+ methods -= Object.methods unless options.include? :more
37
+ filter = options.select {|opt| opt.kind_of? Regexp}.first
38
+ methods = methods.select {|name| name =~ filter} if filter
39
+
40
+ data = methods.sort.collect do |name|
41
+ method = obj.method(name)
42
+ if method.arity == 0
43
+ args = "()"
44
+ elsif method.arity > 0
45
+ n = method.arity
46
+ args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")})"
47
+ elsif method.arity < 0
48
+ n = -method.arity
49
+ args = "(#{(1..n).collect {|i| "arg#{i}"}.join(", ")}, ...)"
50
+ end
51
+ klass = $1 if method.inspect =~ /Method: (.*?)#/
52
+ [name, args, klass]
53
+ end
54
+ max_name = data.collect {|item| item[0].size}.max
55
+ max_args = data.collect {|item| item[1].size}.max
56
+ data.each do |item|
57
+ print " #{ANSI_BOLD}#{item[0].to_s.rjust(max_name)}#{ANSI_RESET}"
58
+ print "#{ANSI_GRAY}#{item[1].ljust(max_args)}#{ANSI_RESET}"
59
+ print " #{ANSI_LGRAY}#{item[2]}#{ANSI_RESET}\n"
60
+ end
61
+ data.size
62
+ end
63
+
64
+ # Used to print the methods of a ole object
65
+ # @param [Object] obj The object
66
+ # @param options
67
+ def self.pm_ole(obj, *options)
68
+ methods = obj.ole_methods
69
+ methods -= Object.methods unless options.include? :more
70
+ filter = options.select {|opt| opt.kind_of? Regexp}.first
71
+ methods = methods.select {|name| name =~ filter} if filter
72
+
73
+ data = methods.collect do |m|
74
+ name = m.to_s
75
+ method = obj.ole_method(name)
76
+ [name, "("+method.params.join(",")+")", method.return_type_detail,method.helpstring]
77
+ end
78
+ max_name = data.collect {|item| item[0].size}.max
79
+ max_args = data.collect {|item| item[1].size}.max
80
+ data.each do |item|
81
+ print " #{ANSI_BOLD}#{item[0].to_s.rjust(max_name)}#{ANSI_RESET}"
82
+ print "#{ANSI_GRAY}#{item[1].ljust(max_args)}#{ANSI_RESET}"
83
+ print " #{ANSI_LGRAY}#{item[2]}#{ANSI_RESET}\n"
84
+ end
85
+ data.size
86
+ end
87
+
88
+ # Used to print the methods of a objc object
89
+ # @param [Object] obj The object
90
+ # @param options
91
+ def self.pm_objc(obj, *options)
92
+ methods = obj.objc_methods
93
+ puts methods
94
+ end
95
+
96
+ # Used to print track information
97
+ # @param track iTunes track
98
+ def self.printTrack(track)
99
+ puts getTrackDescription(track)
100
+ end
101
+
102
+ # Used to get a track description
103
+ # @param track iTunes track
104
+ # @return the track information
105
+ def self.getTrackDescription(track)
106
+ result=[]
107
+ if (track.show!=nil && track.show!="")
108
+ result.push("Type: TV Episode")
109
+ result.push("Show Name: "+track.show)
110
+ else
111
+ result.push("Type: Film")
112
+ end
113
+ result.push("Name: "+track.name)
114
+ if (Platform.isWindows())
115
+ result.push("Database ID: "+track.TrackDatabaseID.to_s)
116
+ result.push("Location: "+track.location)
117
+ else
118
+ result.push("Database ID: "+track.databaseID.to_s)
119
+ result.push("Location: "+track.location.path)
120
+ end
121
+ return result.join("\n")
122
+ end
123
+ end
124
+ end
@@ -0,0 +1,40 @@
1
+ # Copyright (C) 2011-2012 John-Paul.Stanford <dev@stanwood.org.uk>
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # (at your option) any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
+ #
16
+ # Author:: John-Paul Stanford <dev@stanwood.org.uk>
17
+ # Copyright:: Copyright (C) 2011 John-Paul.Stanford <dev@stanwood.org.uk>
18
+ # License:: GNU General Public License v3 <http://www.gnu.org/licenses/>
19
+ #
20
+
21
+ module ItunesController
22
+
23
+ class DummyItunesTrack
24
+ attr_accessor :location,:databaseID,:name
25
+
26
+ def initialize(location,databaseId,name)
27
+ @location = location
28
+ @databaseID = databaseId
29
+ @name = name
30
+ end
31
+
32
+ def refresh
33
+ end
34
+
35
+ def to_s
36
+ return "Location: '#{@location}' - Database ID: #{@databaseID} - Name: '#{@name}' "
37
+ end
38
+ end
39
+
40
+ end
@@ -0,0 +1,142 @@
1
+ #
2
+ # Copyright (C) 2011-2012 John-Paul.Stanford <dev@stanwood.org.uk>
3
+ #
4
+ # This program is free software: you can redistribute it and/or modify
5
+ # it under the terms of the GNU General Public License as published by
6
+ # the Free Software Foundation, either version 3 of the License, or
7
+ # (at your option) any later version.
8
+ #
9
+ # This program is distributed in the hope that it will be useful,
10
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
11
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ # GNU General Public License for more details.
13
+ #
14
+ # You should have received a copy of the GNU General Public License
15
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
+ #
17
+ # Author:: John-Paul Stanford <dev@stanwood.org.uk>
18
+ # Copyright:: Copyright (C) 2011 John-Paul.Stanford <dev@stanwood.org.uk>
19
+ # License:: GNU General Public License v3 <http://www.gnu.org/licenses/>
20
+ #
21
+ require 'itunesController/itunescontroller'
22
+ require 'itunesController/dummy_itunes_track'
23
+
24
+ module ItunesController
25
+ # This is a dummy implementation of the itunes controller which can be used
26
+ # in tests to check that they talk to the server correctly. Any commands
27
+ # that are recived are logged in the COMMNAD_LOG list. Tests can read
28
+ # these to make sure they did the correct thing
29
+ class DummyITunesController < ItunesController::BaseITunesController
30
+
31
+ # The constructor
32
+ def initialize
33
+ end
34
+
35
+ def self.getCommandLog()
36
+ return @@commandLog
37
+ end
38
+
39
+ def self.resetCommandLog()
40
+ @@commandLog=[]
41
+ end
42
+
43
+ def self.resetTracks()
44
+ @@tracks=[]
45
+ end
46
+
47
+ def self.forceAddTrack(track)
48
+ ItunesController::ItunesControllerLogging::debug("Force Adding track #{track}")
49
+ dummyTrack=DummyItunesTrack.new(track.location,track.databaseId,track.title)
50
+ @@tracks.push(dummyTrack)
51
+ end
52
+
53
+ def version
54
+ return "Dummy"
55
+ end
56
+
57
+ # Used to tell iTunes to refresh a list of tracks data from the info stored in the files.
58
+ # This is a dummy implementaion that is used with tests. It pushes messages into the
59
+ # ItunesController::DummyITunesController::COMMAND_LOG so that tests can check the result.
60
+ # @param track The track
61
+ def refreshTracks(tracks)
62
+ tracks.each do | track |
63
+ ItunesController::ItunesControllerLogging::debug("Refresh track #{track}")
64
+ @@commandLog.push("refreshTracks(#{track})")
65
+ end
66
+ end
67
+
68
+ # Used to remove tracks from the libaray. This is a dummy implementaion that is used with tests.
69
+ # It pushes messages into the ItunesController::DummyITunesController::COMMAND_LOG so that tests
70
+ # can check the result.
71
+ # @param [Array] tracks A list of tracks to remove from the itunes libaray
72
+ def removeTracksFromLibrary(tracks)
73
+ tracks.each do | track |
74
+ ItunesController::ItunesControllerLogging::debug("Remove track #{track}")
75
+ @@commandLog.push("removeTracksFromLibrary(#{track})")
76
+ @@tracks.delete(track)
77
+ end
78
+ end
79
+
80
+ # Used to add a list of files to the itunes library. This is a dummy implementaion that is used
81
+ # with tests. It pushes messages into the ItunesController::DummyITunesController::COMMAND_LOG
82
+ # so that tests can check the result.
83
+ # @param [Array[String]] A list of files to add to the itunes library
84
+ # @return [Array[ItunesController::Track]] List of ids of the new tracks once they are in the database
85
+ def addFilesToLibrary(files)
86
+ tracks=[]
87
+ files.each do | file |
88
+ track=ItunesController::Track.new(file,@@tracks.length,"Test #{@@tracks.length}")
89
+ ItunesController::ItunesControllerLogging::debug("Adding track #{track}")
90
+ dummyTrack=DummyItunesTrack.new(track.location,track.databaseId,track.title)
91
+ tracks.push(track)
92
+ @@tracks.push(dummyTrack)
93
+ @@commandLog.push("addFilesToLibrary("+file+")")
94
+ end
95
+ return tracks
96
+ end
97
+
98
+ def findPlaylists(types)
99
+ playlists=[]
100
+ @@commandLog.push("findPlaylists(types)")
101
+ return playlists
102
+ end
103
+
104
+ def getTrackCount()
105
+ @@commandLog.push("getTrackCount() = #{@@tracks.length}")
106
+ return @@tracks.length
107
+ end
108
+
109
+ def getTracks(&b)
110
+ @@commandLog.push("getTracks()")
111
+ for i in (0..@@tracks.length-1)
112
+ track=@@tracks[i]
113
+ dead=!File.exist?(track.location)
114
+ ItunesController::ItunesControllerLogging::debug("Getting track: #{track}, dead = #{dead}")
115
+ b.call(ItunesController::Track.new(track.location,track.databaseID,track.name),i,@@tracks.length,dead)
116
+ end
117
+ end
118
+
119
+
120
+ def searchLibrary(title)
121
+ tracks=[]
122
+ ItunesController::ItunesControllerLogging::debug("Searching for tracks with title '#{title}'")
123
+ @@tracks.each do | track |
124
+ if (track.name == title)
125
+ tracks.push(track)
126
+ ItunesController::ItunesControllerLogging::debug("Found track '#{track}'")
127
+ end
128
+ end
129
+ return tracks
130
+ end
131
+
132
+ # Used to get the database of a itunes track
133
+ # @param track the track
134
+ # @return The database id
135
+ def getTrackDatabaseId(track)
136
+ return track.databaseID
137
+ end
138
+
139
+ end
140
+
141
+ end
142
+