itunes-controller 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
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,312 @@
1
+ require 'base_server_test_case'
2
+ require 'dummy_client'
3
+ require 'itunesController/track'
4
+
5
+ class ServerTest < BaseServerTest
6
+
7
+ def this_method
8
+ caller[0][/`([^']*)'/, 1]
9
+ end
10
+
11
+ def test_connect
12
+ puts("\n-- Test Start: #{this_method()}")
13
+ setupServer
14
+ begin
15
+ assert(!@server.stopped?)
16
+ # assert_equal(0,@server.connections.size)
17
+ client=DummyClient.new
18
+ client.connect("localhost",@port)
19
+ # assert_equal(1,@server.connections.size)
20
+ client.disconnect
21
+ # TODO Fix this so when the client disconnects, we spot it
22
+ # assert_equal(0,@server.connections.size)
23
+ ensure
24
+ teardownServer
25
+ assert(@server.stopped?)
26
+ end
27
+ puts("-- Test Finish:#{this_method()}")
28
+ end
29
+
30
+ def test_quit_loggedin
31
+ puts("\n-- Test Start: #{this_method()}")
32
+ setupServer
33
+ begin
34
+ assert(!@server.stopped?)
35
+ # assert_equal(0,@server.connections.size)
36
+ client=DummyClient.new
37
+ client.connect("localhost",@port)
38
+ # assert_equal(1,@server.connections.size)
39
+ client.login(BaseServerTest::USER,BaseServerTest::PASSWORD)
40
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
41
+ # TODO Fix this so when the client disconnects, we spot it
42
+ #assert_equal(0,@server.connections.size)
43
+ client.disconnect
44
+ ensure
45
+ teardownServer
46
+ assert(@server.stopped?)
47
+ end
48
+ puts("-- Test Finish:#{this_method()}")
49
+ end
50
+
51
+ def test_quit_not_loggedin
52
+ puts("\n-- Test Start: #{this_method()}")
53
+ setupServer
54
+ begin
55
+ assert(!@server.stopped?)
56
+ # assert_equal(0,@server.connections.size)
57
+ client=DummyClient.new
58
+ client.connect("localhost",@port)
59
+ # assert_equal(1,@server.connections.size)
60
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
61
+ # TODO Fix this so when the client disconnects, we spot it
62
+ #assert_equal(0,@server.connections.size)
63
+ client.disconnect
64
+ ensure
65
+ teardownServer
66
+ assert(@server.stopped?)
67
+ end
68
+ puts("--Test Finish:#{this_method()}")
69
+ end
70
+
71
+ def test_login
72
+ puts("\n-- Test Start: #{this_method()}")
73
+ setupServer
74
+ begin
75
+ client=DummyClient.new
76
+ client.connect("localhost",@port)
77
+ client.login(BaseServerTest::USER,BaseServerTest::PASSWORD)
78
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
79
+ client.disconnect
80
+ ensure
81
+ teardownServer
82
+ end
83
+ puts("--Test Finish:#{this_method()}")
84
+ end
85
+
86
+ def test_InvalidLoginDetails
87
+ puts("\n-- Test Start: #{this_method()}")
88
+ setupServer
89
+ begin
90
+ client=DummyClient.new
91
+ client.connect("localhost",@port)
92
+ begin
93
+ client.login(BaseServerTest::USER,"blah1")
94
+ rescue
95
+ end
96
+ begin
97
+ client.login("balh",BaseServerTest::PASSWORD)
98
+ rescue
99
+ end
100
+ client.disconnect
101
+ assertCommandLog(["getTrackCount() = 0"])
102
+ ensure
103
+ teardownServer
104
+ end
105
+ puts("--Test Finish:#{this_method()}")
106
+ end
107
+
108
+ def test_CommandsDontWorkWhenNotLoggedIn
109
+ puts("\n-- Test Start: #{this_method()}")
110
+ setupServer
111
+ begin
112
+ client=DummyClient.new
113
+ client.connect("localhost",@port)
114
+ client.sendCommand(ItunesController::CommandName::REMOVEDEADFILES,500)
115
+ assertCommandLog(["getTrackCount() = 0"])
116
+ client.disconnect
117
+ ensure
118
+ teardownServer
119
+ end
120
+ puts("--Test Finish:#{this_method()}")
121
+ end
122
+
123
+ def test_AddFiles
124
+ puts("\n-- Test Start: #{this_method()}")
125
+ setupServer
126
+ begin
127
+ client=DummyClient.new
128
+ client.connect("localhost",@port)
129
+ client.login(BaseServerTest::USER,BaseServerTest::PASSWORD)
130
+
131
+ client.sendCommand(ItunesController::CommandName::FILE+":/blah", 220);
132
+ client.sendCommand(ItunesController::CommandName::FILE+":/blah1/shows's/S01E01 - The Episode.m4v", 220);
133
+ client.sendCommand(ItunesController::CommandName::FILE+":/blah/blah2", 220);
134
+ client.sendCommand(ItunesController::CommandName::ADDFILES, 220);
135
+ client.sendCommand(ItunesController::CommandName::HELO, 220);
136
+
137
+ commandLog = ItunesController::DummyITunesController::getCommandLog()
138
+
139
+ assertCommandLog(["getTrackCount() = 0",
140
+ "getTrackCount() = 0",
141
+ "addFilesToLibrary(/blah)",
142
+ "addFilesToLibrary(/blah1/shows's/S01E01 - The Episode.m4v)",
143
+ "addFilesToLibrary(/blah/blah2)"])
144
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
145
+ client.disconnect
146
+ ensure
147
+ teardownServer
148
+ assert(@server.stopped?)
149
+ end
150
+ puts("--Test Finish:#{this_method()}")
151
+ end
152
+
153
+ def test_RemoveFiles
154
+ puts("\n-- Test Start: #{this_method()}")
155
+ setupServer([ItunesController::Track.new("/blah",1,"Test 1"),
156
+ ItunesController::Track.new("/blah1/shows's/S01E01 - The Episode.m4v",2,"Test 2"),
157
+ ItunesController::Track.new("/blah1/blah2",3,"Test 3")])
158
+ begin
159
+ Dir.tmpdir do
160
+ client=DummyClient.new
161
+ client.connect("localhost",@port)
162
+ client.login(BaseServerTest::USER,BaseServerTest::PASSWORD)
163
+
164
+ files=[Dir.pwd+"/blah",
165
+ Dir.pwd+"/blah1/shows's/S01E01 - The Episode.m4v",
166
+ Dir.pwd+"/blah/blah2"]
167
+ files.each do | file |
168
+ File.open(file, "w") {}
169
+ client.sendCommand(ItunesController::CommandName::FILE+":"+file, 220);
170
+ end
171
+ client.sendCommand(ItunesController::CommandName::REMOVEFILES, 220);
172
+ client.sendCommand(ItunesController::CommandName::HELO, 220);
173
+
174
+ commandLog = ItunesController::DummyITunesController::getCommandLog()
175
+ expected=[]
176
+ expected.push("getTrackCount() = 0")
177
+ files.each do | file |
178
+ expected.push("addFilesToLibrary("+file+")")
179
+ end
180
+ files.each do | file |
181
+ expected.push("removeTracksFromLibrary(Location: '#{file}' - Database ID: 0 - Name: 'Test 0' )")
182
+ end
183
+ assertCommandLog(expected)
184
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
185
+ client.disconnect
186
+ end
187
+ ensure
188
+ teardownServer
189
+ assert(@server.stopped?)
190
+ end
191
+ puts("--Test Finish:#{this_method()}")
192
+ end
193
+
194
+ def test_RefreshFiles
195
+ Dir.tmpdir do
196
+ puts("\n-- Test Start: #{this_method()}")
197
+ tracks = [ItunesController::Track.new(Dir.pwd+"/blah",1,"Test 1"),
198
+ ItunesController::Track.new(Dir.pwd+"/blah1/shows's/S01E01 - The Episode.m4v",2,"Test 2"),
199
+ ItunesController::Track.new(Dir.pwd+"/blah1/blah2",3,"Test 3")]
200
+ files=[]
201
+ tracks.each do | t |
202
+ File.open(file, "w") {}
203
+ files.push(t.location)
204
+ end
205
+ setupServer(tracks)
206
+ begin
207
+ client=DummyClient.new
208
+ client.connect("localhost",@port)
209
+ client.login(BaseServerTest::USER,BaseServerTest::PASSWORD)
210
+ client.sendCommand(ItunesController::CommandName::REFRESHFILES, 220);
211
+ client.sendCommand(ItunesController::CommandName::HELO, 220);
212
+
213
+ commandLog = ItunesController::DummyITunesController::getCommandLog()
214
+ assertCommandLog(["getTrackCount() = 0",
215
+ "addFilesToLibrary(/blah)",
216
+ "addFilesToLibrary(/blah1/shows's/S01E01 - The Episode.m4v)",
217
+ "addFilesToLibrary(/blah/blah2)",
218
+ "refreshTracks(Location: '/blah' - Database ID: 0 - Name: 'Test 0' )",
219
+ "refreshTracks(Location: '/blah1' - Database ID: 1 - Name: 'Test 1' )",
220
+ "refreshTracks(Location: '/blah/blah2' - Database ID: 2 - Name: 'Test 2' )"])
221
+
222
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
223
+ client.disconnect
224
+ ensure
225
+ teardownServer
226
+ assert(@server.stopped?)
227
+ end
228
+ puts("--Test Finish:#{this_method()}")
229
+ end
230
+ end
231
+
232
+ def test_ClearFiles
233
+ puts("\n-- Test Start: #{this_method()}")
234
+ setupServer
235
+ begin
236
+ client=DummyClient.new
237
+ client.connect("localhost",@port)
238
+ client.login(BaseServerTest::USER,BaseServerTest::PASSWORD)
239
+
240
+ client.sendCommand(ItunesController::CommandName::FILE+":/blah", 220);
241
+ client.sendCommand(ItunesController::CommandName::FILE+":/blah1", 220);
242
+ client.sendCommand(ItunesController::CommandName::FILE+":/blah/blah2", 220);
243
+ client.sendCommand(ItunesController::CommandName::CLEARFILES, 220);
244
+ client.sendCommand(ItunesController::CommandName::HELO, 220);
245
+
246
+ assertCommandLog(["getTrackCount() = 0"])
247
+
248
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
249
+ client.disconnect
250
+ ensure
251
+ teardownServer
252
+ assert(@server.stopped?)
253
+ end
254
+ puts("--Test Finish:#{this_method()}")
255
+ end
256
+
257
+ def test_ClearFiles2
258
+ puts("\n-- Test Start: #{this_method()}")
259
+ setupServer
260
+ begin
261
+ client=DummyClient.new
262
+ client.connect("localhost",@port)
263
+ client.login(BaseServerTest::USER,BaseServerTest::PASSWORD)
264
+
265
+ client.sendCommand(ItunesController::CommandName::CLEARFILES, 220);
266
+ client.sendCommand(ItunesController::CommandName::HELO, 220);
267
+
268
+ assertCommandLog(["getTrackCount() = 0"])
269
+
270
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
271
+ client.disconnect
272
+ ensure
273
+ teardownServer
274
+ assert(@server.stopped?)
275
+ end
276
+ puts("-- Test Finish:#{this_method()}")
277
+ end
278
+
279
+ def test_RemoveDeadFiles
280
+ puts("\n-- Test Start: #{this_method()}")
281
+ tracks=[ItunesController::Track.new("/blah",1,"Test 1"),
282
+ ItunesController::Track.new("/blah1/shows's/S01E01 - The Episode.m4v",2,"Test 2"),
283
+ ItunesController::Track.new("/blah1/blah2",3,"Test 3")]
284
+ setupServer(tracks)
285
+ begin
286
+ client=DummyClient.new
287
+ client.connect("localhost",@port)
288
+ client.login(BaseServerTest::USER,BaseServerTest::PASSWORD)
289
+
290
+ client.sendCommand(ItunesController::CommandName::REMOVEDEADFILES, 220);
291
+ client.sendCommand(ItunesController::CommandName::HELO, 220);
292
+
293
+ commandLog = ItunesController::DummyITunesController::getCommandLog()
294
+ expected=[]
295
+ expected.push("getTrackCount() = 3")
296
+ expected.push("getTrackCount() = 3")
297
+ expected.push("getTracks()")
298
+ expected.push("getTrackCount() = 3")
299
+ tracks.each do | t |
300
+ expected.push("removeTracksFromLibrary(Location: '#{t.location}' - Database ID: #{t.databaseId} - Name: '#{t.title}' )")
301
+ end
302
+ assertCommandLog(expected)
303
+ client.sendCommand(ItunesController::CommandName::QUIT,221)
304
+ client.disconnect
305
+ ensure
306
+ teardownServer
307
+ assert(@server.stopped?)
308
+ end
309
+ puts("-- Test Finish:#{this_method()}")
310
+ end
311
+
312
+ end
metadata ADDED
@@ -0,0 +1,185 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: itunes-controller
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - John-Paul Stanford
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: yard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: test-unit
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: escape
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: sqlite3
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: A application to control enable iTunes to be operated on a headless server
95
+ without the GUI. It provides a TCP server which can be connected to locally or remote
96
+ by other applications to control iTunes
97
+ email: dev@stanwood.org.uk
98
+ executables:
99
+ - addFiles.rb
100
+ - dummyiTunesController.rb
101
+ - itunesController.rb
102
+ - listDeadTracks.rb
103
+ - listNewTracks.rb
104
+ - recreateTrackCache.rb
105
+ - refreshFiles.rb
106
+ - removeDeadTracks.rb
107
+ - removeFiles.rb
108
+ - trackInfo.rb
109
+ extensions: []
110
+ extra_rdoc_files:
111
+ - LICENSE
112
+ - README
113
+ files:
114
+ - .buildpath
115
+ - .gitignore
116
+ - .project
117
+ - .rvmrc
118
+ - LICENSE
119
+ - README
120
+ - Rakefile
121
+ - TODO
122
+ - bin/addFiles.rb
123
+ - bin/dummyiTunesController.rb
124
+ - bin/itunesController.rb
125
+ - bin/listDeadTracks.rb
126
+ - bin/listNewTracks.rb
127
+ - bin/recreateTrackCache.rb
128
+ - bin/refreshFiles.rb
129
+ - bin/removeDeadTracks.rb
130
+ - bin/removeFiles.rb
131
+ - bin/trackInfo.rb
132
+ - itunes-controller.gemspec
133
+ - jar-stuff.sh
134
+ - lib/itunesController/application.rb
135
+ - lib/itunesController/cachedcontroller.rb
136
+ - lib/itunesController/config.rb
137
+ - lib/itunesController/controller_creator.rb
138
+ - lib/itunesController/controllserver.rb
139
+ - lib/itunesController/database/backend.rb
140
+ - lib/itunesController/database/database.rb
141
+ - lib/itunesController/database/sqlite3_backend.rb
142
+ - lib/itunesController/debug.rb
143
+ - lib/itunesController/dummy_itunes_track.rb
144
+ - lib/itunesController/dummy_itunescontroller.rb
145
+ - lib/itunesController/itunescontroller.rb
146
+ - lib/itunesController/itunescontroller_factory.rb
147
+ - lib/itunesController/kinds.rb
148
+ - lib/itunesController/logging.rb
149
+ - lib/itunesController/macosx_itunescontroller.rb
150
+ - lib/itunesController/platform.rb
151
+ - lib/itunesController/sqlite_creator.rb
152
+ - lib/itunesController/track.rb
153
+ - lib/itunesController/version.rb
154
+ - lib/itunesController/windows_itunescontroller.rb
155
+ - test/base_server_test_case.rb
156
+ - test/dummy_client.rb
157
+ - test/test_server.rb
158
+ homepage: http://code.google.com/p/itunes-remote-control-server/
159
+ licenses: []
160
+ post_install_message:
161
+ rdoc_options:
162
+ - --main
163
+ - README
164
+ require_paths:
165
+ - lib
166
+ required_ruby_version: !ruby/object:Gem::Requirement
167
+ none: false
168
+ requirements:
169
+ - - ! '>='
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ none: false
174
+ requirements:
175
+ - - ! '>='
176
+ - !ruby/object:Gem::Version
177
+ version: '0'
178
+ requirements: []
179
+ rubyforge_project:
180
+ rubygems_version: 1.8.21
181
+ signing_key:
182
+ specification_version: 3
183
+ summary: TCP command server that can be used to control iTunes headlessly
184
+ test_files: []
185
+ has_rdoc: yard