forked from rastersoft/Devede
-
Notifications
You must be signed in to change notification settings - Fork 0
/
devede_newfiles.py
executable file
·1796 lines (1464 loc) · 51.2 KB
/
devede_newfiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# Copyright 2006-2009 (C) Raster Software Vigo (Sergio Costas)
# Copyright 2006-2009 (C) Peter Gill - win32 parts
# This file is part of DeVeDe
#
# DeVeDe is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# DeVeDe is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import stat
import pygtk # for testing GTK version number
pygtk.require ('2.0')
import gtk
import gobject
import sys
import gc
import copy
import time
import devede_other
import devede_executor
import devede_convert
import devede_dialogs
import devede_help
import math
# How to add new file options:
# In the class NEWFILE, method CREATE_DEFAULT_VIDEO_PARAMETERS, add the new option
# to the SELF.FILE_PROPERTIES dictionary, setting its default value based in the
# SELF.FILE_VALUES values (the ones obtained with MPLAYER --IDENTIFY), SELF.PAL (True
# for PAL output video, False for NTSC output video) and SELF.DISCTOCREATE (DVD, VCD, SVCD
# CVD or DIVX)
# In the class FILE_PROPERTIES
# In the method GET_WIDGETS, set the parameter value in the SELF.FILE_PROPERTIES
# dictionary using the widget's current value
# In the method SET_WIDGETS, set the widget's value using the parameter value in
# SELF.FILE_PROPERTIES
# If the widget must be disabled or enabled under some circumstances (other widgets)
# set that code in method SET_FILM_BUTTONS
#
# Finally, add the needed code in DEVEDE_LOADSAVE.PY to ensure that old project files
# work fine with the new options
class file_get_params(devede_executor.executor):
def read_file_values(self,filename,check_audio):
""" Reads the values of the video (width, heigth, fps...) and stores them
into file_values.
Returns (False,AUDIO) if the file is not a video (with AUDIO the number
of audio tracks)
Returns (True,0) if the file is a right video file """
handler=''
vrate=0
arate=0
width=0
height=0
fps=0
length=0
audio=0
video=0
audiorate=0
aspect_ratio=1.3333333333
self.length=0
# if CHECK_AUDIO is TRUE, we just check if it's an audio file
if check_audio:
nframes=0
else:
nframes=1
if (sys.platform=="win32") or (sys.platform=="win64"):
command="mplayer.exe"
else:
command="mplayer"
launcher=[command, "-loop","1","-identify", "-ao", "null", "-vo", "null", "-frames", str(nframes), filename]
handler=self.launch_program(launcher, win32arg=False,with_stderr=False)
minimum_audio=10000
audio_list=[]
while True:
linea=handler.stdout.readline()
linea=self.remove_ansi(linea)
if linea=="":
break
position=linea.find("ID_")
if position==-1:
continue
linea=linea[position:]
if linea[:16]=="ID_VIDEO_BITRATE":
vrate=int(linea[17:])
if linea[:14]=="ID_VIDEO_WIDTH":
width=int(linea[15:])
if linea[:15]=="ID_VIDEO_HEIGHT":
height=int(linea[16:])
if linea[:15]=="ID_VIDEO_ASPECT":
aspect_ratio=float(linea[16:])
if linea[:12]=="ID_VIDEO_FPS":
fps2=linea[13:]
while ord(fps2[-1])<32:
fps2=fps2[:-1]
posic=linea.find(".")
if posic==-1:
fps=int(linea[13:])
else:
fps=int(linea[13:posic])
if linea[posic+1]=="9":
fps+=1
if linea[:16]=="ID_AUDIO_BITRATE":
arate=int(linea[17:])
if linea[:13]=="ID_AUDIO_RATE":
audiorate=int(linea[14:])
if linea[:9]=="ID_LENGTH":
length=int(float(linea[10:]))
if linea[:11]=="ID_VIDEO_ID":
video+=1
if linea[:11]=="ID_AUDIO_ID":
audio+=1
audio_track=int(linea[12:])
if minimum_audio>audio_track:
minimum_audio=audio_track
audio_list.append(audio_track)
handler.wait()
if (video==0) or (width==0) or (height==0):
if (audio!=0):
self.length=length
self.audio=audio
return False,audio
if aspect_ratio==0.0 or math.isnan(aspect_ratio) :
aspect_ratio=(float(width))/(float(height))
if aspect_ratio<=1.5:
aspect_ratio=(4.0/3.0)
self.file_values={}
self.file_values["vrate"]=vrate
self.file_values["arate"]=arate
self.file_values["video_streams"]=video
self.file_values["audio_streams"]=audio
self.file_values["width"]=width
self.file_values["height"]=height
self.file_values["fps"]=fps
self.file_values["ofps2"]=fps2
self.file_values["length"]=length
self.file_values["aspect_ratio"]=aspect_ratio
self.file_values["audiorate"]=audiorate
self.file_values["audio_list"]=audio_list
self.file_values["audio_stream"]=minimum_audio
return True,0
class newfile(file_get_params):
def __init__(self,pal,disctocreate):
""" This class manages every new film added. It reads its parameters (resolution, FPS, number of
channels...) and allows to generate the default values, both when choosing manually a file from the
Properties window, or when dragging&dropping them into the main window """
file_get_params.__init__(self)
self.pal=pal
self.disctocreate=disctocreate
self.file_values=None
self.file_properties=None
def get_recomended_resolution(self,vrate,arate,desired_resolution):
""" Returns the recomended resolution for a video based in its original
resolution and the resolution chosed by the user.
DESIRED_RESOLUTION is a value from 0 to 7:
0=auto, 1=720x480, 2=704x480, 3=480x480, 4=352x480, 5=352x240
6=1280x720, 7=1920x1080, 8 160x128
It returns the recomended audio and video rate for that resolution,
but only if the user hasn't changed them """
if self.pal:
nheigh1=576
nheigh2=288
else:
nheigh1=480
nheigh2=240
if self.file_values==None:
return 0,0,False,0,0
if desired_resolution==0: # default resolution; we have to take the most similar resolution
if self.disctocreate=="vcd":
resx=352
resy=nheigh2
elif self.disctocreate=="cvd":
resx=352
resy=nheigh1
elif self.disctocreate=="svcd":
resx=480
resy=nheigh1
else: # dvd o divx
if self.file_values["width"]<=352:
resx=352
if self.file_values["height"]<=nheigh2:
resy=nheigh2
else:
resy=nheigh1
else:
resx=720
resy=nheigh1
elif desired_resolution==1:
resx=720
resy=nheigh1
elif desired_resolution==2:
resx=704
resy=nheigh1
elif desired_resolution==3:
resx=480
resy=nheigh1
elif desired_resolution==4:
resx=352
resy=nheigh1
elif desired_resolution==5:
resx=352
resy=nheigh2
elif desired_resolution==6:
resx=1280
resy=720
elif desired_resolution==7:
resx=1920
resy=1080
elif desired_resolution==8:
resx=160
resy=128
if (((resx==720) and (resy==nheigh1)) or ((self.disctocreate=="divx") and (desired_resolution!=8))) and (self.file_values["aspect_ratio"]>=1.77):
use_widescreen=True
else:
use_widescreen=False
if (vrate==5001) or (vrate==3001) or (vrate==2001):
if (resx>703):
vrate=5001
if (resx==480) or ((resx==352) and (resy==nheigh1)):
vrate=3001
if (resx==352) and (resy==nheigh2):
vrate=2001
if (self.disctocreate!="dvd") and (self.disctocreate!="divx"):
vrate=2001
if self.disctocreate=="vcd":
vrate=1152
arate=224
return resx,resy,use_widescreen,vrate,arate
def create_default_video_parameters(self,filename):
""" This method fills the FILE_PROPERTIES property with the default values for the file.
It returns False if the file isn't a valid video. The tuple contains the number of sound
tracks found, so if it's different from 0, its an audio-only file. """
if filename==None:
return False,0
isvideo,audio_tracks=self.read_file_values(filename,True)
if isvideo==False:
return False,audio_tracks
isvideo,audio_tracks=self.read_file_values(filename,False) # get all the values in FILE_VALUES
while filename[-1]==os.sep:
filename=filename[:-1]
nombre=filename
while True: # get the filename without the path
posic=nombre.find(os.path.sep)
if posic==-1:
break
else:
nombre=nombre[posic+1:]
# filename[0]; path[1]; width[2]; heigh[3]; length[4] (seconds); original fps[5];
# original videorate["oarate"]; original audiorate[7];
# final videorate[8]; final arate[9]; final width[10]; final heigh[11];
# 0=Black bars, 1=Scale picture [12];
# length of chapters[13]; audio delay["fps"]; final fps["arateunc"]; original audio rate (uncompressed)["oaspect"];
# original aspect ratio[17]; final aspect ratio[18];
# 0=full length, 1=first half, 2=second half [19];
# Resolution: 0=auto, 1=720x480, 2=704x480, 3=480x480, 4=352x480, 5=352x240, 6=1280x720, 7=1920x1080 [20]
# extra parameters [21]
self.file_properties={}
self.file_properties["filename"]=nombre # filename without path
self.file_properties["path"]=filename # file with complete path
self.file_properties["owidth"]=self.file_values["width"] # original width
self.file_properties["oheight"]=self.file_values["height"] # original height
self.file_properties["olength"]=self.file_values["length"] # original length (in seconds)
self.file_properties["ovrate"]=self.file_values["vrate"]/1000 # original videorate (in kbytes/second)
self.file_properties["oarate"]=self.file_values["arate"]/1000 # original audiorate (in kbytes/second)
self.file_properties["arateunc"]=self.file_values["audiorate"] # original uncompressed audiorate
self.file_properties["oaspect"]=self.file_values["aspect_ratio"] # original aspect ratio
self.file_properties["audio_list"]=self.file_values["audio_list"][:]
self.file_properties["audio_stream"]=self.file_values["audio_stream"]
if self.pal:
self.file_properties["fps"]=25
else:
self.file_properties["fps"]=30
self.file_properties["ofps"]=self.file_values["fps"]
self.file_properties["ofps2"]=self.file_values["ofps2"]
self.file_properties["blackbars"]=0 # black bars, no scale
self.file_properties["lchapters"]=5
self.file_properties["adelay"]=0 # no audio delay
self.file_properties["cutting"]=0 # full length
self.file_properties["resolution"]=0 # output resolution = auto
self.file_properties["params"]="" # no mencoder extra parameters
self.file_properties["params_vf"]="" # no mencoder extra VF parameters
self.file_properties["params_lavc"]="" # no mencoder extra LAVC parameters
self.file_properties["params_lame"]="" # no mencoder extra LAME parameters
self.file_properties["ismpeg"]=False # is already an MPEG-2 compliant file
self.file_properties["copy_audio"]=False # recompress the audio
self.file_properties["isvob"]=False # recompress both audio and video
self.file_properties["swap_fields"]=False # swap fields in interlaced videos
self.file_properties["subfont_size"]=28 # subtitle font size
self.file_properties["sound51"]=False # don't use 5.1 sound
self.file_properties["gop12"]=True # GOP of 12 by default to increase compatibility
self.file_properties["filesize"]=os.stat(filename)[stat.ST_SIZE] # file size
self.file_properties["trellis"]=True # use trellis
self.file_properties["twopass"]=False # two pass encoding
self.file_properties["turbo1stpass"]=False # use turbo 1st pass on two pass encoding
self.file_properties["mbd"]=2 # maximum quality
self.file_properties["deinterlace"]="none" # don't deinterlace
self.file_properties["sub_list"]=[]
self.file_properties["force_subs"]=False
resx,resy,use_widescreen,vrate,arate=self.get_recomended_resolution(5001, 224, 0)
self.file_properties["width"]=resx
self.file_properties["height"]=resy
self.file_properties["vrate"]=vrate
self.file_properties["arate"]=arate
self.file_properties["rotate"]=0 # no rotation
self.file_properties["hmirror"]=False
self.file_properties["vmirror"]=False
if use_widescreen:
self.file_properties["aspect"]=1.7777777
else:
self.file_properties["aspect"]=1.3333333
self.file_properties["volume"]=100
return True,audio_tracks
def split_dnd(self,data):
""" Takes the list of files dragged into the window and returns them in a list """
lista=[]
item=""
tempo=""
mode=0
if (sys.platform=="win32") or (sys.platform=="win64"):
length=8
else:
length=7
cadena2=""
for elemento in data:
if (ord(elemento)<32):
cadena2+="\n"
else:
cadena2+=elemento
while(True):
pos=cadena2.find("file:///")
if (pos==-1):
break
pos2=cadena2.find("\n",pos)
if (pos2==-1):
cadena=cadena2[pos+length:]
cadena2=""
else:
cadena=cadena2[pos+length:pos2]
cadena2=cadena2[pos2:]
while (True):
pos=cadena.find("%")
if (pos==-1):
break
cadena=cadena[:pos]+chr(int(cadena[pos+1:pos+3],16))+cadena[pos+3:]
lista.append(cadena)
print "Dragged files: "+str(lista)
return lista
##################################################################################
class file_properties(newfile):
""" This class manages the properties window, where the user can choose the properties
of each video file """
def motion_cb(self,wid, context, x, y, time):
context.drag_status(gtk.gdk.ACTION_COPY, time)
return True
def drop_cb(self, wid, context, x, y, time):
# Used with windows drag and drop
print 'drop'
self.have_drag = False
if context.targets:
wid.drag_get_data(context, context.targets[0], time)
return True
return False
# public methods
def __init__(self,global_vars,title,chapter,structure,callback_refresh):
newfile.__init__(self,global_vars["PAL"],global_vars["disctocreate"])
self.gladefile=global_vars["gladefile"]
self.global_vars=global_vars
self.title=title
self.chapter=chapter
self.structure=structure
self.callback_refresh=callback_refresh
self.tree=devede_other.create_tree(self,"wfile",self.gladefile)
self.window=self.tree.get_object("wfile")
self.window.show()
self.window.drag_dest_set(0,[],0)
self.window.connect('drag_drop', self.drop_cb)
self.window.connect('drag_motion', self.motion_cb)
w = self.tree.get_object("expander_advanced")
w.set_expanded(self.global_vars["expand_advanced"])
if global_vars["PAL"]:
w=self.tree.get_object("video_pal")
else:
w=self.tree.get_object("video_ntsc")
w.set_active(True)
# Model and view for subtitles
# first element: position
# second: filename
# third: codepage
self.sub_model=gtk.ListStore(gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING)
self.sub_tree=self.tree.get_object("sub_treeview")
self.sub_tree.set_model(self.sub_model)
render1=gtk.CellRendererText()
column1=gtk.TreeViewColumn(_("Subtitle"),render1,text=1)
self.sub_tree.append_column(column1)
render2=gtk.CellRendererText()
column2=gtk.TreeViewColumn(_("Codepage"),render2,text=2)
self.sub_tree.append_column(column2)
render3=gtk.CellRendererText()
column3=gtk.TreeViewColumn(_("Language"),render3,text=3)
self.sub_tree.append_column(column3)
# Model and view for audio tracks
self.audio_model=gtk.ListStore(gobject.TYPE_STRING)
self.audio_view=self.tree.get_object("audiotrack")
self.audio_view.set_model(self.audio_model)
audiorender=gtk.CellRendererText()
self.audio_view.pack_start(audiorender,True)
self.audio_view.add_attribute(audiorender,"text",0)
w1 = self.tree.get_object("subtitles_label")
w2 = self.tree.get_object("frame_special")
w3 = self.tree.get_object("gop12")
w4 = self.tree.get_object("res1280x720")
w5 = self.tree.get_object("res1920x1080")
w6 = self.tree.get_object("subtitles_list")
w7 = self.tree.get_object("res160x128")
if (self.disctocreate == "divx"):
w1.show()
w2.hide()
w3.hide()
w4.show()
w5.show()
w6.hide()
w7.show()
else:
w1.hide()
w2.show()
w3.show()
w4.hide()
w5.hide()
w6.show()
w7.hide()
w=self.tree.get_object("noaudiotracks")
w.hide()
w=self.tree.get_object("file_split_frame")
if (self.disctocreate=="vcd") or (self.disctocreate=="svcd") or (self.disctocreate=="cvd"):
w.show()
else:
w.hide()
w = self.tree.get_object("frame_division") # SPLIT THE FILES IN CHAPTERS FOR EASY SEEKING
if (self.disctocreate == "dvd"):
w.show()
else:
w.hide()
self.set_resolution()
self.change_file=False
if (self.chapter!=-1): # we want to modify a chapter
the_chapter=structure[title][chapter]
print "Chequeo "+str(the_chapter["path"])
isvideo,audio_tracks=self.read_file_values(the_chapter["path"],True)
if isvideo==True:
self.read_file_values(the_chapter["path"],False) # get all the values in FILE_VALUES
self.file_properties=copy.deepcopy(the_chapter)
self.change_file=True # we are changing the file name manually
w=self.tree.get_object("moviefile")
print "Pongo nombre por propiedades"
w.set_filename(self.file_properties["path"])
else:
w1.set_sensitive(False)
else:
if (self.global_vars["filmpath"]!=""):
w=self.tree.get_object("moviefile")
w.set_current_folder(self.global_vars["filmpath"])
w=self.tree.get_object("moviefile")
self.file_filter_videos=gtk.FileFilter()
self.file_filter_videos.set_name(_("Video files"))
if (sys.platform!="win32") and (sys.platform!="win64"):
self.file_filter_videos.add_mime_type("video/*")
self.file_filter_videos.add_pattern("*.rmvb")
else:
self.file_filter_videos.add_custom(gtk.FILE_FILTER_FILENAME|gtk.FILE_FILTER_DISPLAY_NAME, self.custom_video_filter)
self.file_filter_all=gtk.FileFilter()
self.file_filter_all.set_name(_("All files"))
self.file_filter_all.add_pattern("*")
print "Anado filtro"
w.add_filter(self.file_filter_videos)
print "Anado filtro"
w.add_filter(self.file_filter_all)
self.set_widgets()
if (self.chapter!=-1): # we want to modify a chapter
self.set_global_values()
self.set_film_buttons()
if (self.chapter!=-1): # we want to modify a chapter
print "Modificando"
w=self.tree.get_object("fileaccept")
w.set_sensitive(True)
w=self.tree.get_object("preview_film")
w.set_sensitive(True)
print "Fin"
# help methods
def custom_video_filter(self, filter_info=None, data=None):
"""Custom file filter. Filter for video files when running on win32"""
video_types=["m2ts","wmv", "avi", "asf", "flv", "bin", "vob", "es", "ps", "pes","qt", "mov", "mp4", "mpg", "mpeg", "rm", "mkv", "nut", "nsv", "vivo", "fli", "yuv4mpeg", "cpk","ogm", "asx", "3gp"]
if os.path.splitext(filter_info[2])[1][1:] in video_types:
return True
return False
def get_desired_resolution(self):
""" Returns the resolution desired by the user as a single number """
if (self.tree.get_object("res160x128").get_active()):
return 8
if (self.tree.get_object("res1920x1080").get_active()):
return 7
if (self.tree.get_object("res1280x720").get_active()):
return 6
if (self.tree.get_object("res720x480").get_active()):
return 1
if (self.tree.get_object("res704x480").get_active()):
return 2
if (self.tree.get_object("res480x480").get_active()):
return 3
if (self.tree.get_object("res352x480").get_active()):
return 4
if (self.tree.get_object("res352x240").get_active()):
return 5
return 0
def adjust_resolution(self):
""" Sets the final resolution and bitrate based on the original resolution and the
desired one by the user """
if self.file_properties==None:
return
w1=self.tree.get_object("video_rate")
vrate=w1.get_value()
w2=self.tree.get_object("audio_rate")
arate=w2.get_value()
resx,resy,use_widescreen,vrate,arate=self.get_recomended_resolution(vrate, arate, self.get_desired_resolution())
self.file_properties["width"]=resx
self.file_properties["height"]=resy
w1.set_value(vrate)
w2.set_value(arate)
w=self.tree.get_object("aspect_ratio_4_3")
if ((resx<720) or (resy<480)) and (self.disctocreate!="divx"):
w.set_active(True)
if w.get_active():
self.file_properties["aspect"]=1.3333333
else:
self.file_properties["aspect"]=1.7777777
def get_widgets(self):
""" Fills the file_properties list with the values expressed in the widgets """
if len(self.file_properties["audio_list"])>0:
w=self.tree.get_object("audiotrack")
pos=w.get_active()
if (pos==-1):
pos=0
self.file_properties["audio_stream"]=self.file_properties["audio_list"][pos]
w=self.tree.get_object("force_subs")
self.file_properties["force_subs"]=w.get_active()
w=self.tree.get_object("blackbars")
if w.get_active():
self.file_properties["blackbars"]=0
else:
self.file_properties["blackbars"]=1
w=self.tree.get_object("trell")
self.file_properties["trellis"]=w.get_active()
w=self.tree.get_object("twopass")
self.file_properties["twopass"]=w.get_active()
w=self.tree.get_object("turbo1stpass")
self.file_properties["turbo1stpass"]=w.get_active()
self.file_properties["mbd"]=0
w=self.tree.get_object("mbd1")
if w.get_active():
self.file_properties["mbd"]=1
w=self.tree.get_object("mbd2")
if w.get_active():
self.file_properties["mbd"]=2
self.file_properties["deinterlace"]="none"
w=self.tree.get_object("deinterlace_lb")
if w.get_active():
self.file_properties["deinterlace"]="lb"
w=self.tree.get_object("deinterlace_md")
if w.get_active():
self.file_properties["deinterlace"]="md"
w=self.tree.get_object("deinterlace_fd")
if w.get_active():
self.file_properties["deinterlace"]="fd"
w=self.tree.get_object("deinterlace_l5")
if w.get_active():
self.file_properties["deinterlace"]="l5"
w=self.tree.get_object("deinterlace_yadif")
if w.get_active():
self.file_properties["deinterlace"]="yadif"
w=self.tree.get_object("ismpeg")
self.file_properties["ismpeg"]=w.get_active()
self.file_properties["swap_fields"]=self.tree.get_object("swap_fields").get_active()
w=self.tree.get_object("copy_audio")
self.file_properties["copy_audio"]=w.get_active()
w=self.tree.get_object("isvob")
self.file_properties["isvob"]=w.get_active()
w=self.tree.get_object("sound51")
self.file_properties["sound51"]=w.get_active()
w=self.tree.get_object("gop12")
self.file_properties["gop12"]=w.get_active()
w=self.tree.get_object("do_chapters")
if w.get_active():
w=self.tree.get_object("chapter_long")
self.file_properties["lchapters"]=w.get_value()
else:
self.file_properties["lchapters"]=0
w=self.tree.get_object("subfont_size")
self.file_properties["subfont_size"]=int(w.get_value())
w=self.tree.get_object("audiodelay")
self.file_properties["adelay"]=float(w.get_value())
w=self.tree.get_object("video_rate")
self.file_properties["vrate"]=int(w.get_value())
w=self.tree.get_object("audio_rate")
self.file_properties["arate"]=int(w.get_value())
w=self.tree.get_object("volume_adj")
self.file_properties["volume"]=int(w.get_value())
w=self.tree.get_object("full_length")
if w.get_active():
self.file_properties["cutting"]=0
else:
w=self.tree.get_object("first_half")
if w.get_active():
self.file_properties["cutting"]=1
else:
self.file_properties["cutting"]=2
w=self.tree.get_object("video_pal")
if w.get_active():
self.file_properties["fps"]=25
else:
self.file_properties["fps"]=30
if (self.disctocreate=="dvd") or (self.disctocreate=="divx"):
w=self.tree.get_object("aspect_ratio_16_9")
if w.get_active():
self.file_properties["aspect"]=1.77777777
else:
self.file_properties["aspect"]=1.33333333
else:
self.file_properties["aspect"]=1.33333333
self.file_properties["resolution"]=self.get_desired_resolution()
w=self.tree.get_object("custom_params")
self.file_properties["params"]=w.get_text()
w=self.tree.get_object("custom_params_vf")
self.file_properties["params_vf"]=w.get_text()
w=self.tree.get_object("custom_params_lavcopts")
self.file_properties["params_lavc"]=w.get_text()
if (self.disctocreate=="divx"):
w=self.tree.get_object("custom_params_lameopts")
self.file_properties["params_lame"]=w.get_text()
w=self.tree.get_object("rotation0")
if w.get_active():
self.file_properties["rotate"]=0 # no rotation
w=self.tree.get_object("rotation90")
if w.get_active():
self.file_properties["rotate"]=90 # rotate 90 degrees clockwise
w=self.tree.get_object("rotation180")
if w.get_active():
self.file_properties["rotate"]=180 # rotate 180 degrees
w=self.tree.get_object("rotation270")
if w.get_active():
self.file_properties["rotate"]=270 # rotate 90 degrees counter-clockwise
w=self.tree.get_object("hmirror")
self.file_properties["hmirror"]=w.get_active()
w=self.tree.get_object("vmirror")
self.file_properties["vmirror"]=w.get_active()
# Callbacks
def on_reset_volume_clicked(self,widget):
w=self.tree.get_object("volume_adj")
w.set_value(100)
def on_sub_add_clicked(self,widget):
window=ask_subtitle(self.gladefile,self.global_vars["filmpath"],self.global_vars)
ret=window.run()
window=None
if ret!=None:
self.file_properties["sub_list"].append(ret)
self.refresh_subtitles()
self.set_global_values()
def on_sub_remove_clicked(self,widget):
w=self.tree.get_object("sub_treeview")
try:
ctree,iter=w.get_selection().get_selected()
subtitle=ctree.get_value(iter,0)
except:
subtitle=-1
if subtitle==-1:
return
newtree=devede_other.create_tree(self,"wdel_subtitle",self.gladefile,False)
window=newtree.get_object("wdel_subtitle")
window.show()
ret=window.run()
window.hide()
window.destroy()
window=None
newtree=None
if ret==-5:
del (self.file_properties["sub_list"])[subtitle]
self.refresh_subtitles()
self.set_global_values()
def on_filecancel_clicked(self,widget):
w=self.tree.get_object("expander_advanced")
self.global_vars["expand_advanced"]=w.get_expanded()
self.window.destroy()
self.window=None
gc.collect()
def on_fileaccept_clicked(self,widget):
w=self.tree.get_object("expander_advanced")
self.global_vars["expand_advanced"]=w.get_expanded()
self.get_widgets()
if self.chapter==-1: # add this file as a new chapter
self.structure[self.title].append(self.file_properties)
else:
self.structure[self.title][self.chapter]=self.file_properties
self.window.destroy()
self.window=None
(self.callback_refresh)()
gc.collect()
def on_wfile_delete_event(self,widget,arg2):
self.window.destroy()
self.window=None
gc.collect()
return True
def on_wfile_destroy_event(self,widget,arg2):
self.window.destroy()
self.window=None
gc.collect()
def on_clear_subtitles_clicked(self,widget):
""" clears the subtitle filechooser """
w=self.tree.get_object("subtitles_chooser")
w.unselect_all()
def on_moviefile_file_set(self,widget):
w=self.tree.get_object("moviefile")
filename=widget.get_filename()
print "File changed to "+str(filename)
if (filename==None) or (filename==""):
self.set_widgets()
self.set_global_values()
self.set_film_buttons()
return
self.global_vars["filmpath"]=os.path.split(filename)[0]
if self.change_file:
self.set_widgets()
self.set_global_values()
self.set_film_buttons()
self.change_file=False
return
fine,tracks=self.create_default_video_parameters(filename)
if fine==False: # it's not a video file
if tracks==0: # it's not a multimedia file
devede_dialogs.show_error(self.gladefile,_("File doesn't seem to be a video file."))
else:
devede_dialogs.show_error(self.gladefile,_("File seems to be an audio file."))
w.unselect_all()
self.set_widgets()
self.set_global_values()
self.set_film_buttons()
def on_video_pal_toggled(self,widget):
""" Detects the change in the option PAL/NTSC """
w=self.tree.get_object("video_pal")
self.pal=w.get_active()
self.set_resolution()
self.adjust_resolution()
self.set_global_values()
def on_res_toggled(self,widget):
self.adjust_resolution()
self.set_global_values()
self.set_film_buttons()
def on_length_toggled(self,widget):
self.set_global_values()
def on_video_rate_value_changed(self,widget):
self.set_global_values()
def on_audio_rate_value_changed(self,widget):
self.set_global_values()
def on_subtitles_chooser_selection_changed(self,widget):
self.set_global_values()
def on_aspect_ratio_toggled(self,widget):
if self.file_properties==None:
return
w=self.tree.get_object("aspect_ratio_16_9")
if w.get_active()==False:
return
self.set_resolution()
if (self.file_properties["width"]<720) or (self.file_properties["height"]<480):
w=self.tree.get_object("res720x480")
w.set_active(True)
def on_ismpeg_toggled(self,widget):
self.set_film_buttons()
self.set_global_values()
def on_copy_audio_toggled(self,widget):
self.set_film_buttons()
self.set_global_values()
def on_isvob_toggled(self,widget):
self.set_film_buttons()
self.set_global_values()
def on_twopass_toggled(self,widget):
w = self.tree.get_object("turbo1stpass")
if widget.get_active():
w.set_sensitive(True)
else: