sensible-cinema 0.20.0 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -31,37 +31,40 @@ describe MplayerEdl do
31
31
  EOL
32
32
  end
33
33
 
34
-
35
- it "should ignore overlaps" do
36
- a = MplayerEdl.convert_to_edl({ "mutes"=>{105=>145}, "blank_outs" => {105 => 145} } )
37
- a.should == <<EOL
38
- 105.0 145.0 0
39
- EOL
40
- end
41
-
42
34
  it "should add to mutes" do
43
35
  a = MplayerEdl.convert_to_edl({ "mutes"=>{105=>106}, "blank_outs" => {110 => 111} }, 1 )
44
36
  a.should == <<EOL
45
37
  105.0 107.0 1
46
- 110.0 111.0 0
38
+ 110.0 112.0 0
47
39
  EOL
48
40
  end
49
41
 
50
42
  it "should catch overlaps from additions to mutes" do
51
- a = MplayerEdl.convert_to_edl({ "mutes"=>{105=>106}, "blank_outs" => {106 => 107} }, 1 )
52
- a.should == <<EOL
43
+ pending do
44
+ a = MplayerEdl.convert_to_edl({ "mutes"=>{105=>106}, "blank_outs" => {106 => 107} }, 1 )
45
+ a.should == <<-EOL
53
46
  105.0 106.0 1
54
47
  106.0 107.0 0
55
- EOL
56
- end
48
+ EOL
49
+ end
50
+ end
57
51
 
58
52
  it "should add to beginning and ending of mutes" do
59
53
  a = MplayerEdl.convert_to_edl({ "mutes"=>{105=>106}, "blank_outs" => {110 => 111} }, 1, 1 )
60
54
  a.should == <<EOL
61
55
  104.0 107.0 1
62
- 110.0 111.0 0
56
+ 109.0 112.0 0
63
57
  EOL
64
58
 
65
59
  end
60
+
61
+ it "should accomodate for split sections in some dvd's and order the output" do
62
+ a = MplayerEdl.convert_to_edl({ "mutes"=>{5=>6,105=>106}, "blank_outs" => {110 => 111}}, 0, 0, [103] )
63
+ a.should == <<-EOL
64
+ 2.0 3.0 1
65
+ 5.0 6.0 1
66
+ 7.0 8.0 0
67
+ EOL
68
+ end
66
69
 
67
70
  end
data/spec/notes CHANGED
@@ -1,3 +1,12 @@
1
+ watching a DVD "from the DVD" in smplayer seemed to have the right audio always. yep.
2
+
3
+ previewing section on HP 2 hours or so and the first thing overlapped the muted section in error...went too long...huh?
4
+ call ffmpeg -i C:\HP_AND_THE_CHAMBER_OF_SECRETS_edited_version.fulli_unedited.tmp.mpg -vcodec copy -acodec copy -ss 7260.0 -t 10.499 C:\HP_AND_THE_CHAMBER_OF_SECRETS_edited_version.1.avi
5
+ call ffmpeg -i C:\HP_AND_THE_CHAMBER_OF_SECRETS_edited_version.fulli_unedited.tmp.mpg -vcodec copy -acodec ac3 -vol 0 -ss 7270.5 -t 1.499 C:\HP_AND_THE_CHAMBER_OF_SECRETS_edited_version.2.avi
6
+ call ffmpeg -i C:\HP_AND_THE_CHAMBER_OF_SECRETS_edited_version.fulli_unedited.tmp.mpg -vcodec copy -acodec copy -ss 7272.0 -t 3.999 C:\HP_AND_THE_CHAMBER_OF_SECRETS_edited_version.3.avi
7
+
8
+ resulted in sectors of 13.17 1.93, 5.03 instead of 10.5, 1.5, and 4. huh?
9
+
1
10
  $ to fix mplayer out of sync audio:
2
11
  $ ffmpeg -i HP_AND_THE_CHAMBER_OF_SECRETS_edited_version.fulli_unedited.tmp.mpg -target ntsc-dvd -t 1600 yo.mpg
3
12
  seemed to be as good as adding a harddup via mplayer. except...umm...VLC can play it right so why can't mplayer? Hopefully all doesn't matter [?]
@@ -1,409 +1,435 @@
1
- =begin
2
- Copyright 2010, Roger Pack
3
- This file is part of Sensible Cinema.
4
-
5
- Sensible Cinema is free software: you can redistribute it and/or modify
6
- it under the terms of the GNU General Public License as published by
7
- the Free Software Foundation, either version 3 of the License, or
8
- (at your option) any later version.
9
-
10
- Sensible Cinema is distributed in the hope that it will be useful,
11
- but WITHOUT ANY WARRANTY; without even the implied warranty of
12
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
- GNU General Public License for more details.
14
-
15
- You should have received a copy of the GNU General Public License
16
- along with Sensible Cinema. If not, see <http://www.gnu.org/licenses/>.
17
- =end
18
-
19
- require 'ostruct'
20
- require File.expand_path(File.dirname(__FILE__) + '/common')
21
- load '../bin/sensible-cinema'
22
-
23
- module SensibleSwing
24
- describe MainWindow do
25
-
26
- it "should be able to start up" do
27
- MainWindow.new.dispose# doesn't crash :)
28
- end
29
-
30
- it "should auto-select a EDL if it matches a DVD's title" do
31
- MainWindow.new.single_edit_list_matches_dvd("19d121ae8dc40cdd70b57ab7e8c74f76").should_not be nil
32
- end
33
-
34
- it "should not auto-select if you pass it nil" do
35
- MainWindow.new.single_edit_list_matches_dvd(nil).should be nil
36
- end
37
-
38
- it "should not die if you choose a poorly formed edl (should warn)" do
39
- time_through = 0
40
- @subject.stub!(:single_edit_list_matches_dvd) {
41
- 'fake filename doesnt matter because we fake its being parsed'
42
- }
43
-
44
- @subject.stub!(:parse_edl) {
45
- if time_through == 0
46
- time_through += 1
47
- eval("a-----") # force it to throw a Syntax Error first time
48
- else
49
- "stuff"
50
- end
51
- }
52
- @subject.choose_dvd_and_edl_for_it
53
- @show_blocking_message_dialog_last_args.should_not be nil
54
- end
55
-
56
- it "should warn if you don't have enough disk space" do
57
- @subject.get_freespace('.').should be > 0
58
- @subject.get_freespace("c:\\nonexistent").should be > 0
59
- @subject.stub!(:get_freespace) {
60
- 0
61
- }
62
- @subject.get_save_to_filename 'dvd_title'
63
- @show_blocking_message_dialog_last_args[0].should =~ /may not be enough/
64
- end
65
-
66
- it "should not warn if you have enough free disk space" do
67
- @subject.stub!(:get_freespace) {
68
- 16_000_000_000
69
- }
70
- @subject.get_save_to_filename 'dvd_title'
71
- @show_blocking_message_dialog_last_args.should be nil
72
- end
73
-
74
- it "should not select a file if poorly formed" do
75
- @subject.stub!(:parse_edl) {
76
- eval("a----")
77
- }
78
- @subject.single_edit_list_matches_dvd 'fake md5'
79
- end
80
-
81
- def with_clean_edl_dir_as this
82
- FileUtils.rm_rf 'temp'
83
- Dir.mkdir 'temp'
84
- old_edl = MainWindow::EDL_DIR
85
- MainWindow.const_set(:EDL_DIR, 'temp')
86
- begin
87
- yield
88
- ensure
89
- MainWindow.const_set(:EDL_DIR, old_edl)
90
- end
91
- end
92
-
93
- it "should prompt if two EDL's match a DVD title" do
94
- with_clean_edl_dir_as 'temp' do
95
- MainWindow.new.single_edit_list_matches_dvd("BOBS_BIG_PLAN").should be nil
96
- Dir.chdir 'temp' do
97
- File.binwrite('a.txt', "\"disk_unique_id\" => \"abcdef1234\"")
98
- File.binwrite('b.txt', "\"disk_unique_id\" => \"abcdef1234\"")
99
- end
100
- MainWindow.new.single_edit_list_matches_dvd("abcdef1234").should be nil
101
- end
102
- end
103
-
104
- it "should modify path to have mencoder available" do
105
- ENV['PATH'].should include("mencoder")
106
- end
107
-
108
- it "should not modify path to have mplayer available" do
109
- ENV['PATH'].should_not include("mplayer")
110
- end
111
-
112
- before do
113
- @subject = MainWindow.new
114
- @subject.stub!(:choose_dvd_drive) {
115
- ["mock_dvd_drive", "Volume", "19d121ae8dc40cdd70b57ab7e8c74f76"] # happiest baby on the block
116
- }
117
- @subject.stub!(:get_mencoder_commands) { |*args|
118
- args[-5].should match(/abc/)
119
- @args = args
120
- 'fake get_mencoder_commands'
121
- }
122
- @subject.stub!(:new_filechooser) {
123
- FakeFileChooser.new
124
- }
125
- @subject.stub!(:get_drive_with_most_space_with_slash) {
126
- "e:\\"
127
- }
128
- @subject.stub!(:show_blocking_message_dialog) { |*args|
129
- @show_blocking_message_dialog_last_args = args
130
- }
131
- @subject.stub!(:get_user_input) {'01:00'}
132
- @subject.stub!(:system_blocking) { |command|
133
- @system_blocking_command = command
134
- }
135
-
136
- @subject.stub!(:system_non_blocking) { |command|
137
- @system_non_blocking_command = command
138
- Thread.new {} # fake out the return...
139
- }
140
- @subject.stub!(:open_file_to_edit_it) {}
141
-
142
- PlayAudio.stub!(:play) {
143
- # don't play anything, by default :)
144
- }
145
-
146
- @subject.stub!(:get_freespace) {
147
- # during testing, we *always* have enough free space :)
148
- 16_000_000_000
149
- }
150
-
151
- end
152
-
153
- after do
154
- @subject.background_thread.join if @subject.background_thread
155
- end
156
-
157
- class FakeFileChooser
158
- def set_title x; end
159
- def set_file y; end
160
- def go
161
- 'abc'
162
- end
163
- end
164
-
165
- # name like :@rerun_previous
166
- def click_button(name)
167
- @subject.instance_variable_get(name).simulate_click
168
- end
169
-
170
- it "should be able to do a normal copy to hard drive, edited" do
171
- @subject.system_non_blocking "ls"
172
- @subject.do_copy_dvd_to_hard_drive(false).should == [false, "abc.fulli_unedited.tmp.mpg"]
173
- File.exist?('test_file_to_see_if_we_have_permission_to_write_to_this_folder').should be false
174
- end
175
-
176
- it "should have a good default title of 1" do
177
- @subject.get_title_track({}).should == "1"
178
- descriptors = {"dvd_title_track" => "3"}
179
- @subject.get_title_track(descriptors).should == "3"
180
- end
181
-
182
- it "should call through to explorer for the full thing" do
183
- PlayAudio.stub!(:play) {
184
- @played = true
185
- }
186
- @subject.do_copy_dvd_to_hard_drive(false)
187
- @subject.background_thread.join
188
- @args[-4].should == nil
189
- @system_blocking_command.should match /explorer/
190
- @system_blocking_command.should_not match /fulli/
191
- @played.should == true
192
- end
193
-
194
- it "should be able to return the fulli name if it already exists" do
195
- FileUtils.touch "abc.fulli_unedited.tmp.mpg.done"
196
- @subject.do_copy_dvd_to_hard_drive(false,true).should == [true, "abc.fulli_unedited.tmp.mpg"]
197
- FileUtils.rm "abc.fulli_unedited.tmp.mpg.done"
198
- end
199
-
200
- it "should call explorer eventually, if it has to create the fulli file" do
201
- @subject.do_copy_dvd_to_hard_drive(true).should == [false, "abc.fulli_unedited.tmp.mpg"]
202
- join_background_thread
203
- @args[-2].should == 1
204
- @args[-3].should == "01:00"
205
- @system_non_blocking_command.should match /smplayer/
206
- @system_non_blocking_command.should_not match /fulli/
207
- end
208
-
209
- def prompt_for_start_and_end_times
210
- click_button(:@preview_section)
211
- join_background_thread
212
- @args[-2].should == 1
213
- @args[-3].should == "01:00"
214
- @system_non_blocking_command.should match /smplayer/
215
- end
216
-
217
- it "should prompt for start and end times" do
218
- prompt_for_start_and_end_times
219
- end
220
-
221
- temp_dir = Dir.tmpdir
222
-
223
- def join_background_thread
224
- @subject.background_thread.join # must be running...
225
- end
226
-
227
- it "should be able to preview unedited" do
228
- @subject.stub!(:get_user_input).and_return('06:00', '07:00')
229
- @subject.unstub!(:get_mencoder_commands)
230
- click_button(:@preview_section_unedited)
231
- join_background_thread # scary timing spec
232
- temp_file = temp_dir + '/vlc.temp.bat'
233
- File.read(temp_file).should include("59.99")
234
- end
235
-
236
- it "should call something for fast preview" do
237
- click_button(:@fast_preview)
238
- # pending ... @system_non_blocking_command.should =~ /ffmpeg.*ntsc-dvd/
239
- join_background_thread
240
- @system_blocking_command.should =~ /mplayer.*fast/ # pending, smplayer
241
- end
242
-
243
- it "should be able to rerun the latest start and end times with the rerun button" do
244
- prompt_for_start_and_end_times
245
- old_args = @args
246
- old_args.should_not == nil
247
- @args = nil
248
- click_button(:@rerun_preview).join
249
- @args.should == old_args
250
- @system_non_blocking_command.should match(/smplayer/)
251
- end
252
-
253
- it "should not die if you pass it the same start and end time frames--graceful acceptance" do
254
- @subject.stub!(:get_mencoder_commands) {
255
- raise MencoderWrapper::TimingError
256
- }
257
- click_button(:@rerun_preview)
258
- @show_blocking_message_dialog_last_args[0].should =~ /you chose a time frame/
259
- end
260
-
261
- it "should not die if you pass it the same start and end time frames--graceful acceptance" do
262
- @subject.stub!(:get_mencoder_commands) {
263
- raise Errno::EACCES
264
- }
265
- click_button(:@rerun_preview) # lodo rspec error: wrong backtrace if no => e!
266
- @show_blocking_message_dialog_last_args[0].should =~ /a file/
267
- end
268
-
269
- it "should warn if you watch an edited time frame with no edits in it" do
270
- @subject.unstub!(:get_mencoder_commands)
271
- click_button(:@preview_section)
272
- @show_blocking_message_dialog_last_args[0].should =~ /unable to/
273
- @subject.stub!(:get_user_input).and_return('06:00', '07:00')
274
- # rspec bug: wrong'ish backtrace: proc { prompt_for_start_and_end_times #}.should_not raise_error LODO
275
- click_button(:@preview_section)
276
- join_background_thread
277
- @system_blocking_command.should == "echo wrote (probably successfully) to abc.avi"
278
- end
279
-
280
- it "if the .done files exists, watch unedited should call smplayer ja" do
281
- FileUtils.touch "abc.fulli_unedited.tmp.mpg.done"
282
- @subject.instance_variable_get(:@watch_unedited).simulate_click
283
- @system_non_blocking_command.should == "smplayer abc.fulli_unedited.tmp.mpg"
284
- FileUtils.rm "abc.fulli_unedited.tmp.mpg.done"
285
- end
286
-
287
- it "if the .done file does not exist, watch unedited should call smplayer after x seconds" do
288
- @subject.stub!(:sleep) {
289
- @slept = true
290
- } # speed this test up...
291
- @subject.unstub!(:get_mencoder_commands)
292
- click_button(:@watch_unedited).join
293
- join_background_thread
294
- @system_blocking_command.should_not == nil
295
- @slept.should == true
296
- @show_blocking_message_dialog_last_args.should == nil
297
- end
298
-
299
- it "should create a new file for ya" do
300
- out = MainWindow::EDL_DIR + "/sweetest_disc_ever.txt"
301
- File.exist?( out ).should be_false
302
- @subject.stub!(:get_user_input) {'sweetest disc ever'}
303
- @subject.instance_variable_get(:@create_new_edl_for_current_dvd).simulate_click
304
- begin
305
- File.exist?( out ).should be_true
306
- content = File.read(out)
307
- content.should_not include("\"title\"")
308
- content.should include("disk_unique_id")
309
- content.should include("dvd_title_track")
310
- ensure
311
- FileUtils.rm_rf out
312
- end
313
- end
314
-
315
- it "should display unique disc in an input box" do
316
- @subject.instance_variable_get(:@display_unique).simulate_click.should == "01:00"
317
- end
318
-
319
- it "should create an edl and pass it through to mplayer" do
320
- click_button(:@mplayer_edl).join
321
- @system_blocking_command.should match(/mplayer.*-edl/)
322
- @system_blocking_command.should match(/-dvd-device /)
323
- end
324
-
325
- it "should play edl with elongated mutes" do
326
- temp_file = temp_dir + '/mplayer.temp.edl'
327
- click_button(:@mplayer_edl).join
328
- wrote = File.read(temp_file)
329
- # normally "378.0 379.1 1\n"
330
- wrote.should include("380.85 1")
331
- end
332
-
333
- def should_allow_for_changing_file corrupt_the_file = false
334
- with_clean_edl_dir_as 'temp' do
335
- File.binwrite('temp/a.txt', "\"disk_unique_id\" => \"abcdef1234\"")
336
- @subject.stub!(:choose_dvd_drive) {
337
- ["mock_dvd_drive", "Volume", "abcdef1234"]
338
- }
339
- @subject.choose_dvd_and_edl_for_it[4]['mutes'].should == []
340
- new_file_contents = '"disk_unique_id" => "abcdef1234","mutes"=>["0:33", "0:34"]'
341
- new_file_contents = '"a syntax error' if corrupt_the_file
342
- File.binwrite('temp/a.txt', new_file_contents)
343
- # file has been modified!
344
- @subject.choose_dvd_and_edl_for_it[4]['mutes'].should_not == []
345
- end
346
- end
347
-
348
- it "should allow for file to change contents while editing it" do
349
- should_allow_for_changing_file
350
- end
351
-
352
- it "should prompt you if you re-choose, and your file now has a failure in it" do
353
- @subject.stub(:show_blocking_message_dialog) {
354
- @got_here = true
355
- @subject.stub(:parse_edl) { 'pass the second time through' }
356
- }
357
- should_allow_for_changing_file true
358
- @got_here.should == true
359
- end
360
-
361
- it "should only prompt for save to filename once" do
362
- count = 0
363
- @subject.stub!(:new_filechooser) {
364
- count += 1
365
- FakeFileChooser.new
366
- }
367
- @subject.get_save_to_filename 'yo'
368
- @subject.get_save_to_filename 'yo'
369
- count.should == 1
370
- end
371
-
372
- describe 'with unstubbed choose_dvd_drive' do
373
- before do
374
- DriveInfo.stub!(:get_dvd_drives_as_openstruct) {
375
- a = OpenStruct.new
376
- # NB no VolumeName set
377
- a.Name = 'a name'
378
- [a]
379
- }
380
- @subject.unstub!(:choose_dvd_drive)
381
- end
382
-
383
- it "should only prompt for drive once" do
384
- count = 0
385
- DriveInfo.stub!(:md5sum_disk) {
386
- count += 1
387
- '19d121ae8dc40cdd70b57ab7e8c74f76'
388
- }
389
- @subject.choose_dvd_and_edl_for_it
390
- @subject.choose_dvd_and_edl_for_it
391
- count.should == 1
392
- end
393
-
394
- it "should prompt you if you need to insert a dvd" do
395
- proc {@subject.choose_dvd_drive }.should raise_error(/might not yet have.*in it/)
396
- @show_blocking_message_dialog_last_args.should_not be nil
397
- end
398
- end
399
-
400
- it "should not show the normal buttons in create mode" do
401
- MainWindow.new.buttons.length.should == 3 # exit button, two normal buttons
402
- ARGV << "--create-mode"
403
- MainWindow.new.buttons.length.should == 10
404
- ARGV.pop # test cleanup--why not :)
405
- end
406
-
407
- end
408
-
409
- end
1
+ =begin
2
+ Copyright 2010, Roger Pack
3
+ This file is part of Sensible Cinema.
4
+
5
+ Sensible Cinema is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ Sensible Cinema is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with Sensible Cinema. If not, see <http://www.gnu.org/licenses/>.
17
+ =end
18
+
19
+ require 'ostruct'
20
+ require File.expand_path(File.dirname(__FILE__) + '/common')
21
+ load '../bin/sensible-cinema'
22
+
23
+ module SensibleSwing
24
+ describe MainWindow do
25
+
26
+ it "should be able to start up" do
27
+ MainWindow.new.dispose# doesn't crash :)
28
+ end
29
+
30
+ it "should auto-select a EDL if it matches a DVD's title" do
31
+ MainWindow.new.single_edit_list_matches_dvd("19d121ae8dc40cdd70b57ab7e8c74f76").should_not be nil
32
+ end
33
+
34
+ it "should not auto-select if you pass it nil" do
35
+ MainWindow.new.single_edit_list_matches_dvd(nil).should be nil
36
+ end
37
+
38
+ it "should not die if you choose a poorly formed edl (should warn)" do
39
+ time_through = 0
40
+ @subject.stub!(:single_edit_list_matches_dvd) {
41
+ 'fake filename doesnt matter because we fake its being parsed'
42
+ }
43
+
44
+ @subject.stub!(:parse_edl) {
45
+ if time_through == 0
46
+ time_through += 1
47
+ eval("a-----") # force it to throw a Syntax Error first time
48
+ else
49
+ "stuff"
50
+ end
51
+ }
52
+ @subject.choose_dvd_and_edl_for_it
53
+ @show_blocking_message_dialog_last_arg.should_not be nil
54
+ end
55
+
56
+ it "should warn if you don't have enough disk space" do
57
+ @subject.get_freespace('.').should be > 0
58
+ @subject.get_freespace("c:\\nonexistent").should be > 0
59
+ @subject.stub!(:get_freespace) {
60
+ 0
61
+ }
62
+ @subject.get_save_to_filename 'dvd_title'
63
+ @show_blocking_message_dialog_last_arg.should =~ /may not be enough/
64
+ end
65
+
66
+ it "should not warn if you have enough free disk space" do
67
+ @subject.stub!(:get_freespace) {
68
+ 16_000_000_000
69
+ }
70
+ @subject.get_save_to_filename 'dvd_title'
71
+ @show_blocking_message_dialog_last_arg.should be nil
72
+ end
73
+
74
+ it "should not select a file if poorly formed" do
75
+ @subject.stub!(:parse_edl) {
76
+ eval("a----")
77
+ }
78
+ @subject.single_edit_list_matches_dvd('fake md5') # doesn't die
79
+ end
80
+
81
+ def with_clean_edl_dir_as this
82
+ FileUtils.rm_rf 'temp'
83
+ Dir.mkdir 'temp'
84
+ old_edl = MainWindow::EDL_DIR
85
+ MainWindow.const_set(:EDL_DIR, 'temp')
86
+ begin
87
+ yield
88
+ ensure
89
+ MainWindow.const_set(:EDL_DIR, old_edl)
90
+ end
91
+ end
92
+
93
+ it "should prompt if two EDL's match a DVD title" do
94
+ MainWindow.new.single_edit_list_matches_dvd("BOBS_BIG_PLAN").should be nil
95
+ with_clean_edl_dir_as 'temp' do
96
+ MainWindow.new.single_edit_list_matches_dvd("BOBS_BIG_PLAN").should be nil
97
+ Dir.chdir 'temp' do
98
+ File.binwrite('a.txt', "\"disk_unique_id\" => \"abcdef1234\"")
99
+ File.binwrite('b.txt', "\"disk_unique_id\" => \"abcdef1234\"")
100
+ end
101
+ MainWindow.new.single_edit_list_matches_dvd("abcdef1234").should be nil
102
+ end
103
+ end
104
+
105
+ it "should modify path to have mencoder available" do
106
+ ENV['PATH'].should include("mencoder")
107
+ end
108
+
109
+ it "should not modify path to have mplayer available" do
110
+ ENV['PATH'].should_not include("mplayer")
111
+ end
112
+
113
+ before do
114
+ @subject = MainWindow.new
115
+ @subject.stub!(:choose_dvd_drive) {
116
+ ["mock_dvd_drive", "Volume", "19d121ae8dc40cdd70b57ab7e8c74f76"] # happiest baby on the block
117
+ }
118
+ @subject.stub!(:get_mencoder_commands) { |*args|
119
+ args[-5].should match(/abc/)
120
+ @args = args
121
+ 'fake get_mencoder_commands'
122
+ }
123
+ @subject.stub!(:new_filechooser) {
124
+ FakeFileChooser.new
125
+ }
126
+ @subject.stub!(:get_drive_with_most_space_with_slash) {
127
+ "e:\\"
128
+ }
129
+ @subject.stub!(:show_blocking_message_dialog) { |*args|
130
+ @show_blocking_message_dialog_last_arg = args[0]
131
+ }
132
+
133
+ @subject.stub!(:get_user_input) {'01:00'}
134
+ @subject.stub!(:system_blocking) { |command|
135
+ @system_blocking_command = command
136
+ }
137
+
138
+ @subject.stub!(:system_non_blocking) { |command|
139
+ @system_non_blocking_command = command
140
+ Thread.new {} # fake out the return...
141
+ }
142
+ @subject.stub!(:open_file_to_edit_it) {}
143
+
144
+ PlayAudio.stub!(:play) {
145
+ # don't play anything, by default :)
146
+ }
147
+
148
+ @subject.stub!(:get_freespace) {
149
+ # during testing, we *always* have enough free space :)
150
+ 16_000_000_000
151
+ }
152
+ # less chatty...
153
+ @subject.stub!(:p) {}
154
+ @subject.stub!(:puts) {}
155
+
156
+ end
157
+
158
+ after do
159
+ @subject.background_thread.join if @subject.background_thread
160
+ end
161
+
162
+ class FakeFileChooser
163
+ def set_title x; end
164
+ def set_file y; end
165
+ def go
166
+ 'abc'
167
+ end
168
+ end
169
+
170
+ # name like :@rerun_previous
171
+ def click_button(name)
172
+ @subject.instance_variable_get(name).simulate_click
173
+ end
174
+
175
+ it "should be able to do a normal copy to hard drive, edited" do
176
+ @subject.system_non_blocking "ls"
177
+ @subject.do_copy_dvd_to_hard_drive(false).should == [false, "abc.fulli_unedited.tmp.mpg"]
178
+ File.exist?('test_file_to_see_if_we_have_permission_to_write_to_this_folder').should be false
179
+ end
180
+
181
+ it "should have a good default title of 1" do
182
+ @subject.get_title_track({}).should == "1"
183
+ descriptors = {"dvd_title_track" => "3"}
184
+ @subject.get_title_track(descriptors).should == "3"
185
+ end
186
+
187
+ it "should call through to explorer for the full thing" do
188
+ PlayAudio.stub!(:play) {
189
+ @played = true
190
+ }
191
+ @subject.do_copy_dvd_to_hard_drive(false)
192
+ @subject.background_thread.join
193
+ @args[-4].should == nil
194
+ @system_blocking_command.should match /explorer/
195
+ @system_blocking_command.should_not match /fulli/
196
+ @played.should == true
197
+ end
198
+
199
+ it "should be able to return the fulli name if it already exists" do
200
+ FileUtils.touch "abc.fulli_unedited.tmp.mpg.done"
201
+ @subject.do_copy_dvd_to_hard_drive(false,true).should == [true, "abc.fulli_unedited.tmp.mpg"]
202
+ FileUtils.rm "abc.fulli_unedited.tmp.mpg.done"
203
+ end
204
+
205
+ it "should call explorer eventually, if it has to create the fulli file" do
206
+ @subject.do_copy_dvd_to_hard_drive(true).should == [false, "abc.fulli_unedited.tmp.mpg"]
207
+ join_background_thread
208
+ @args[-2].should == 1
209
+ @args[-3].should == "01:00"
210
+ @system_non_blocking_command.should match /smplayer/
211
+ @system_non_blocking_command.should_not match /fulli/
212
+ end
213
+
214
+ def prompt_for_start_and_end_times
215
+ click_button(:@preview_section)
216
+ join_background_thread
217
+ @args[-2].should == 1
218
+ @args[-3].should == "01:00"
219
+ @system_non_blocking_command.should match /smplayer/
220
+ end
221
+
222
+ it "should prompt for start and end times" do
223
+ prompt_for_start_and_end_times
224
+ end
225
+
226
+ temp_dir = Dir.tmpdir
227
+
228
+ def join_background_thread
229
+ @subject.background_thread.join # must be running...
230
+ end
231
+
232
+ it "should be able to preview unedited" do
233
+ @subject.stub!(:get_user_input).and_return('06:00', '07:00')
234
+ @subject.unstub!(:get_mencoder_commands)
235
+ click_button(:@preview_section_unedited)
236
+ join_background_thread # scary timing spec
237
+ temp_file = temp_dir + '/vlc.temp.bat'
238
+ File.read(temp_file).should include("59.99")
239
+ end
240
+
241
+ it "should call something for fast preview" do
242
+ click_button(:@fast_preview).join
243
+ join_background_thread
244
+ #XXXX @system_blocking_command.should =~ /ffmpeg.*ntsc-dvd/ # I think this is a timing thing...
245
+ @system_blocking_command.should =~ /mplayer.*fast/ # pending, smplayer
246
+ end
247
+
248
+ it "should be able to rerun the latest start and end times with the rerun button" do
249
+ prompt_for_start_and_end_times
250
+ old_args = @args
251
+ old_args.should_not == nil
252
+ @args = nil
253
+ click_button(:@rerun_preview).join
254
+ @args.should == old_args
255
+ @system_non_blocking_command.should match(/smplayer/)
256
+ end
257
+
258
+ it "should not die if you pass it the same start and end time frames--graceful acceptance" do
259
+ @subject.stub!(:get_mencoder_commands) {
260
+ raise MencoderWrapper::TimingError
261
+ }
262
+ click_button(:@rerun_preview)
263
+ @show_blocking_message_dialog_last_arg.should =~ /you chose a time frame/
264
+ end
265
+
266
+ it "should not die if you pass it the same start and end time frames--graceful acceptance" do
267
+ @subject.stub!(:get_mencoder_commands) {
268
+ raise Errno::EACCES
269
+ }
270
+ click_button(:@rerun_preview) # lodo rspec error: wrong backtrace if no => e!
271
+ @show_blocking_message_dialog_last_arg.should =~ /a file/
272
+ end
273
+
274
+ it "should warn if you watch an edited time frame with no edits in it" do
275
+ @subject.unstub!(:get_mencoder_commands)
276
+ click_button(:@preview_section)
277
+ @show_blocking_message_dialog_last_arg.should =~ /unable to/
278
+ @subject.stub!(:get_user_input).and_return('06:00', '07:00')
279
+ # rspec bug: wrong'ish backtrace: proc { prompt_for_start_and_end_times #}.should_not raise_error LODO
280
+ click_button(:@preview_section)
281
+ join_background_thread
282
+ @system_blocking_command.should == "echo wrote (probably successfully) to abc.avi"
283
+ end
284
+
285
+ it "if the .done files exists, watch unedited should call smplayer ja" do
286
+ FileUtils.touch "abc.fulli_unedited.tmp.mpg.done"
287
+ @subject.instance_variable_get(:@watch_unedited).simulate_click
288
+ @system_non_blocking_command.should == "smplayer abc.fulli_unedited.tmp.mpg"
289
+ FileUtils.rm "abc.fulli_unedited.tmp.mpg.done"
290
+ end
291
+
292
+ it "if the .done file does not exist, watch unedited should call smplayer after x seconds" do
293
+ @subject.stub!(:sleep) {
294
+ @slept = true
295
+ } # speed this test up...
296
+ @subject.unstub!(:get_mencoder_commands)
297
+ click_button(:@watch_unedited).join
298
+ join_background_thread
299
+ @system_blocking_command.should_not == nil
300
+ @slept.should == true
301
+ @show_blocking_message_dialog_last_arg.should == nil
302
+ end
303
+
304
+ it "should create a new file for ya" do
305
+ out = MainWindow::EDL_DIR + "/sweetest_disc_ever.txt"
306
+ File.exist?( out ).should be_false
307
+ @subject.stub!(:get_user_input) {'sweetest disc ever'}
308
+ @subject.instance_variable_get(:@create_new_edl_for_current_dvd).simulate_click
309
+ begin
310
+ File.exist?( out ).should be_true
311
+ content = File.read(out)
312
+ content.should_not include("\"title\"")
313
+ content.should include("disk_unique_id")
314
+ content.should include("dvd_title_track")
315
+ content.should include("mplayer_dvd_splits")
316
+ ensure
317
+ FileUtils.rm_rf out
318
+ end
319
+ end
320
+
321
+ it "should display unique disc in an input box" do
322
+ @subject.instance_variable_get(:@display_unique).simulate_click.should == "01:00"
323
+ end
324
+
325
+ it "should create an edl and pass it through to mplayer" do
326
+ click_button(:@mplayer_edl).join
327
+ @system_blocking_command.should match(/mplayer.*-edl/)
328
+ @system_blocking_command.should match(/-dvd-device /)
329
+ end
330
+
331
+ it "should play edl with elongated mutes" do
332
+ click_button(:@mplayer_edl).join
333
+ wrote = File.read(MainWindow::EdlTempFile)
334
+ # normally "378.0 379.1 1"
335
+ p wrote
336
+ wrote.should include("377.5 379.1 1")
337
+ end
338
+
339
+ def should_allow_for_changing_file corrupt_the_file = false
340
+ with_clean_edl_dir_as 'temp' do
341
+ File.binwrite('temp/a.txt', "\"disk_unique_id\" => \"abcdef1234\"")
342
+ @subject.stub!(:choose_dvd_drive) {
343
+ ["mock_dvd_drive", "Volume", "abcdef1234"]
344
+ }
345
+ @subject.choose_dvd_and_edl_for_it[4]['mutes'].should == []
346
+ new_file_contents = '"disk_unique_id" => "abcdef1234","mutes"=>["0:33", "0:34"]'
347
+ new_file_contents = '"a syntax error' if corrupt_the_file
348
+ File.binwrite('temp/a.txt', new_file_contents)
349
+ # file has been modified!
350
+ @subject.choose_dvd_and_edl_for_it[4]['mutes'].should_not == []
351
+ end
352
+ end
353
+
354
+ it "should allow for file to change contents while editing it" do
355
+ should_allow_for_changing_file
356
+ end
357
+
358
+ it "should prompt you if you re-choose, and your file now has a failure in it" do
359
+ @subject.stub(:show_blocking_message_dialog) {
360
+ @got_here = true
361
+ @subject.stub(:parse_edl) { 'pass the second time through' }
362
+ }
363
+ should_allow_for_changing_file true
364
+ @got_here.should == true
365
+ end
366
+
367
+ it "should only prompt for save to filename once" do
368
+ count = 0
369
+ @subject.stub!(:new_filechooser) {
370
+ count += 1
371
+ FakeFileChooser.new
372
+ }
373
+ @subject.get_save_to_filename 'yo'
374
+ @subject.get_save_to_filename 'yo'
375
+ count.should == 1
376
+ end
377
+
378
+ describe 'with unstubbed choose_dvd_drive' do
379
+ before do
380
+ DriveInfo.stub!(:get_dvd_drives_as_openstruct) {
381
+ a = OpenStruct.new
382
+ # NB no VolumeName set
383
+ a.Name = 'a name'
384
+ [a]
385
+ }
386
+ @subject.unstub!(:choose_dvd_drive)
387
+ end
388
+
389
+ it "should only prompt for drive once" do
390
+ count = 0
391
+ DriveInfo.stub!(:md5sum_disk) {
392
+ count += 1
393
+ '19d121ae8dc40cdd70b57ab7e8c74f76'
394
+ }
395
+ @subject.choose_dvd_and_edl_for_it
396
+ @subject.choose_dvd_and_edl_for_it
397
+ count.should == 1
398
+ end
399
+
400
+ it "should prompt you if you need to insert a dvd" do
401
+ proc {@subject.choose_dvd_drive}.should raise_error(/might not yet have.*in it/)
402
+ @show_blocking_message_dialog_last_arg.should_not be nil
403
+ end
404
+ end
405
+
406
+ it "should not show the normal buttons in create mode" do
407
+ MainWindow.new.buttons.length.should == 3 # exit button, two normal buttons
408
+ ARGV << "--create-mode"
409
+ MainWindow.new.buttons.length.should == 10
410
+ ARGV.pop # test cleanup--why not :)
411
+ end
412
+
413
+ it "should read splits from the file" do
414
+ splits1 = nil
415
+ MplayerEdl.stub(:convert_to_edl) do |d,s,s,splits|
416
+ splits1 = splits
417
+ end
418
+ @subject.do_mplayer_edl nil, 0, 0
419
+ splits1.should == []
420
+ end
421
+
422
+ it "should warn if there are no DVD splits and you try to use EDL" do
423
+ with_clean_edl_dir_as 'temp' do
424
+ File.binwrite('temp/a.txt', "\"disk_unique_id\" => \"abcdef1234\"")
425
+ @subject.stub!(:choose_dvd_drive) {
426
+ ["mock_dvd_drive", "mockVolume", "abcdef1234"]
427
+ }
428
+ @subject.do_mplayer_edl(nil, 0, 0)
429
+ @show_blocking_message_dialog_last_arg.should =~ /does not contain mplayer replay information \[mplayer_dvd_splits\]/
430
+ end
431
+ end
432
+
433
+ end # describe MainWindow
434
+
435
+ end