Debian Codegraph @

src/devedeng/file_movie.py

raw
1 # Copyright 2014 (C) Raster Software Vigo (Sergio Costas)
2 #
3 # This file is part of DeVeDe-NG
4 #
5 # DeVeDe-NG is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License version 3
7 # as published by the Free Software Foundation.
8 #
9 # DeVeDe-NG 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 from gi.repository import Gtk, GObject
18 import os
19
20 import devedeng.configuration_data
21 import devedeng.interface_manager
22 import devedeng.converter
23 import devedeng.ask_subtitles
24 import devedeng.preview
25 import devedeng.file_copy
26 import devedeng.subtitles_mux
27
28
29 class file_movie(devedeng.interface_manager.interface_manager):
30
31 __gsignals__ = {'title_changed': (GObject.SIGNAL_RUN_FIRST, None, (str,)), 'in_menu_changed': (
32 GObject.SIGNAL_RUN_FIRST, None, (bool,))}
33
34 def __init__(self, file_name, list_files=None):
35
36 self.element_type = "file_movie"
37 self.list_files = list_files
38
39 devedeng.interface_manager.interface_manager.__init__(self)
40
41 self.wfile_properties = None
42 self.builder = None
43
44 self.config = devedeng.configuration_data.configuration.get_config()
45 self.set_type(None, self.config.disc_type)
46 self.config.connect('disc_type', self.set_type)
47
48 if list_files is None:
49 self.add_text("file_name", file_name)
50 self.add_text("title_name", os.path.splitext(
51 os.path.basename(file_name))[0])
52 self.add_label("original_size", None)
53 self.add_label("original_length", None)
54 self.add_label("original_videorate", None)
55 self.add_label("original_audiorate", None)
56 self.add_label("original_aspect_ratio", None)
57 self.add_label("original_fps", None)
58 self.add_toggle("show_in_menu", True)
59 else:
60 self.original_aspect_ratio = 1.777 # dummy value
61
62 self.add_text("chapter_list_entry", None)
63
64 self.add_dualtoggle("format_pal", "format_ntsc", self.config.PAL)
65 self.add_toggle("video_rate_automatic", True)
66 self.add_toggle("audio_rate_automatic", True)
67 self.add_toggle("divide_in_chapters", True)
68 self.add_toggle("force_subtitles", False)
69 self.add_toggle("mirror_horizontal", False)
70 self.add_toggle("mirror_vertical", False)
71 self.add_toggle("two_pass_encoding", False)
72 self.add_toggle("sound5_1", False)
73 self.add_toggle("copy_sound", False)
74 self.add_toggle("is_mpeg_ps", False)
75 self.add_toggle("no_reencode_audio_video", False)
76 if (self.disc_type == "divx") or (self.disc_type == "mkv") or (self.config.disc_type == "hevc"):
77 self.add_toggle("gop12", False)
78 else:
79 self.add_toggle("gop12", True)
80
81 self.add_group("final_size_pal", ["size_auto", "size_1920x1080", "size_1280x720", "size_720x576",
82 "size_704x576", "size_480x576", "size_352x576", "size_352x288"], "size_auto")
83 self.add_group("final_size_ntsc", ["size_auto_ntsc", "size_1920x1080_ntsc", "size_1280x720_ntsc", "size_720x480_ntsc",
84 "size_704x480_ntsc", "size_480x480_ntsc", "size_352x480_ntsc", "size_352x240_ntsc"], "size_auto_ntsc")
85 self.add_group("aspect_ratio", [
86 "aspect_auto", "aspect_classic", "aspect_wide"], "aspect_auto")
87 self.add_group(
88 "scaling", ["add_black_bars", "scale_picture", "cut_picture"], "add_black_bars")
89 self.add_group("rotation", [
90 "rotation_0", "rotation_90", "rotation_180", "rotation_270"], "rotation_0")
91 self.add_group("deinterlace", [
92 "deinterlace_none", "deinterlace_ffmpeg", "deinterlace_yadif"], "deinterlace_none")
93 self.add_group("actions", ["action_stop", "action_play_first", "action_play_previous",
94 "action_play_again", "action_play_next", "action_play_last"], "action_stop")
95
96 self.prerotation = 0
97 self.add_integer_adjustment("volume", 100)
98 if (self.disc_type == "dvd"):
99 self.add_integer_adjustment("video_rate", 5000)
100 elif (self.disc_type == "vcd"):
101 self.add_integer_adjustment("video_rate", 1152)
102 else:
103 self.add_integer_adjustment("video_rate", 2000)
104
105 self.add_integer_adjustment("audio_rate", 224)
106 self.add_integer_adjustment("subt_font_size", 28)
107 self.add_float_adjustment("audio_delay", 0.0)
108 self.add_integer_adjustment("chapter_size", 5)
109
110 self.add_colorbutton("subt_fill_color", self.config.subt_fill_color)
111 self.add_colorbutton("subt_outline_color",
112 self.config.subt_outline_color)
113 self.add_float_adjustment(
114 "subt_thickness", self.config.subt_outline_thickness)
115
116 if list_files is None:
117 self.add_list("subtitles_list")
118 else:
119 self.add_list("files_to_set")
120 for e in list_files:
121 self.files_to_set.append([e.title_name, e])
122
123 self.add_show_hide("format_pal", ["size_pal"], ["size_ntsc"])
124
125 self.add_enable_disable("divide_in_chapters", [
126 "chapter_size_spinbutton", "chapter_list_entry"], [])
127 self.add_enable_disable("video_rate_automatic",
128 [], ["video_spinbutton"])
129 self.add_enable_disable("audio_rate_automatic",
130 [], ["audio_spinbutton"])
131 self.add_enable_disable("sound5_1", ["copy_sound"], [])
132
133 if (self.disc_type == "dvd"):
134 self.add_enable_disable("aspect_wide", [], ["size_704x576", "size_480x576", "size_352x576", "size_352x288",
135 "size_704x480_ntsc", "size_480x480_ntsc", "size_352x480_ntsc", "size_352x240_ntsc"])
136
137 self.add_enable_disable("copy_sound", [], ["audio_delay_spinbutton", "audio_rate_automatic",
138 "audio_spinbutton", "spinbutton_volume", "scale_volume", "reset_volume"])
139
140 common_elements = ["gop12", "video_rate_automatic", "video_spinbutton", "audio_rate_automatic", "audio_spinbutton", "format_pal", "format_ntsc", "spinbutton_volume", "scale_volume", "reset_volume",
141 "size_auto", "size_1920x1080", "size_1280x720", "size_720x576", "size_704x576", "size_480x576", "size_352x576", "size_352x288",
142 "size_auto_ntsc", "size_1920x1080_ntsc", "size_1280x720_ntsc", "size_720x480_ntsc", "size_704x480_ntsc", "size_480x480_ntsc", "size_352x480_ntsc", "size_352x240_ntsc",
143 "aspect_auto", "aspect_classic", "aspect_wide", "mirror_horizontal", "mirror_vertical", "add_black_bars", "scale_picture", "cut_picture",
144 "rotation_0", "rotation_90", "rotation_180", "rotation_270", "two_pass_encoding", "deinterlace_none", "deinterlace_ffmpeg", "deinterlace_yadif",
145 "audio_delay_spinbutton", "sound5_1", "copy_sound"]
146
147 is_mpeg_ps_list = common_elements[:]
148 is_mpeg_ps_list.append("no_reencode_audio_video")
149 is_mpeg_ps_list.append("font_size_spinbutton")
150 is_mpeg_ps_list.append("force_subtitles")
151 is_mpeg_ps_list.append("add_subtitles")
152 is_mpeg_ps_list.append("del_subtitles")
153 no_reencode_audio_video_list = common_elements[:]
154 no_reencode_audio_video_list.append("is_mpeg_ps")
155
156 self.add_enable_disable("is_mpeg_ps", [], is_mpeg_ps_list)
157 self.add_enable_disable("no_reencode_audio_video",
158 [], no_reencode_audio_video_list)
159
160 if list_files is None:
161 cv = devedeng.converter.converter.get_converter()
162 film_analizer = (cv.get_film_analizer())()
163 if (film_analizer.get_film_data(self.file_name)):
164 self.error = True
165 else:
166 self.error = False
167 self.audio_list = film_analizer.audio_list[:]
168 self.video_list = film_analizer.video_list[:]
169 self.audio_streams = film_analizer.audio_streams
170 self.video_streams = film_analizer.video_streams
171 self.original_width = film_analizer.original_width
172 self.original_height = film_analizer.original_height
173 self.original_length = film_analizer.original_length
174 self.original_size = film_analizer.original_size
175 self.original_aspect_ratio = film_analizer.original_aspect_ratio
176 self.original_videorate = film_analizer.original_videorate
177 self.original_audiorate = film_analizer.original_audiorate
178 self.prerotation = film_analizer.prerotation
179
180 self.original_audiorate_uncompressed = film_analizer.original_audiorate_uncompressed
181 self.original_fps = film_analizer.original_fps
182 self.original_file_size = film_analizer.original_file_size
183
184 if self.original_audiorate <= 0:
185 # just a guess, but usually correct
186 self.original_audiorate = 224
187 if self.original_videorate <= 0:
188 # presume that there are only video and audio streams
189 self.original_videorate = ((8 * self.original_file_size) / self.original_length) - (
190 self.original_audiorate * self.audio_streams)
191 # to avoid division by zero when a clip is very short
192 if self.original_length <= 0:
193 self.original_length = 1
194
195 self.width_midle = -1
196 self.height_midle = -1
197 self.width_final = -1
198 self.height_final = -1
199 self.video_rate_auto = self.video_rate
200 self.audio_rate_auto = self.audio_rate
201 self.video_rate_final = self.video_rate
202 self.audio_rate_final = self.audio_rate
203 self.aspect_ratio_final = None
204 self.converted_filename = None
205
206 def set_name(self, new_title):
207 self.title_name = new_title
208 self.emit('title_changed', self.title_name)
209
210 def set_show_in_menu(self, show):
211 self.show_in_menu = show
212 self.emit('in_menu_changed', self.show_in_menu)
213
214 def get_duration(self):
215 return self.original_length
216
217 def get_estimated_size(self):
218 """ Returns the estimated final file size, in kBytes, based on the final audio and video rate, and the subtitles """
219
220 self.set_final_rates()
221 self.set_final_size_aspect()
222
223 if self.is_mpeg_ps:
224 estimated_size = self.original_file_size / 1000
225 else:
226 # let's asume 8kbps for each subtitle
227 sub_rate = 8 * len(self.subtitles_list)
228 estimated_size = ((self.video_rate_final + (self.audio_rate_final *
229 self.audio_streams) + sub_rate) * self.original_length) / 8
230
231 return estimated_size
232
233 def get_size_data(self):
234
235 estimated_size = self.get_estimated_size()
236 if self.is_mpeg_ps or self.no_reencode_audio_video:
237 videorate_fixed_size = True
238 else:
239 videorate_fixed_size = False
240
241 # let's asume 8kbps for each subtitle
242 sub_rate = 8 * len(self.subtitles_list)
243
244 return estimated_size, videorate_fixed_size, self.audio_rate_final * self.audio_streams, sub_rate, self.width_final, self.height_final, self.original_length
245
246 def set_auto_video_audio_rate(self, new_video_rate, new_audio_rate):
247
248 self.video_rate_auto = int(new_video_rate)
249 self.audio_rate_auto = int(new_audio_rate)
250
251 def get_max_resolution(self, rx, ry, aspect):
252
253 if aspect == 0:
254 aspect = 1
255 tmpx = ry * aspect
256 tmpy = rx / aspect
257 if (tmpx > rx):
258 return tmpx, ry
259 else:
260 return rx, tmpy
261
262 def set_final_rates(self):
263
264 if (self.disc_type == "divx") or (self.disc_type == "mkv") or (self.config.disc_type == "hevc"):
265 self.audio_rate_auto = 192
266 elif (self.disc_type == "vcd") or (self.disc_type == "svcd") or (self.disc_type == "cvd"):
267 self.audio_rate_auto = 224
268 else: # dvd
269 if self.sound5_1:
270 self.audio_rate_auto = 384
271 else:
272 self.audio_rate_auto = 224
273
274 if self.is_mpeg_ps or self.no_reencode_audio_video:
275 self.video_rate_final = self.original_videorate
276 self.audio_rate_final = self.original_audiorate
277 else:
278 if self.video_rate_automatic:
279 self.video_rate_final = self.video_rate_auto
280 else:
281 self.video_rate_final = self.video_rate
282
283 if self.copy_sound:
284 self.audio_rate_final = self.original_audiorate
285 else:
286 if self.audio_rate_automatic:
287 self.audio_rate_final = self.audio_rate_auto
288 else:
289 self.audio_rate_final = self.audio_rate
290
291 def set_final_size_aspect(self):
292
293 if self.is_mpeg_ps:
294 self.width_midle = self.original_width
295 self.width_final = self.original_width
296 self.height_midle = self.original_height
297 self.height_final = self.original_height
298 self.aspect_ratio_final = self.original_aspect_ratio
299 return
300
301 if self.format_pal:
302 final_size = self.final_size_pal
303 else:
304 # remove the "_ntsc" from the string
305 final_size = self.final_size_ntsc[:-5]
306
307 # for divx or matroska, if the size and the aspect ratio is automatic,
308 # just don't change them
309 if ((self.disc_type == "divx") or (self.disc_type == "mkv") or (self.config.disc_type == "hevc")) and (final_size == "size_auto") and (self.aspect_ratio == "aspect_auto"):
310 self.width_midle = self.original_width
311 self.width_final = self.original_width
312 self.height_midle = self.original_height
313 self.height_final = self.original_height
314 self.aspect_ratio_final = self.original_aspect_ratio
315 return
316
317 # The steps are:
318 # - Decide the final aspect ratio
319 # - Calculate the midle size: the original video will be cut to this size, or black bars will be added
320 # - Calculate the final size: the midle video will be scaled to this size
321
322 aspect_wide = False
323 # first, decide the final aspect ratio
324 if (self.disc_type == "vcd") or (self.disc_type == "svcd") or (self.disc_type == "cvd"):
325 self.aspect_ratio_final = 4.0 / 3.0
326 else:
327 if (self.aspect_ratio == "aspect_auto"):
328 if (self.disc_type != "dvd"):
329 self.aspect_ratio_final = self.original_aspect_ratio
330 else:
331 if self.original_aspect_ratio >= 1.7:
332 self.aspect_ratio_final = 16.0 / 9.0
333 aspect_wide = True
334 else:
335 self.aspect_ratio_final = 4.0 / 3.0
336 elif (self.aspect_ratio == "aspect_classic"):
337 self.aspect_ratio_final = 4.0 / 3.0
338 else:
339 self.aspect_ratio_final = 16.0 / 9.0
340 aspect_wide = True
341
342 # now, the final resolution
343 if self.disc_type == "vcd":
344 self.width_final = 352
345 if (self.format_pal):
346 self.height_final = 288
347 else:
348 self.height_final = 240
349 else:
350 if final_size == "size_auto":
351 if self.disc_type == "svcd":
352 self.width_final = 480
353 if (self.format_pal):
354 self.height_final = 576
355 else:
356 self.height_final = 480
357 elif self.disc_type == "cvd":
358 self.width_final = 352
359 if (self.format_pal):
360 self.height_final = 576
361 else:
362 self.height_final = 480
363 elif self.disc_type == "dvd":
364 if aspect_wide:
365 self.width_final = 720
366 if (self.format_pal):
367 self.height_final = 576
368 else:
369 self.height_final = 480
370 else:
371 tx, ty = self.get_max_resolution(self.original_width, self.original_height, self.original_aspect_ratio)
372 if (self.format_pal):
373 th = 576
374 th2 = 288
375 else:
376 th = 480
377 th2 = 240
378 if (tx <= 352) and (ty <= th2):
379 self.width_final = 352
380 self.height_final = th2
381 elif (tx <= 352) and (ty <= th):
382 self.width_final = 352
383 self.height_final = th
384 elif (tx <= 704) and (ty <= th):
385 self.width_final = 704
386 self.height_final = th
387 else:
388 self.width_final = 720
389 self.height_final = th
390 else:
391 self.width_final, self.height_final = self.get_max_resolution(self.original_width, self.original_height, self.original_aspect_ratio)
392 else:
393 values = final_size[5:].split("x")
394 self.width_final = int(values[0])
395 self.height_final = int(values[1])
396
397 self.width_final = int(self.width_final)
398 self.height_final = int(self.height_final)
399
400 # finally, calculate the midle size
401
402 if (self.rotation == "rotation_90") or (self.rotation == "rotation_270"):
403 midle_aspect_ratio = 1.0 / self.original_aspect_ratio
404 original_width = self.original_height
405 original_height = self.original_width
406 else:
407 original_width = self.original_width
408 original_height = self.original_height
409 midle_aspect_ratio = self.original_aspect_ratio
410
411 if midle_aspect_ratio == 0:
412 midle_aspect_ratio = 1
413
414 if self.scaling == "scale_picture":
415 self.width_midle = int(original_width)
416 self.height_midle = int(original_height)
417 elif self.scaling == "add_black_bars":
418 print(f"Original width {original_width}x{original_height}; ratio original: {midle_aspect_ratio}; ratio nuevo: {self.aspect_ratio_final}")
419 if midle_aspect_ratio > self.aspect_ratio_final: # add horizontal black bars, at top and bottom
420 self.width_midle = int(original_width)
421 self.height_midle = int(original_height * midle_aspect_ratio / self.aspect_ratio_final)
422 else: # add vertical black bars, at left and right
423 self.width_midle = int(original_width * self.aspect_ratio_final / midle_aspect_ratio)
424 self.height_midle = int(original_height)
425 else: # cut picture
426 if midle_aspect_ratio > self.aspect_ratio_final:
427 self.width_midle = int(original_width * self.aspect_ratio_final / midle_aspect_ratio)
428 self.height_midle = int(original_height)
429 else:
430 self.width_midle = int(original_width)
431 self.height_midle = int(original_height * midle_aspect_ratio / self.aspect_ratio_final)
432
433 def set_type(self, obj=None, disc_type=None):
434 if (disc_type is not None):
435 self.disc_type = disc_type
436
437 def delete_element(self):
438 return
439
440 def on_help_clicked(self, b):
441 help_file = devedeng.help.help("file.html")
442
443 def properties(self):
444 if (self.wfile_properties is not None):
445 self.wfile_properties.present()
446 return
447
448 self.builder = Gtk.Builder()
449 self.builder.set_translation_domain(self.config.gettext_domain)
450
451 self.builder.add_from_file(os.path.join(
452 self.config.glade, "wfile_properties.ui"))
453 self.builder.connect_signals(self)
454 self.wfile_properties = self.builder.get_object("file_properties")
455 self.wfile_properties.show_all()
456
457 self.wframe_title = self.builder.get_object("frame_title")
458 self.wframe_fileinfo = self.builder.get_object("frame_fileinfo")
459 self.wframe_multiproperties = self.builder.get_object(
460 "frame_multiproperties")
461 self.wtreeview_multiproperties = self.builder.get_object(
462 "treeview_multiproperties")
463 self.wbutton_preview = self.builder.get_object("button_preview")
464
465 self.wshow_in_menu = self.builder.get_object("show_in_menu")
466
467 self.wnotebook = self.builder.get_object("notebook")
468
469 # elements in page GENERAL
470 self.wformat_pal = self.builder.get_object("format_pal")
471 self.wformat_ntsc = self.builder.get_object("format_ntsc")
472 self.wframe_video_rate = self.builder.get_object("frame_video_rate")
473 self.wframe_audio_rate = self.builder.get_object("frame_audio_rate")
474 self.waudio_rate = self.builder.get_object("audio_rate")
475 self.wframe_division_chapters = self.builder.get_object(
476 "frame_division_chapters")
477
478 if (self.disc_type == "dvd") or (self.disc_type == "divx") or (self.disc_type == "mkv") or (self.config.disc_type == "hevc"):
479 self.waudio_rate.set_upper(448.0)
480 else:
481 self.waudio_rate.set_upper(384.0)
482
483 # elements in page SUBTITLES
484 self.wsubtitles_list = self.builder.get_object("subtitles_list")
485 self.wtreview_subtitles = self.builder.get_object("treeview_subtitles")
486 self.wscrolledwindow_subtitles = self.builder.get_object(
487 "scrolledwindow_subtitles")
488 self.wadd_subtitles = self.builder.get_object("add_subtitles")
489 self.wdel_subtitles = self.builder.get_object("del_subtitles")
490
491 selection = self.wtreview_subtitles.get_selection()
492 selection.set_mode(Gtk.SelectionMode.BROWSE)
493
494 # elements in page VIDEO OPTIONS
495 self.wsize_1920x1080 = self.builder.get_object("size_1920x1080")
496 self.wsize_1280x720 = self.builder.get_object("size_1280x720")
497 self.wsize_1920x1080_ntsc = self.builder.get_object(
498 "size_1920x1080_ntsc")
499 self.wsize_1280x720_ntsc = self.builder.get_object(
500 "size_1280x720_ntsc")
501 self.wframe_final_size = self.builder.get_object("frame_final_size")
502 self.wframe_aspect_ratio = self.builder.get_object(
503 "frame_aspect_ratio")
504 self.waspect_classic = self.builder.get_object("aspect_classic")
505 self.waspect_wide = self.builder.get_object("aspect_wide")
506 self.wadd_black_bars_pic = self.builder.get_object(
507 "add_black_bars_pic")
508 self.wscale_picture_pic = self.builder.get_object("scale_picture_pic")
509 self.wcut_picture_pic = self.builder.get_object("cut_picture_pic")
510
511 # elements in page AUDIO
512 self.wsound5_1 = self.builder.get_object("sound5_1")
513 self.wcopy_sound = self.builder.get_object("copy_sound")
514
515 # Adjust the interface UI to the kind of disc
516
517 if (self.disc_type == 'dvd'):
518 self.wsize_1920x1080.hide()
519 self.wsize_1280x720.hide()
520 self.wsize_1920x1080_ntsc.hide()
521 self.wsize_1280x720_ntsc.hide()
522 elif (self.disc_type == 'vcd'):
523 self.wshow_in_menu.hide()
524 self.wframe_video_rate.hide()
525 self.wframe_audio_rate.hide()
526 self.wframe_division_chapters.hide()
527 self.wframe_final_size.hide()
528 self.wframe_aspect_ratio.hide()
529 self.wsound5_1.hide()
530 self.wcopy_sound.hide()
531 self.wnotebook.remove_page(5)
532 elif (self.disc_type == 'svcd'):
533 self.wsize_1920x1080.hide()
534 self.wsize_1280x720.hide()
535 self.wsize_1920x1080_ntsc.hide()
536 self.wsize_1280x720_ntsc.hide()
537 self.wshow_in_menu.hide()
538 self.wframe_division_chapters.hide()
539 self.wframe_aspect_ratio.hide()
540 self.wsound5_1.hide()
541 self.wcopy_sound.hide()
542 self.wnotebook.remove_page(5)
543 elif (self.disc_type == 'cvd'):
544 self.wsize_1920x1080.hide()
545 self.wsize_1280x720.hide()
546 self.wsize_1920x1080_ntsc.hide()
547 self.wsize_1280x720_ntsc.hide()
548 self.wshow_in_menu.hide()
549 self.wframe_division_chapters.hide()
550 self.wframe_aspect_ratio.hide()
551 self.wsound5_1.hide()
552 self.wcopy_sound.hide()
553 self.wnotebook.remove_page(5)
554 elif (self.disc_type == 'divx'):
555 self.wshow_in_menu.hide()
556 self.wframe_division_chapters.hide()
557 self.wsound5_1.hide()
558 self.wcopy_sound.hide()
559 self.wnotebook.remove_page(5)
560 self.wnotebook.remove_page(1)
561 elif (self.disc_type == 'mkv') or (self.config.disc_type == "hevc"):
562 self.wshow_in_menu.hide()
563 self.wframe_division_chapters.hide()
564 self.wnotebook.remove_page(5)
565
566 if self.list_files is None:
567 self.wframe_title.show()
568 self.wframe_fileinfo.show()
569 self.wframe_multiproperties.hide()
570 else:
571 self.wframe_title.hide()
572 self.wframe_fileinfo.hide()
573 self.wframe_multiproperties.show()
574 self.wscrolledwindow_subtitles.hide()
575 self.wbutton_preview.hide()
576 self.wadd_subtitles.hide()
577 self.wdel_subtitles.hide()
578 sel = self.wtreeview_multiproperties.get_selection()
579 sel.set_mode(Gtk.SelectionMode.MULTIPLE)
580 self.wtreeview_multiproperties.set_rubber_banding(True)
581
582 self.save_ui()
583 self.update_ui(self.builder)
584 self.on_aspect_classic_toggled(None)
585 self.on_treeview_subtitles_cursor_changed(None)
586
587 def on_aspect_classic_toggled(self, b):
588
589 status1 = self.waspect_classic.get_active()
590 status2 = self.waspect_wide.get_active()
591 if (status1):
592 final_aspect = 4.0 / 3.0
593 elif (status2):
594 final_aspect = 16.0 / 9.0
595 else:
596 if self.original_aspect_ratio >= 1.7:
597 final_aspect = 16.0 / 9.0
598 else:
599 final_aspect = 4.0 / 3.0
600 if (final_aspect < self.original_aspect_ratio):
601 self.wadd_black_bars_pic.set_from_file(os.path.join(
602 self.config.pic_path, "to_classic_blackbars.png"))
603 self.wcut_picture_pic.set_from_file(os.path.join(
604 self.config.pic_path, "to_classic_cut.png"))
605 self.wscale_picture_pic.set_from_file(os.path.join(
606 self.config.pic_path, "to_classic_scale.png"))
607 else:
608 self.wadd_black_bars_pic.set_from_file(os.path.join(
609 self.config.pic_path, "to_wide_blackbars.png"))
610 self.wcut_picture_pic.set_from_file(
611 os.path.join(self.config.pic_path, "to_wide_cut.png"))
612 self.wscale_picture_pic.set_from_file(
613 os.path.join(self.config.pic_path, "to_wide_scale.png"))
614
615 def on_button_accept_clicked(self, b):
616
617 self.store_ui(self.builder)
618 self.config.subt_fill_color = self.subt_fill_color
619 self.config.subt_outline_color = self.subt_outline_color
620 self.config.subt_outline_thickness = self.subt_thickness
621 if self.list_files is None:
622 # editing file properties
623 self.set_final_rates()
624 self.set_final_size_aspect()
625 self.emit('title_changed', self.title_name)
626 self.emit('in_menu_changed', self.show_in_menu)
627 else:
628 # editing properties for a group of files
629 data = self.store_element()
630 sel = self.wtreeview_multiproperties.get_selection()
631 model, pathlist = sel.get_selected_rows()
632 for file_path in pathlist:
633 obj = model[file_path][1]
634 obj.restore_element(data)
635
636 self.wfile_properties.destroy()
637 self.wfile_properties = None
638 self.builder = None
639
640 def on_button_cancel_clicked(self, b):
641
642 if self.list_files is None:
643 self.restore_ui()
644
645 self.wfile_properties.destroy()
646 self.wfile_properties = None
647 self.builder = None
648
649 def on_add_subtitles_clicked(self, b):
650
651 subt = devedeng.ask_subtitles.ask_subtitles()
652 if (subt.run()):
653 self.wsubtitles_list.append(
654 [subt.filename, subt.encoding, subt.language, subt.put_upper])
655
656 def get_selected_subtitle(self):
657
658 selection = self.wtreview_subtitles.get_selection()
659 model, treeiter = selection.get_selected()
660
661 if treeiter is not None:
662 return ((model, treeiter))
663 else:
664 return ((None, None))
665
666 def on_del_subtitles_clicked(self, b):
667
668 model, treeiter = self.get_selected_subtitle()
669 if (model is not None):
670 model.remove(treeiter)
671
672 def on_treeview_subtitles_cursor_changed(self, b):
673
674 model, treeiter = self.get_selected_subtitle()
675 if (model is None):
676 self.wdel_subtitles.set_sensitive(False)
677 else:
678 self.wdel_subtitles.set_sensitive(True)
679
680 def do_conversion(self, output_path, duration=0):
681
682 self.converted_filename = output_path
683 if self.is_mpeg_ps:
684 converter = devedeng.file_copy.file_copy(
685 self.file_name, output_path)
686 else:
687 self.set_final_size_aspect()
688 self.set_final_rates()
689
690 cv = devedeng.converter.converter.get_converter()
691 disc_converter = cv.get_disc_converter()
692 converter = disc_converter()
693 converter.convert_file(self, output_path, duration)
694
695 if len(self.subtitles_list) != 0:
696 last_process = converter
697 # if duration == 0:
698 # it seems that SPUMUX always fills the entire subtitles
699 duration2 = self.original_length
700 # else:
701 # duration2 = duration
702 stream_id = 0
703 for subt in self.subtitles_list:
704 subt_file = subt[0]
705 subt_codepage = subt[1]
706 subt_lang = subt[2]
707 subt_upper = subt[3]
708 if self.aspect_ratio_final >= 1.7:
709 final_aspect = "16:9"
710 else:
711 final_aspect = "4:3"
712 subt_mux = devedeng.subtitles_mux.subtitles_mux()
713 subt_mux.multiplex_subtitles(output_path, subt_file, subt_codepage, subt_lang, subt_upper,
714 self.subt_font_size, self.format_pal, self.force_subtitles,
715 final_aspect, duration2, stream_id,
716 self.subt_fill_color, self.subt_outline_color, self.subt_thickness)
717 subt_mux.add_dependency(last_process)
718 converter.add_child_process(subt_mux)
719 last_process = subt_mux
720 stream_id += 1
721
722 return converter
723
724 def on_button_preview_clicked(self, b):
725 self.store_ui(self.builder)
726 self.do_preview()
727
728 def do_preview(self):
729
730 wpreview = devedeng.preview.preview_window()
731 if (wpreview.run() == False):
732 return
733
734 run_window = devedeng.runner.runner()
735 p = self.do_conversion(os.path.join(
736 self.config.tmp_folder, "movie_preview.mpg"), wpreview.lvalue)
737 run_window.add_process(p)
738 run_window.connect("done", self.preview_done)
739 run_window.run()
740
741 def preview_done(self, o, retval):
742
743 if (retval == 0):
744 cv = devedeng.converter.converter.get_converter()
745 disc_player = (cv.get_film_player())()
746 disc_player.play_film(os.path.join(
747 self.config.tmp_folder, "movie_preview.mpg"))
748
749 def store_element(self):
750 data = self.serialize()
751 if "files_to_set" in data:
752 del data["files_to_set"]
753 data["element_type"] = "file_movie"
754 return data
755
756 def restore_element(self, data):
757 self.unserialize(data)
758
759 def on_select_all_clicked(self, b):
760 sel = self.wtreeview_multiproperties.get_selection()
761 sel.select_all()
762
763 def on_unselect_all_clicked(self, b):
764 sel = self.wtreeview_multiproperties.get_selection()
765 sel.unselect_all()