diff --git a/setup.py b/setup.py index 82fa15c..8dd20d8 100755 --- a/setup.py +++ b/setup.py @@ -9,6 +9,7 @@ try: except: pass + def get_data_files(): data_files = [ (os.path.join('share', 'applications'), ['data/devedeng.desktop']), @@ -18,15 +19,20 @@ def get_data_files(): (os.path.join('share', 'devedeng'), ['data/devedeng.svg']), (os.path.join('share', 'devedeng'), ['data/codepages.lst']), (os.path.join('share', 'devedeng'), ['data/languages.lst']), - (os.path.join('share', 'devedeng', 'backgrounds'), glob('data/pixmaps/backgrounds/*')), + (os.path.join('share', 'devedeng', 'backgrounds'), + glob('data/pixmaps/backgrounds/*')), (os.path.join('share', 'doc', 'devedeng', 'html'), glob('doc/*')), - (os.path.join('share','man','man1'), ['data/devede.1.gz']) + (os.path.join('share', 'man', 'man1'), ['data/devede.1.gz']) ] for lang_name in [f for f in os.listdir('locale')]: - mofile = os.path.join('locale', lang_name,'LC_MESSAGES','devedeng.mo') - # translations must be always in /usr/share because Gtk.builder only search there. If someone knows how to fix this... - target = os.path.join('/usr','share', 'locale', lang_name, 'LC_MESSAGES') # share/locale/fr/LC_MESSAGES/ + mofile = os.path.join('locale', lang_name, + 'LC_MESSAGES', 'devedeng.mo') + # translations must be always in /usr/share because Gtk.builder only + # search there. If someone knows how to fix this... + # share/locale/fr/LC_MESSAGES/ + target = os.path.join('/usr', 'share', 'locale', + lang_name, 'LC_MESSAGES') data_files.append((target, [mofile])) return data_files @@ -38,9 +44,11 @@ def compile_translations(): for pofile in [f for f in os.listdir('po') if f.endswith('.po')]: pofile = os.path.join('po', pofile) - lang = os.path.basename(pofile)[:-3] # len('.po') == 3 - modir = os.path.join('locale', lang, 'LC_MESSAGES') # e.g. locale/fr/LC_MESSAGES/ - mofile = os.path.join(modir, 'devedeng.mo') # e.g. locale/fr/LC_MESSAGES/devedeng.mo + lang = os.path.basename(pofile)[:-3] # len('.po') == 3 + # e.g. locale/fr/LC_MESSAGES/ + modir = os.path.join('locale', lang, 'LC_MESSAGES') + # e.g. locale/fr/LC_MESSAGES/devedeng.mo + mofile = os.path.join(modir, 'devedeng.mo') # create an architecture for these locales if not os.path.isdir(modir): @@ -67,7 +75,7 @@ setup( version='4.8.6', description='A video DVD creator', - long_description = "A program that allows to create video DVDs", + long_description="A program that allows to create video DVDs", url='http://www.rastersoft.com', @@ -98,7 +106,7 @@ setup( packages=['devedeng'], - package_dir={"devedeng" : "src/devedeng"}, + package_dir={"devedeng": "src/devedeng"}, #package_data={'devede': ['data/*.ui']}, @@ -107,6 +115,6 @@ setup( # see http://docs.python.org/3.4/distutils/setupscript.html#installing-additional-files # In this case, 'data_file' will be installed into '/my_data' #data_files=[('share/devedeng/ui', ['ui/test.ui'])], - data_files = get_data_files(), + data_files=get_data_files(), scripts=['src/devede_ng.py', 'src/copy_files_verbose.py'], ) diff --git a/src/copy_files_verbose.py b/src/copy_files_verbose.py index af03b60..6fa8151 100644 --- a/src/copy_files_verbose.py +++ b/src/copy_files_verbose.py @@ -26,11 +26,11 @@ if len(sys.argv) != 3: filesize = os.path.getsize(sys.argv[1]) done = 0.0 -f1 = open(sys.argv[1],"rb") -f2 = open(sys.argv[2],"wb") +f1 = open(sys.argv[1], "rb") +f2 = open(sys.argv[2], "wb") while (done < filesize): data = f1.read(65536) f2.write(data) done += len(data) - print("Copied %.1f%%" % (100.0 * float(done)/float(filesize))) + print("Copied %.1f%%" % (100.0 * float(done) / float(filesize))) diff --git a/src/devede_ng.py b/src/devede_ng.py index 6ed7bd5..5162241 100755 --- a/src/devede_ng.py +++ b/src/devede_ng.py @@ -31,16 +31,16 @@ import devedeng.choose_disc_type config_data = devedeng.configuration_data.configuration.get_config() if config_data is None: - print ("Can't locate extra files. Aborting.") + print("Can't locate extra files. Aborting.") sys.exit(1) -gettext.bindtextdomain(config_data.gettext_domain,config_data.share_locale) +gettext.bindtextdomain(config_data.gettext_domain, config_data.share_locale) try: - locale.setlocale(locale.LC_ALL,"") + locale.setlocale(locale.LC_ALL, "") except locale.Error: pass gettext.textdomain(config_data.gettext_domain) -gettext.install(config_data.gettext_domain,localedir=config_data.share_locale) +gettext.install(config_data.gettext_domain, localedir=config_data.share_locale) _ = gettext.gettext diff --git a/src/devedeng/__init__.py b/src/devedeng/__init__.py index 3ad5e84..cd8904b 100644 --- a/src/devedeng/__init__.py +++ b/src/devedeng/__init__.py @@ -16,4 +16,3 @@ # # You should have received a copy of the GNU General Public License # along with this program. If not, see . - diff --git a/src/devedeng/about.py b/src/devedeng/about.py index f7a6cef..39905f9 100644 --- a/src/devedeng/about.py +++ b/src/devedeng/about.py @@ -19,6 +19,7 @@ from gi.repository import Gtk import os import devedeng.configuration_data + class about_window: def __init__(self): @@ -28,7 +29,7 @@ class about_window: builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wabout.ui")) + builder.add_from_file(os.path.join(self.config.glade, "wabout.ui")) builder.connect_signals(self) w_window = builder.get_object("about_devedeng") w_window.set_version(self.config.version) diff --git a/src/devedeng/add_files.py b/src/devedeng/add_files.py index fa7c410..12b712e 100644 --- a/src/devedeng/add_files.py +++ b/src/devedeng/add_files.py @@ -19,6 +19,7 @@ from gi.repository import Gtk import os import devedeng.configuration_data + class add_files: last_path = None @@ -32,7 +33,7 @@ class add_files: builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wadd_files.ui")) + builder.add_from_file(os.path.join(self.config.glade, "wadd_files.ui")) builder.connect_signals(self) wadd_files = builder.get_object("add_files") self.wfile_chooser = builder.get_object("filechooserwidget1") @@ -40,12 +41,12 @@ class add_files: self.wfile_chooser.set_current_folder(add_files.last_path) self.wbutton_accept = builder.get_object("button_accept") - file_filter_videos=Gtk.FileFilter() + file_filter_videos = Gtk.FileFilter() file_filter_videos.set_name(_("Video files")) file_filter_videos.add_mime_type("video/*") file_filter_videos.add_pattern("*.rmvb") - file_filter_all=Gtk.FileFilter() + file_filter_all = Gtk.FileFilter() file_filter_all.set_name(_("All files")) file_filter_all.add_pattern("*") @@ -77,7 +78,7 @@ class add_files: files_out.append(element) return files_out - def on_filechooserwidget1_selection_changed(self,b): + def on_filechooserwidget1_selection_changed(self, b): files = self.get_files() if (len(files) == 0): diff --git a/src/devedeng/ask.py b/src/devedeng/ask.py index aa198b3..5645d8c 100644 --- a/src/devedeng/ask.py +++ b/src/devedeng/ask.py @@ -19,18 +19,19 @@ from gi.repository import Gtk import os import devedeng.configuration_data + class ask_window: def __init__(self): self.config = devedeng.configuration_data.configuration.get_config() - def run(self,text,title): + def run(self, text, title): builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wask.ui")) + builder.add_from_file(os.path.join(self.config.glade, "wask.ui")) builder.connect_signals(self) wask_window = builder.get_object("dialog_ask") wask_window.set_title(title) @@ -43,4 +44,4 @@ class ask_window: if (retval == 1): return True else: - return False \ No newline at end of file + return False diff --git a/src/devedeng/ask_subtitles.py b/src/devedeng/ask_subtitles.py index b401158..e357125 100644 --- a/src/devedeng/ask_subtitles.py +++ b/src/devedeng/ask_subtitles.py @@ -20,6 +20,7 @@ import os import devedeng.configuration_data import devedeng.add_files + class ask_subtitles: def __init__(self): @@ -31,7 +32,8 @@ class ask_subtitles: builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wask_subtitles.ui")) + builder.add_from_file(os.path.join( + self.config.glade, "wask_subtitles.ui")) builder.connect_signals(self) wask_window = builder.get_object("ask_subtitles") self.wfilename = builder.get_object("subtitle_file") @@ -42,7 +44,8 @@ class ask_subtitles: wlanguage = builder.get_object("language_l") if (devedeng.add_files.add_files.last_path is not None): - self.wfilename.set_current_folder(devedeng.add_files.add_files.last_path) + self.wfilename.set_current_folder( + devedeng.add_files.add_files.last_path) lang_selection = 0 enc_selection = 0 @@ -51,9 +54,9 @@ class ask_subtitles: self.encoding = None self.put_upper = False self.filename = None - + counter = 0 - encodings = open(os.path.join(self.config.other_path,"codepages.lst")) + encodings = open(os.path.join(self.config.other_path, "codepages.lst")) for element in encodings: element = element.strip() if (element == self.config.sub_codepage): @@ -61,9 +64,9 @@ class ask_subtitles: wlist_encodings.append([element]) counter += 1 encodings.close() - + counter = 0 - languages = open(os.path.join(self.config.other_path,"languages.lst")) + languages = open(os.path.join(self.config.other_path, "languages.lst")) for element in languages: element = element.strip() if (element == self.config.sub_language): @@ -71,11 +74,11 @@ class ask_subtitles: wlist_languages.append([element]) counter += 1 languages.close() - + wencoding.set_active(enc_selection) wlanguage.set_active(lang_selection) - file_filter_subt=Gtk.FileFilter() + file_filter_subt = Gtk.FileFilter() file_filter_subt.set_name(_("Subtitle files")) file_filter_subt.add_pattern("*.sub") @@ -86,7 +89,7 @@ class ask_subtitles: file_filter_subt.add_pattern("*.txt") file_filter_subt.add_pattern("*.aqt") - file_filter_all=Gtk.FileFilter() + file_filter_all = Gtk.FileFilter() file_filter_all.set_name(_("All files")) file_filter_all.add_pattern("*") @@ -96,8 +99,9 @@ class ask_subtitles: wask_window.show_all() self.on_subtitle_file_set(None) retval = wask_window.run() - if (retval == 2): # accept - self.put_upper = builder.get_object("put_subtitles_upper").get_active() + if (retval == 2): # accept + self.put_upper = builder.get_object( + "put_subtitles_upper").get_active() self.config.sub_codepage = wencoding.get_active_id() self.config.sub_language = wlanguage.get_active_id() self.encoding = wencoding.get_active_id() @@ -110,9 +114,8 @@ class ask_subtitles: else: return False - - def on_subtitle_file_set(self,b): - + def on_subtitle_file_set(self, b): + f = self.wfilename.get_filename() if (f is None) or (f == ""): self.waccept.set_sensitive(False) diff --git a/src/devedeng/avbase.py b/src/devedeng/avbase.py index 1d4e49a..44bcf4f 100644 --- a/src/devedeng/avbase.py +++ b/src/devedeng/avbase.py @@ -20,12 +20,14 @@ import devedeng.executor import subprocess + class avbase(devedeng.executor.executor): - def check_version(self,cmd): + def check_version(self, cmd): try: - handle = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() if 0 != handle.wait(): return False @@ -33,18 +35,17 @@ class avbase(devedeng.executor.executor): return False self.check_version_txt(stdout) - - def check_version_txt(self,vtext): + def check_version_txt(self, vtext): self.major_version = 0 self.minor_version = 0 - + for line in vtext: if not isinstance(line, str): continue if (line.startswith("avconv version")): - pos1 = line.find('.',15) - pos2 = line.find('-',15) + pos1 = line.find('.', 15) + pos2 = line.find('-', 15) if (pos2 == -1): return False try: @@ -53,12 +54,10 @@ class avbase(devedeng.executor.executor): minor = 0 else: major = int(line[15:pos1].strip()) - minor = int(line[pos1+1:pos2].strip()) + minor = int(line[pos1 + 1:pos2].strip()) except: return False self.major_version = major self.minor_version = minor return True return False - - diff --git a/src/devedeng/avconv.py b/src/devedeng/avconv.py index 7cbc8e6..ea0275a 100644 --- a/src/devedeng/avconv.py +++ b/src/devedeng/avconv.py @@ -23,537 +23,551 @@ import devedeng.configuration_data import devedeng.avbase import devedeng.mux_dvd_menu + class avconv(devedeng.avbase.avbase): - supports_analize = False - supports_play = False - supports_convert = True - supports_menu = True - supports_mkiso = False - supports_burn = False - display_name = "AVCONV" - disc_types = [] + supports_analize = False + supports_play = False + supports_convert = True + supports_menu = True + supports_mkiso = False + supports_burn = False + display_name = "AVCONV" + disc_types = [] + @staticmethod + def check_is_installed(): + try: + handle = subprocess.Popen( + ["avconv", "-codecs"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdout, stderr) = handle.communicate() + if 0 == handle.wait(): + mp2 = False + mp3 = False + ac3 = False + mpeg1 = False + mpeg2 = False + divx = False + h264 = False + for line in stdout.decode("latin-1").split("\n"): + parts = line.strip().split(" ") + if len(parts) < 2: + continue + if len(parts[0]) != 6: + continue + capabilities = parts[0] + codec = parts[1] - @staticmethod - def check_is_installed(): - try: - handle = subprocess.Popen(["avconv","-codecs"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) - (stdout, stderr) = handle.communicate() - if 0==handle.wait(): - mp2 = False - mp3 = False - ac3 = False - mpeg1 = False - mpeg2 = False - divx = False - h264 = False - for line in stdout.decode("latin-1").split("\n"): - parts = line.strip().split(" ") - if len(parts) < 2: - continue - if len(parts[0]) != 6: - continue - capabilities = parts[0] - codec = parts[1] + if capabilities[1] != 'E': + continue - if capabilities[1] != 'E': - continue + if (codec == "mpeg1video"): + mpeg1 = True + continue + if (codec == "mpeg2video"): + mpeg2 = True + continue + if (codec == "mp2"): + mp2 = True + continue + if (codec == "mp3"): + mp3 = True + continue + if (codec == "ac3"): + ac3 = True + continue + if (codec == "h264") or (codec == "H264"): + h264 = True + continue + if (codec == "mpeg4"): + divx = True + continue - if (codec == "mpeg1video"): - mpeg1 = True - continue - if (codec == "mpeg2video"): - mpeg2 = True - continue - if (codec == "mp2"): - mp2 = True - continue - if (codec == "mp3"): - mp3 = True - continue - if (codec == "ac3"): - ac3 = True - continue - if (codec == "h264") or (codec == "H264"): - h264 = True - continue - if (codec == "mpeg4"): - divx = True - continue + if (mpeg1 and mp2): + devedeng.avconv.avconv.disc_types.append("vcd") + if (mpeg2 and mp2): + devedeng.avconv.avconv.disc_types.append("svcd") + devedeng.avconv.avconv.disc_types.append("cvd") + if (mpeg2 and mp2 and ac3): + devedeng.avconv.avconv.disc_types.append("dvd") + if (divx and mp3): + devedeng.avconv.avconv.disc_types.append("divx") + if (h264 and mp3): + devedeng.avconv.avconv.disc_types.append("mkv") - if (mpeg1 and mp2): - devedeng.avconv.avconv.disc_types.append("vcd") - if (mpeg2 and mp2): - devedeng.avconv.avconv.disc_types.append("svcd") - devedeng.avconv.avconv.disc_types.append("cvd") - if (mpeg2 and mp2 and ac3): - devedeng.avconv.avconv.disc_types.append("dvd") - if (divx and mp3): - devedeng.avconv.avconv.disc_types.append("divx") - if (h264 and mp3): - devedeng.avconv.avconv.disc_types.append("mkv") + return True + else: + return False + except: + return False - return True - else: - return False - except: - return False + def __init__(self): + devedeng.executor.executor.__init__(self) + self.config = devedeng.configuration_data.configuration.get_config() + self.check_version(["avconv", "-version"]) - def __init__(self): + def convert_file(self, file_project, output_file, video_length, pass2=False): - devedeng.executor.executor.__init__(self) - self.config = devedeng.configuration_data.configuration.get_config() - self.check_version(["avconv","-version"]) + if file_project.two_pass_encoding: + if pass2: + self.text = _("Converting %(X)s (pass 2)") % { + "X": file_project.title_name} + else: + self.text = _("Converting %(X)s (pass 1)") % { + "X": file_project.title_name} + # Prepare the converting process for the second pass + tmp = devedeng.avconv.avconv() + tmp.convert_file(file_project, output_file, video_length, True) + # it deppends of this process + tmp.add_dependency(self) + # add it as a child process of this one + self.add_child_process(tmp) + else: + self.text = _("Converting %(X)s") % {"X": file_project.title_name} + if (pass2 == False) and (file_project.two_pass_encoding == True): + # this is the first pass in a 2-pass codification + second_pass = False + else: + # second_pass is TRUE in the second pass of a 2-pass codification, and also when not doing 2-pass codification + # It is used to remove unnecessary steps during the first pass, but + # that are needed on the second pass, or when not using 2-pass + # codification + second_pass = True - def convert_file(self,file_project,output_file,video_length,pass2 = False): + if (video_length == 0): + self.final_length = file_project.original_length + else: + self.final_length = video_length + self.command_var = [] + self.command_var.append("avconv") + self.command_var.append("-i") + self.command_var.append(file_project.file_name) - if file_project.two_pass_encoding: - if pass2: - self.text = _("Converting %(X)s (pass 2)") % {"X" : file_project.title_name} - else: - self.text = _("Converting %(X)s (pass 1)") % {"X" : file_project.title_name} - # Prepare the converting process for the second pass - tmp = devedeng.avconv.avconv() - tmp.convert_file(file_project, output_file, video_length, True) - # it deppends of this process - tmp.add_dependency(self) - # add it as a child process of this one - self.add_child_process(tmp) - else: - self.text = _("Converting %(X)s") % {"X" : file_project.title_name} + if (file_project.volume != 100) and second_pass: + self.command_var.append("-vol") + self.command_var.append( + str(int((256 * file_project.volume) / 100))) - if (pass2 == False) and (file_project.two_pass_encoding == True): - # this is the first pass in a 2-pass codification - second_pass = False - else: - # second_pass is TRUE in the second pass of a 2-pass codification, and also when not doing 2-pass codification - # It is used to remove unnecessary steps during the first pass, but that are needed on the second pass, or when not using 2-pass codification - second_pass = True + if (file_project.audio_delay != 0.0) and (file_project.copy_sound == False) and (file_project.no_reencode_audio_video == False) and second_pass: + self.command_var.append("-itsoffset") + self.command_var.append(str(file_project.audio_delay)) - if (video_length == 0): - self.final_length = file_project.original_length - else: - self.final_length = video_length - self.command_var=[] - self.command_var.append("avconv") - self.command_var.append("-i") - self.command_var.append(file_project.file_name) + self.command_var.append("-i") + self.command_var.append(file_project.file_name) + self.command_var.append("-map") + self.command_var.append("1:" + str(file_project.video_list[0])) + if (not file_project.copy_sound) and (not file_project.no_reencode_audio_video): + for l in file_project.audio_list: + self.command_var.append("-map") + self.command_var.append("0:" + str(l)) - if (file_project.volume!=100) and second_pass: - self.command_var.append("-vol") - self.command_var.append(str(int((256*file_project.volume)/100))) + if (file_project.no_reencode_audio_video == False) and second_pass: + cmd_line = "" - if (file_project.audio_delay != 0.0) and (file_project.copy_sound==False) and (file_project.no_reencode_audio_video==False) and second_pass: - self.command_var.append("-itsoffset") - self.command_var.append(str(file_project.audio_delay)) + if file_project.deinterlace == "deinterlace_yadif": + cmd_line += "yadif" - self.command_var.append("-i") - self.command_var.append(file_project.file_name) - self.command_var.append("-map") - self.command_var.append("1:"+str(file_project.video_list[0])) - if (not file_project.copy_sound) and (not file_project.no_reencode_audio_video): - for l in file_project.audio_list: - self.command_var.append("-map") - self.command_var.append("0:"+str(l)) + vflip = False + hflip = False - if (file_project.no_reencode_audio_video==False) and second_pass: - cmd_line="" + if (file_project.rotation == "rotation_90"): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "transpose=1" + elif (file_project.rotation == "rotation_270"): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "transpose=2" + elif (file_project.rotation == "rotation_180"): + vflip = True + hflip = True - if file_project.deinterlace=="deinterlace_yadif": - cmd_line+="yadif" + if (file_project.mirror_vertical): + vflip = not vflip + if (file_project.mirror_horizontal): + hflip = not hflip - vflip=False - hflip=False + if (vflip): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "vflip" + if (hflip): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "hflip" - if (file_project.rotation=="rotation_90"): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="transpose=1" - elif (file_project.rotation=="rotation_270"): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="transpose=2" - elif (file_project.rotation=="rotation_180"): - vflip=True - hflip=True + if (file_project.width_midle != file_project.original_width) or (file_project.height_midle != file_project.original_height): + if (cmd_line != ""): + cmd_line += ",fifo," + x = int((file_project.width_midle - + file_project.original_width) / 2) + y = int((file_project.height_midle - + file_project.original_height) / 2) + if (x > 0) or (y > 0): + cmd_line += "pad=" + str(file_project.width_midle) + ":" + str( + file_project.height_midle) + ":" + str(x) + ":" + str(y) + ":0x000000" + else: + cmd_line += "crop=" + str(file_project.width_midle) + ":" + str( + file_project.height_midle) + ":" + str(x) + ":" + str(y) - if (file_project.mirror_vertical): - vflip=not vflip - if (file_project.mirror_horizontal): - hflip=not hflip + if (file_project.width_final != file_project.width_midle) or (file_project.height_final != file_project.height_midle): + if (cmd_line != ""): + cmd_line += ",fifo," + if self.major_version < 11: + cmd_line += "scale=" + \ + str(file_project.width_final) + ":" + \ + str(file_project.height_final) + else: + cmd_line += "scale=w=" + \ + str(file_project.width_final) + ":h=" + \ + str(file_project.height_final) - if (vflip): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="vflip" - if (hflip): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="hflip" + if cmd_line != "": + self.command_var.append("-vf") + self.command_var.append(cmd_line) - if (file_project.width_midle != file_project.original_width) or (file_project.height_midle != file_project.original_height): - if (cmd_line!=""): - cmd_line+=",fifo," - x = int((file_project.width_midle - file_project.original_width) /2) - y = int((file_project.height_midle - file_project.original_height) /2) - if (x > 0) or (y > 0): - cmd_line+="pad="+str(file_project.width_midle)+":"+str(file_project.height_midle)+":"+str(x)+":"+str(y)+":0x000000" - else: - cmd_line+="crop="+str(file_project.width_midle)+":"+str(file_project.height_midle)+":"+str(x)+":"+str(y) + self.command_var.append("-y") - if (file_project.width_final != file_project.width_midle) or (file_project.height_final != file_project.height_midle): - if (cmd_line!=""): - cmd_line+=",fifo," - if self.major_version < 11: - cmd_line+="scale="+str(file_project.width_final)+":"+str(file_project.height_final) - else: - cmd_line+="scale=w="+str(file_project.width_final)+":h="+str(file_project.height_final) + vcd = False - if cmd_line!="": - self.command_var.append("-vf") - self.command_var.append(cmd_line) + maxrate = int(file_project.video_rate_final * 1500) + minrate = int(file_project.video_rate_final * 666.66) + if (self.config.disc_type == "divx"): + self.command_var.append("-vcodec") + self.command_var.append("mpeg4") + self.command_var.append("-acodec") + self.command_var.append("libmp3lame") + self.command_var.append("-f") + self.command_var.append("avi") + self.command_var.append("-maxrate:v") + self.command_var.append(str(maxrate)) + self.command_var.append("-minrate:v") + if minrate < (devedeng.project.devede_project.divx_min_bps * 1000): + minrate = devedeng.project.devede_project.divx_min_bps * 1000 + self.command_var.append(str(minrate)) + elif (self.config.disc_type == "mkv"): + self.command_var.append("-vcodec") + self.command_var.append("h264") + self.command_var.append("-acodec") + self.command_var.append("libmp3lame") + self.command_var.append("-f") + self.command_var.append("matroska") + self.command_var.append("-maxrate:v") + self.command_var.append(str(maxrate)) + self.command_var.append("-minrate:v") + if minrate < (devedeng.project.devede_project.mkv_min_bps * 1000): + minrate = devedeng.project.devede_project.mkv_min_bps * 1000 + self.command_var.append(str(minrate)) + elif (self.config.disc_type == "dvd"): + if not file_project.no_reencode_audio_video: + self.command_var.append("-c:v") + self.command_var.append("mpeg2video") + if not file_project.copy_sound: + if file_project.sound5_1: + self.command_var.append("-c:a") + self.command_var.append("ac3") + else: + self.command_var.append("-c:a") + if file_project.format_pal: + self.command_var.append("ac3") + else: + self.command_var.append("mp2") + self.command_var.append("-f") + self.command_var.append("dvd") + self.command_var.append("-r") + if file_project.format_pal: + self.command_var.append("25") + else: + if (file_project.original_fps == 24): + self.command_var.append("24000/1001") + else: + self.command_var.append("30000/1001") + self.command_var.append("-pix_fmt") + self.command_var.append("yuv420p") + self.command_var.append("-maxrate:v") + if maxrate > (devedeng.project.devede_project.dvd_max_bps_base[0] * 1000): + maxrate = devedeng.project.devede_project.dvd_max_bps_base[ + 0] * 1000 + self.command_var.append(str(maxrate)) + self.command_var.append("-minrate:v") + if minrate < (devedeng.project.devede_project.dvd_min_bps * 1000): + minrate = devedeng.project.devede_project.dvd_min_bps * 1000 + self.command_var.append(str(minrate)) + self.command_var.append("-bufsize") + self.command_var.append("1835008") + self.command_var.append("-packetsize") + self.command_var.append("2048") + self.command_var.append("-muxrate") + self.command_var.append("10080000") + self.command_var.append("-ar") + self.command_var.append("48000") + elif (self.config.disc_type == "vcd"): + vcd = True + if not file_project.no_reencode_audio_video: + self.command_var.append("-c:v") + self.command_var.append("mpeg1video") + if not file_project.copy_sound: + self.command_var.append("-c:a") + self.command_var.append("mp2") + self.command_var.append("-b:v") + self.command_var.append("1150000") + self.command_var.append("-b:a") + self.command_var.append("224000") + self.command_var.append("-f") + self.command_var.append("vcd") + self.command_var.append("-r") + if file_project.format_pal: + self.command_var.append("25") + else: + if (file_project.original_fps == 24): + self.command_var.append("24000/1001") + else: + self.command_var.append("30000/1001") + self.command_var.append("-g") + if file_project.format_pal: + self.command_var.append("15") + else: + self.command_var.append("18") + self.command_var.append("-s") + if file_project.format_pal: + self.command_var.append("352x288") + else: + self.command_var.append("352x240") + self.command_var.append("-maxrate:v") + self.command_var.append("1150000") + self.command_var.append("-minrate:v") + self.command_var.append("1150000") + self.command_var.append("-bufsize") + self.command_var.append("327680") + self.command_var.append("-packetsize") + self.command_var.append("2324") + self.command_var.append("-muxrate") + self.command_var.append("1411200") + self.command_var.append("-ar") + self.command_var.append("44100") + elif (self.config.disc_type == "svcd") or (self.config.disc_type == "cvd"): + if not file_project.no_reencode_audio_video: + self.command_var.append("-c:v") + self.command_var.append("mpeg2video") + if not file_project.copy_sound: + self.command_var.append("-c:a") + self.command_var.append("mp2") + self.command_var.append("-f") + self.command_var.append("svcd") + self.command_var.append("-r") + if file_project.format_pal: + self.command_var.append("25") + else: + if (file_project.original_fps == 24): + self.command_var.append("24000/1001") + else: + self.command_var.append("30000/1001") + self.command_var.append("-g") + if file_project.format_pal: + self.command_var.append("12") + else: + self.command_var.append("15") + self.command_var.append("-s") + if self.config.disc_type == "cvd": + if file_project.format_pal: + self.command_var.append("352x576") + else: + self.command_var.append("352x480") + else: + if file_project.format_pal: + self.command_var.append("480x576") + else: + self.command_var.append("480x480") + self.command_var.append("-pix_fmt") + self.command_var.append("yuv420p") + self.command_var.append("-maxrate:v") + if maxrate > (devedeng.project.devede_project.svcd_max_bps_base[0] * 1000): + maxrate = devedeng.project.devede_project.svcd_max_bps_base[ + 0] * 1000 + self.command_var.append(str(maxrate)) + self.command_var.append("-minrate:v") + if minrate < (devedeng.project.devede_project.svcd_min_bps * 1000): + minrate = (devedeng.project.devede_project.svcd_min_bps * 1000) + self.command_var.append(str(minrate)) + self.command_var.append("-bufsize") + self.command_var.append("1835008") + self.command_var.append("-packetsize") + self.command_var.append("2324") + self.command_var.append("-ar") + self.command_var.append("44100") + self.command_var.append("-scan_offset") + self.command_var.append("1") - self.command_var.append("-y") + if (not file_project.no_reencode_audio_video): + self.command_var.append("-sn") # no subtitles - vcd = False - - maxrate = int(file_project.video_rate_final * 1500) - minrate = int(file_project.video_rate_final * 666.66) + if file_project.copy_sound or file_project.no_reencode_audio_video: + self.command_var.append("-acodec") + self.command_var.append("copy") - if (self.config.disc_type == "divx"): - self.command_var.append("-vcodec") - self.command_var.append("mpeg4") - self.command_var.append("-acodec") - self.command_var.append("libmp3lame") - self.command_var.append("-f") - self.command_var.append("avi") - self.command_var.append("-maxrate:v") - self.command_var.append(str(maxrate)) - self.command_var.append("-minrate:v") - if minrate < (devedeng.project.devede_project.divx_min_bps * 1000): - minrate = devedeng.project.devede_project.divx_min_bps * 1000 - self.command_var.append(str(minrate)) - elif (self.config.disc_type == "mkv"): - self.command_var.append("-vcodec") - self.command_var.append("h264") - self.command_var.append("-acodec") - self.command_var.append("libmp3lame") - self.command_var.append("-f") - self.command_var.append("matroska") - self.command_var.append("-maxrate:v") - self.command_var.append(str(maxrate)) - self.command_var.append("-minrate:v") - if minrate < (devedeng.project.devede_project.mkv_min_bps * 1000): - minrate = devedeng.project.devede_project.mkv_min_bps * 1000 - self.command_var.append(str(minrate)) - elif (self.config.disc_type=="dvd"): - if not file_project.no_reencode_audio_video: - self.command_var.append("-c:v") - self.command_var.append("mpeg2video") - if not file_project.copy_sound: - if file_project.sound5_1: - self.command_var.append("-c:a") - self.command_var.append("ac3") - else: - self.command_var.append("-c:a") - if file_project.format_pal: - self.command_var.append("ac3") - else: - self.command_var.append("mp2") - self.command_var.append("-f") - self.command_var.append("dvd") - self.command_var.append("-r") - if file_project.format_pal: - self.command_var.append("25") - else: - if (file_project.original_fps == 24): - self.command_var.append("24000/1001") - else: - self.command_var.append("30000/1001") - self.command_var.append("-pix_fmt") - self.command_var.append("yuv420p") - self.command_var.append("-maxrate:v") - if maxrate > (devedeng.project.devede_project.dvd_max_bps_base[0] * 1000): - maxrate = devedeng.project.devede_project.dvd_max_bps_base[0] * 1000 - self.command_var.append(str(maxrate)) - self.command_var.append("-minrate:v") - if minrate < (devedeng.project.devede_project.dvd_min_bps * 1000): - minrate = devedeng.project.devede_project.dvd_min_bps * 1000 - self.command_var.append(str(minrate)) - self.command_var.append("-bufsize") - self.command_var.append("1835008") - self.command_var.append("-packetsize") - self.command_var.append("2048") - self.command_var.append("-muxrate") - self.command_var.append("10080000") - self.command_var.append("-ar") - self.command_var.append("48000") - elif (self.config.disc_type=="vcd"): - vcd = True - if not file_project.no_reencode_audio_video: - self.command_var.append("-c:v") - self.command_var.append("mpeg1video") - if not file_project.copy_sound: - self.command_var.append("-c:a") - self.command_var.append("mp2") - self.command_var.append("-b:v") - self.command_var.append("1150000") - self.command_var.append("-b:a") - self.command_var.append("224000") - self.command_var.append("-f") - self.command_var.append("vcd") - self.command_var.append("-r") - if file_project.format_pal: - self.command_var.append("25") - else: - if (file_project.original_fps == 24): - self.command_var.append("24000/1001") - else: - self.command_var.append("30000/1001") - self.command_var.append("-g") - if file_project.format_pal: - self.command_var.append("15") - else: - self.command_var.append("18") - self.command_var.append("-s") - if file_project.format_pal: - self.command_var.append("352x288") - else: - self.command_var.append("352x240") - self.command_var.append("-maxrate:v") - self.command_var.append("1150000") - self.command_var.append("-minrate:v") - self.command_var.append("1150000") - self.command_var.append("-bufsize") - self.command_var.append("327680") - self.command_var.append("-packetsize") - self.command_var.append("2324") - self.command_var.append("-muxrate") - self.command_var.append("1411200") - self.command_var.append("-ar") - self.command_var.append("44100") - elif (self.config.disc_type=="svcd") or (self.config.disc_type=="cvd"): - if not file_project.no_reencode_audio_video: - self.command_var.append("-c:v") - self.command_var.append("mpeg2video") - if not file_project.copy_sound: - self.command_var.append("-c:a") - self.command_var.append("mp2") - self.command_var.append("-f") - self.command_var.append("svcd") - self.command_var.append("-r") - if file_project.format_pal: - self.command_var.append("25") - else: - if (file_project.original_fps == 24): - self.command_var.append("24000/1001") - else: - self.command_var.append("30000/1001") - self.command_var.append("-g") - if file_project.format_pal: - self.command_var.append("12") - else: - self.command_var.append("15") - self.command_var.append("-s") - if self.config.disc_type == "cvd": - if file_project.format_pal: - self.command_var.append("352x576") - else: - self.command_var.append("352x480") - else: - if file_project.format_pal: - self.command_var.append("480x576") - else: - self.command_var.append("480x480") - self.command_var.append("-pix_fmt") - self.command_var.append("yuv420p") - self.command_var.append("-maxrate:v") - if maxrate > (devedeng.project.devede_project.svcd_max_bps_base[0] * 1000): - maxrate = devedeng.project.devede_project.svcd_max_bps_base[0] * 1000 - self.command_var.append(str(maxrate)) - self.command_var.append("-minrate:v") - if minrate < (devedeng.project.devede_project.svcd_min_bps * 1000): - minrate = (devedeng.project.devede_project.svcd_min_bps * 1000) - self.command_var.append(str(minrate)) - self.command_var.append("-bufsize") - self.command_var.append("1835008") - self.command_var.append("-packetsize") - self.command_var.append("2324") - self.command_var.append("-ar") - self.command_var.append("44100") - self.command_var.append("-scan_offset") - self.command_var.append("1") + if file_project.no_reencode_audio_video: + self.command_var.append("-vcodec") + self.command_var.append("copy") - if (not file_project.no_reencode_audio_video): - self.command_var.append("-sn") # no subtitles + if (not vcd): + if not file_project.format_pal: + if (file_project.original_fps == 24) and ((self.config.disc_type == "dvd")): + keyintv = 15 + else: + keyintv = 18 + else: + keyintv = 15 - if file_project.copy_sound or file_project.no_reencode_audio_video: - self.command_var.append("-acodec") - self.command_var.append("copy") + if (not file_project.gop12) and (not(self.config.disc_type == "divx")) and (not(self.config.disc_type == "mkv")): + self.command_var.append("-g") + self.command_var.append(str(keyintv)) - if file_project.no_reencode_audio_video: - self.command_var.append("-vcodec") - self.command_var.append("copy") + if (self.config.disc_type == "divx") or (self.config.disc_type == "mkv"): + self.command_var.append("-g") + self.command_var.append("300") + elif file_project.gop12 and (file_project.no_reencode_audio_video == False): + self.command_var.append("-g") + self.command_var.append("12") - if (not vcd): - if not file_project.format_pal: - if (file_project.original_fps==24) and ((self.config.disc_type=="dvd")): - keyintv=15 - else: - keyintv=18 - else: - keyintv=15 + self.command_var.append("-bf") + self.command_var.append("2") + self.command_var.append("-strict") + self.command_var.append("1") - if (not file_project.gop12) and (not(self.config.disc_type == "divx")) and (not(self.config.disc_type == "mkv")): - self.command_var.append("-g") - self.command_var.append(str(keyintv)) + if video_length != 0: + self.command_var.append("-t") + self.command_var.append(str(video_length)) - if (self.config.disc_type == "divx") or (self.config.disc_type == "mkv"): - self.command_var.append("-g") - self.command_var.append("300") - elif file_project.gop12 and (file_project.no_reencode_audio_video == False): - self.command_var.append("-g") - self.command_var.append("12") + self.command_var.append("-ac") + if (file_project.sound5_1) and ((self.config.disc_type == "dvd") or (self.config.disc_type == "divx") or (self.config.disc_type == "mkv")): + self.command_var.append("6") + else: + self.command_var.append("2") - self.command_var.append("-bf") - self.command_var.append("2") - self.command_var.append("-strict") - self.command_var.append("1") + self.command_var.append("-aspect") + self.command_var.append(str(file_project.aspect_ratio_final)) - if video_length != 0: - self.command_var.append("-t") - self.command_var.append(str(video_length)) + if self.config.disc_type == "divx": + self.command_var.append("-vtag") + self.command_var.append("DX50") - self.command_var.append("-ac") - if (file_project.sound5_1) and ((self.config.disc_type=="dvd") or (self.config.disc_type=="divx") or (self.config.disc_type=="mkv")): - self.command_var.append("6") - else: - self.command_var.append("2") + if (file_project.deinterlace == "deinterlace_ffmpeg") and (file_project.no_reencode_audio_video == False) and second_pass: + self.command_var.append("-deinterlace") - self.command_var.append("-aspect") - self.command_var.append(str(file_project.aspect_ratio_final)) + if (file_project.no_reencode_audio_video == False) and (vcd == False) and second_pass: + self.command_var.append("-s") + self.command_var.append( + str(file_project.width_final) + "x" + str(file_project.height_final)) - if self.config.disc_type=="divx": - self.command_var.append("-vtag") - self.command_var.append("DX50") + if second_pass: + self.command_var.append("-trellis") + self.command_var.append("1") + self.command_var.append("-mbd") + self.command_var.append("2") + else: + self.command_var.append("-trellis") + self.command_var.append("0") + self.command_var.append("-mbd") + self.command_var.append("0") - if (file_project.deinterlace == "deinterlace_ffmpeg") and (file_project.no_reencode_audio_video==False) and second_pass: - self.command_var.append("-deinterlace") + if (vcd == False) and (file_project.no_reencode_audio_video == False): + self.command_var.append("-b:a") + self.command_var.append(str(file_project.audio_rate_final) + "k") - if (file_project.no_reencode_audio_video==False) and (vcd==False) and second_pass: - self.command_var.append("-s") - self.command_var.append(str(file_project.width_final)+"x"+str(file_project.height_final)) + self.command_var.append("-b:v") + self.command_var.append(str(file_project.video_rate_final) + "k") - if second_pass: - self.command_var.append("-trellis") - self.command_var.append("1") - self.command_var.append("-mbd") - self.command_var.append("2") - else: - self.command_var.append("-trellis") - self.command_var.append("0") - self.command_var.append("-mbd") - self.command_var.append("0") + if file_project.two_pass_encoding == True: + self.command_var.append("-passlogfile") + self.command_var.append(output_file) + self.command_var.append("-pass") + if pass2: + self.command_var.append("2") + else: + self.command_var.append("1") - if (vcd == False) and (file_project.no_reencode_audio_video == False): - self.command_var.append("-b:a") - self.command_var.append(str(file_project.audio_rate_final)+"k") + self.command_var.append(output_file) - self.command_var.append("-b:v") - self.command_var.append(str(file_project.video_rate_final)+"k") + def create_menu_mpeg(self, n_page, background_music, sound_length, pal, video_rate, audio_rate, output_path, use_mp2): - if file_project.two_pass_encoding == True: - self.command_var.append("-passlogfile") - self.command_var.append(output_file) - self.command_var.append("-pass") - if pass2: - self.command_var.append("2") - else: - self.command_var.append("1") + self.n_page = n_page + self.final_length = float(sound_length) + self.text = _("Creating menu %(X)d") % {"X": self.n_page} - self.command_var.append(output_file) + self.command_var = [] + self.command_var.append("avconv") + self.command_var.append("-loop") + self.command_var.append("1") - def create_menu_mpeg(self,n_page,background_music,sound_length,pal,video_rate, audio_rate,output_path, use_mp2): + self.command_var.append("-f") + self.command_var.append("image2") + self.command_var.append("-i") + self.command_var.append(os.path.join( + output_path, "menu_" + str(n_page) + "_bg.png")) + self.command_var.append("-i") + self.command_var.append(background_music) - self.n_page = n_page - self.final_length = float(sound_length) - self.text = _("Creating menu %(X)d") % {"X": self.n_page} + self.command_var.append("-y") + self.command_var.append("-target") + if pal: + self.command_var.append("pal-dvd") + else: + self.command_var.append("ntsc-dvd") + self.command_var.append("-acodec") + if (use_mp2): + self.command_var.append("mp2") + if (audio_rate > 384): + audio_rate = 384 # max bitrate for mp2 + else: + self.command_var.append("ac3") + self.command_var.append("-s") + if pal: + self.command_var.append("720x576") + else: + self.command_var.append("720x480") + self.command_var.append("-g") + self.command_var.append("12") + self.command_var.append("-b:v") + self.command_var.append(str(video_rate) + "k") + self.command_var.append("-b:a") + self.command_var.append(str(audio_rate) + "k") + self.command_var.append("-aspect") + self.command_var.append("4:3") - self.command_var=[] - self.command_var.append("avconv") + self.command_var.append("-t") + self.command_var.append(str(1 + sound_length)) - self.command_var.append("-loop") - self.command_var.append("1") + movie_path = os.path.join(output_path, "menu_" + str(n_page) + ".mpg") + self.command_var.append(movie_path) - self.command_var.append("-f") - self.command_var.append("image2") - self.command_var.append("-i") - self.command_var.append(os.path.join(output_path,"menu_"+str(n_page)+"_bg.png")) - self.command_var.append("-i") - self.command_var.append(background_music) + muxer = devedeng.mux_dvd_menu.mux_dvd_menu() + final_path = muxer.create_mpg(n_page, output_path, movie_path) + # the muxer process depends of the converter process + muxer.add_dependency(self) + self.add_child_process(muxer) - self.command_var.append("-y") - self.command_var.append("-target") - if pal: - self.command_var.append("pal-dvd") - else: - self.command_var.append("ntsc-dvd") - self.command_var.append("-acodec") - if (use_mp2): - self.command_var.append("mp2") - if (audio_rate > 384): - audio_rate = 384 #max bitrate for mp2 - else: - self.command_var.append("ac3") - self.command_var.append("-s") - if pal: - self.command_var.append("720x576") - else: - self.command_var.append("720x480") - self.command_var.append("-g") - self.command_var.append("12") - self.command_var.append("-b:v") - self.command_var.append(str(video_rate)+"k") - self.command_var.append("-b:a") - self.command_var.append(str(audio_rate)+"k") - self.command_var.append("-aspect") - self.command_var.append("4:3") + return (final_path) - self.command_var.append("-t") - self.command_var.append(str(1+sound_length)) + def process_stdout(self, data): - movie_path = os.path.join(output_path,"menu_"+str(n_page)+".mpg") - self.command_var.append(movie_path) + return - muxer = devedeng.mux_dvd_menu.mux_dvd_menu() - final_path = muxer.create_mpg(n_page,output_path,movie_path) - # the muxer process depends of the converter process - muxer.add_dependency(self) - self.add_child_process(muxer) + def process_stderr(self, data): - return (final_path) - - def process_stdout(self,data): - - return - - def process_stderr(self,data): - - pos = data[0].find("time=") - if (pos != -1): - pos+=5 - pos2 = data[0].find(" ",pos) - if (pos2 != -1): - parts = data[0][pos:pos2].split(":") - t = 0.0 - for e in parts: - t *= 60.0 - t += float(e) - t /= self.final_length - self.progress_bar[1].set_fraction(t) - self.progress_bar[1].set_text("%.1f%%" % (100.0 * t)) + pos = data[0].find("time=") + if (pos != -1): + pos += 5 + pos2 = data[0].find(" ", pos) + if (pos2 != -1): + parts = data[0][pos:pos2].split(":") + t = 0.0 + for e in parts: + t *= 60.0 + t += float(e) + t /= self.final_length + self.progress_bar[1].set_fraction(t) + self.progress_bar[1].set_text("%.1f%%" % (100.0 * t)) diff --git a/src/devedeng/avprobe.py b/src/devedeng/avprobe.py index 665f8b9..0bb67ff 100644 --- a/src/devedeng/avprobe.py +++ b/src/devedeng/avprobe.py @@ -23,6 +23,7 @@ import devedeng.executor import os import json + class avprobe(devedeng.avbase.avbase): supports_analize = True @@ -36,9 +37,10 @@ class avprobe(devedeng.avbase.avbase): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["avprobe","-h"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["avprobe", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -50,10 +52,10 @@ class avprobe(devedeng.avbase.avbase): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): return def get_film_data(self, file_name): @@ -62,23 +64,23 @@ class avprobe(devedeng.avbase.avbase): self.original_file_size = os.path.getsize(file_name) - command_line = ["avprobe",file_name,"-of","json","-show_streams", "-loglevel", "quiet"] + command_line = ["avprobe", file_name, "-of", + "json", "-show_streams", "-loglevel", "quiet"] (stdout, stderr) = self.launch_process(command_line, False) - + try: stdout2 = stdout.decode("utf-8") except: stdout2 = stdout.decode("latin1") - self.config.append_static_log("AVProbe JSON data: "+str(stdout2)) + self.config.append_static_log("AVProbe JSON data: " + str(stdout2)) return self.process_json(stdout2, file_name) + def process_json(self, stdout2, file_name): - def process_json(self,stdout2,file_name): - - self.audio_list=[] + self.audio_list = [] self.audio_streams = 0 - self.video_list=[] + self.video_list = [] self.video_streams = 0 self.original_width = 0 self.original_height = 0 @@ -89,14 +91,15 @@ class avprobe(devedeng.avbase.avbase): self.original_fps = 0 self.original_aspect_ratio = 0 - self.config.append_static_log("Getting data for {:s} with avprobe".format(file_name)) + self.config.append_static_log( + "Getting data for {:s} with avprobe".format(file_name)) try: video_data = json.loads(stdout2) except: - return True # There was an error reading the JSON data + return True # There was an error reading the JSON data if not("streams" in video_data): - return True # There are no streams!!!!! + return True # There are no streams!!!!! for element in video_data["streams"]: @@ -106,50 +109,62 @@ class avprobe(devedeng.avbase.avbase): except: self.original_length = -1 - if (element["codec_type"]=="video"): + if (element["codec_type"] == "video"): self.video_streams += 1 self.video_list.append(element["index"]) if (self.video_streams == 1): self.original_width = int(float(element["width"])) self.original_height = int(float(element["height"])) if ("bit_rate" in element): - self.original_videorate = int(float(element["bit_rate"]))/1000 - self.original_fps = self.get_division(element["avg_frame_rate"]) + self.original_videorate = int( + float(element["bit_rate"])) / 1000 + self.original_fps = self.get_division( + element["avg_frame_rate"]) if ("display_aspect_ratio" in element): - self.original_aspect_ratio = self.get_division(element["display_aspect_ratio"]) + self.original_aspect_ratio = self.get_division( + element["display_aspect_ratio"]) - elif (element["codec_type"]=="audio"): + elif (element["codec_type"] == "audio"): self.audio_streams += 1 self.audio_list.append(element["index"]) if (self.audio_streams == 1): if ("bit_rate" in element): - self.original_audiorate = int(float(element["bit_rate"]))/1000 - self.original_audiorate_uncompressed = int(float(element["sample_rate"])) + self.original_audiorate = int( + float(element["bit_rate"])) / 1000 + self.original_audiorate_uncompressed = int( + float(element["sample_rate"])) - self.original_size = str(self.original_width)+"x"+str(self.original_height) + self.original_size = str(self.original_width) + \ + "x" + str(self.original_height) if (self.original_aspect_ratio is None) or (self.original_aspect_ratio <= 1.0): if (self.original_height != 0): - self.original_aspect_ratio = (float(self.original_width))/(float(self.original_height)) + self.original_aspect_ratio = ( + float(self.original_width)) / (float(self.original_height)) if (self.original_aspect_ratio is not None): - self.original_aspect_ratio = (float(int(self.original_aspect_ratio*1000.0)))/1000.0 + self.original_aspect_ratio = ( + float(int(self.original_aspect_ratio * 1000.0))) / 1000.0 if (len(self.video_list) == 0): - return True # the file is not a video file; maybe an audio-only file or another thing + return True # the file is not a video file; maybe an audio-only file or another thing - if self.original_length == -1: # if it was unable to detect the duration, try to use the human readable format - command_line = ["avprobe",file_name] + if self.original_length == -1: # if it was unable to detect the duration, try to use the human readable format + command_line = ["avprobe", file_name] (stdout, stderr) = self.launch_process(command_line, False) try: - stdout2 = stdout.decode("utf-8") + "\n" + stderr.decode("utf-8") + stdout2 = stdout.decode("utf-8") + \ + "\n" + stderr.decode("utf-8") except: - stdout2 = stdout.decode("latin1") + "\n" + stderr.decode("latin1") - self.config.append_static_log("Using avprobe human readable format: "+str(stdout2)) + stdout2 = stdout.decode("latin1") + \ + "\n" + stderr.decode("latin1") + self.config.append_static_log( + "Using avprobe human readable format: " + str(stdout2)) for line in stdout2.split("\n"): line = line.strip() if line.startswith("Duration: "): self.original_length = self.get_time(line[10:]) break - self.config.append_static_log("Estimated length: {:d}; Resolution: {:s}".format(self.original_length,self.original_size)) - return False # no error + self.config.append_static_log("Estimated length: {:d}; Resolution: {:s}".format( + self.original_length, self.original_size)) + return False # no error diff --git a/src/devedeng/brasero.py b/src/devedeng/brasero.py index 160a723..ebcdf51 100644 --- a/src/devedeng/brasero.py +++ b/src/devedeng/brasero.py @@ -19,6 +19,7 @@ import subprocess import devedeng.configuration_data import devedeng.executor + class brasero(devedeng.executor.executor): supports_analize = False @@ -32,9 +33,10 @@ class brasero(devedeng.executor.executor): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["brasero","-h"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["brasero", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -46,12 +48,12 @@ class brasero(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def burn(self,file_name): + def burn(self, file_name): self.command_var = ["brasero", file_name] - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): return diff --git a/src/devedeng/choose_disc_type.py b/src/devedeng/choose_disc_type.py index 3819e47..792ee20 100644 --- a/src/devedeng/choose_disc_type.py +++ b/src/devedeng/choose_disc_type.py @@ -15,22 +15,24 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from gi.repository import Gtk,GObject +from gi.repository import Gtk, GObject import os import subprocess import devedeng.configuration_data + class choose_disc_type(GObject.GObject): def __init__(self): - self.config = devedeng.configuration_data.configuration.get_config() + self.config = devedeng.configuration_data.configuration.get_config() builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wselect_disk.ui")) + builder.add_from_file(os.path.join( + self.config.glade, "wselect_disk.ui")) builder.connect_signals(self) self.wask_window = builder.get_object("wselect_disk") @@ -57,13 +59,13 @@ class choose_disc_type(GObject.GObject): if mkiso is not None: dvd = False - if self.check_program(["dvdauthor","--help"]) == False: + if self.check_program(["dvdauthor", "--help"]) == False: dvd = False - if self.check_program(["vcdimager","--help"]) == False: + if self.check_program(["vcdimager", "--help"]) == False: vcd = False svcd = False cvd = False - if self.check_program(["spumux" , "--help"]) == False: + if self.check_program(["spumux", "--help"]) == False: dvd = False vcd = False svcd = False @@ -91,55 +93,56 @@ class choose_disc_type(GObject.GObject): self.wask_window.show_all() - def check_program(self,command_line): + def check_program(self, command_line): try: - handle = subprocess.Popen(command_line, stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + command_line, stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() retval = handle.wait() return True except: return False - def set_type(self,disc_type): - + def set_type(self, disc_type): + self.config.set_disc_type(disc_type) self.wask_window.hide() self.wask_window.destroy() self.wask_window = None - def on_button_dvd_clicked(self,b): + def on_button_dvd_clicked(self, b): self.set_type("dvd") - def on_button_vcd_clicked(self,b): + def on_button_vcd_clicked(self, b): self.set_type("vcd") - def on_button_svcd_clicked(self,b): + def on_button_svcd_clicked(self, b): self.set_type("svcd") - def on_button_cvd_clicked(self,b): + def on_button_cvd_clicked(self, b): self.set_type("cvd") - def on_button_divx_clicked(self,b): + def on_button_divx_clicked(self, b): self.set_type("divx") - def on_button_mkv_clicked(self,b): + def on_button_mkv_clicked(self, b): self.set_type("mkv") - def on_help_clicked(self,b): - + def on_help_clicked(self, b): + help_file = devedeng.help.help("select.html") - def on_programs_needed_clicked(self,b): + def on_programs_needed_clicked(self, b): builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wneeded.ui")) + builder.add_from_file(os.path.join(self.config.glade, "wneeded.ui")) window = builder.get_object("needed") textbuf = builder.get_object("textbuffer") @@ -151,18 +154,24 @@ class choose_disc_type(GObject.GObject): text = "" for e in analizers: if analizers_i.count(e.display_name) == 0: - text += _("\t%(program_name)s (not installed)\n") % {"program_name": e.display_name} + text += _("\t%(program_name)s (not installed)\n") % { + "program_name": e.display_name} else: - text += _("\t%(program_name)s (installed)\n") % {"program_name": e.display_name} - text1 = _("Movie identifiers (install at least one of these):\n\n%(program_list)s\n") % {"program_list" : text} + text += _("\t%(program_name)s (installed)\n") % { + "program_name": e.display_name} + text1 = _("Movie identifiers (install at least one of these):\n\n%(program_list)s\n") % { + "program_list": text} text = "" for e in players: if players_i.count(e.display_name) == 0: - text += _("\t%(program_name)s (not installed)\n") % {"program_name": e.display_name} + text += _("\t%(program_name)s (not installed)\n") % { + "program_name": e.display_name} else: - text += _("\t%(program_name)s (installed)\n") % {"program_name": e.display_name} - text2 = _("Movie players (install at least one of these):\n\n%(program_list)s\n") % {"program_list" : text} + text += _("\t%(program_name)s (installed)\n") % { + "program_name": e.display_name} + text2 = _("Movie players (install at least one of these):\n\n%(program_list)s\n") % { + "program_list": text} text = "" for e in converters: @@ -172,49 +181,64 @@ class choose_disc_type(GObject.GObject): sup += ", " sup += s if converters_i.count(e.display_name) == 0: - text += _("\t%(program_name)s (not installed)\n") % {"program_name": e.display_name + " ("+sup+")"} + text += _("\t%(program_name)s (not installed)\n") % { + "program_name": e.display_name + " (" + sup + ")"} else: - text += _("\t%(program_name)s (installed)\n") % {"program_name": e.display_name + " ("+sup+")"} - text3 = _("Movie Converters (install at least one of these):\n\n%(program_list)s\n") % {"program_list" : text} + text += _("\t%(program_name)s (installed)\n") % { + "program_name": e.display_name + " (" + sup + ")"} + text3 = _("Movie Converters (install at least one of these):\n\n%(program_list)s\n") % { + "program_list": text} text = "" for e in burners: if burners_i.count(e.display_name) == 0: - text += _("\t%(program_name)s (not installed)\n") % {"program_name": e.display_name} + text += _("\t%(program_name)s (not installed)\n") % { + "program_name": e.display_name} else: - text += _("\t%(program_name)s (installed)\n") % {"program_name": e.display_name} - text4 = _("CD/DVD burners (install at least one of these):\n\n%(program_list)s\n") % {"program_list" : text} + text += _("\t%(program_name)s (installed)\n") % { + "program_name": e.display_name} + text4 = _( + "CD/DVD burners (install at least one of these):\n\n%(program_list)s\n") % {"program_list": text} text = "" for e in mkiso: if mkiso_i.count(e.display_name) == 0: - text += _("\t%(program_name)s (not installed)\n") % {"program_name": e.display_name} + text += _("\t%(program_name)s (not installed)\n") % { + "program_name": e.display_name} else: - text += _("\t%(program_name)s (installed)\n") % {"program_name": e.display_name} - text5 = _("ISO creators (install at least one of these):\n\n%(program_list)s\n") % {"program_list" : text} + text += _("\t%(program_name)s (installed)\n") % { + "program_name": e.display_name} + text5 = _("ISO creators (install at least one of these):\n\n%(program_list)s\n") % { + "program_list": text} text = "" - if self.check_program(["dvdauthor","--help"]) == False: - text += _("\t%(program_name)s (not installed)\n") % {"program_name": "DVDAUTHOR (dvd)"} + if self.check_program(["dvdauthor", "--help"]) == False: + text += _("\t%(program_name)s (not installed)\n") % { + "program_name": "DVDAUTHOR (dvd)"} else: - text += _("\t%(program_name)s (installed)\n") % {"program_name": "DVDAUTHOR (dvd)"} - if self.check_program(["vcdimager","--help"]) == False: - text += _("\t%(program_name)s (not installed)\n") % {"program_name": "VCDIMAGER (vcd, svcd, cvd)"} + text += _("\t%(program_name)s (installed)\n") % { + "program_name": "DVDAUTHOR (dvd)"} + if self.check_program(["vcdimager", "--help"]) == False: + text += _("\t%(program_name)s (not installed)\n") % { + "program_name": "VCDIMAGER (vcd, svcd, cvd)"} else: - text += _("\t%(program_name)s (installed)\n") % {"program_name": "VCDIMAGER (vcd, svcd, cvd)"} - if self.check_program(["spumux" , "--help"]) == False: - text += _("\t%(program_name)s (not installed)\n") % {"program_name": "SPUMUX (dvd, vcd, svcd, cvd)"} + text += _("\t%(program_name)s (installed)\n") % { + "program_name": "VCDIMAGER (vcd, svcd, cvd)"} + if self.check_program(["spumux", "--help"]) == False: + text += _("\t%(program_name)s (not installed)\n") % { + "program_name": "SPUMUX (dvd, vcd, svcd, cvd)"} else: - text += _("\t%(program_name)s (installed)\n") % {"program_name": "SPUMUX (dvd, vcd, svcd, cvd)"} + text += _("\t%(program_name)s (installed)\n") % { + "program_name": "SPUMUX (dvd, vcd, svcd, cvd)"} - text6 = _("Other programs:\n\n%(program_list)s\n") % {"program_list" : text} + text6 = _("Other programs:\n\n%(program_list)s\n") % { + "program_list": text} - final_text = text1+text2+text3+text4+text5+text6 - textbuf.insert_at_cursor(final_text,len(final_text)) + final_text = text1 + text2 + text3 + text4 + text5 + text6 + textbuf.insert_at_cursor(final_text, len(final_text)) window.run() window.destroy() - - def on_wselect_disk_destroy_event(self,w,b): + def on_wselect_disk_destroy_event(self, w, b): Gtk.main_quit() diff --git a/src/devedeng/configuration_data.py b/src/devedeng/configuration_data.py index d52a00e..a94ca9a 100644 --- a/src/devedeng/configuration_data.py +++ b/src/devedeng/configuration_data.py @@ -21,10 +21,11 @@ from gi.repository import GObject import os import pkg_resources + class configuration(GObject.GObject): current_configuration = None - __gsignals__ = {'disc_type': (GObject.SIGNAL_RUN_FIRST, None,(str,))} + __gsignals__ = {'disc_type': (GObject.SIGNAL_RUN_FIRST, None, (str,))} @staticmethod def get_config(): @@ -37,12 +38,12 @@ class configuration(GObject.GObject): def __init__(self): GObject.GObject.__init__(self) self.version = str(pkg_resources.require("devedeng")[0].version) - print("Version: "+self.version) + print("Version: " + self.version) def fill_config(self): self.cores = 0 - proc_file = open("/proc/cpuinfo","r") + proc_file = open("/proc/cpuinfo", "r") for line in proc_file: if (line.startswith("processor")): self.cores += 1 @@ -70,20 +71,21 @@ class configuration(GObject.GObject): return True else: if (is_local): - # locales must be always at /usr/share/locale because Gtk.Builder always search there - self.share_locale="/usr/share/locale" - self.glade="/usr/local/share/devedeng" - self.font_path="/usr/local/share/devedeng" - self.pic_path="/usr/local/share/devedeng" - self.other_path="/usr/local/share/devedeng" - self.help_path="/usr/local/share/doc/devedeng" + # locales must be always at /usr/share/locale because + # Gtk.Builder always search there + self.share_locale = "/usr/share/locale" + self.glade = "/usr/local/share/devedeng" + self.font_path = "/usr/local/share/devedeng" + self.pic_path = "/usr/local/share/devedeng" + self.other_path = "/usr/local/share/devedeng" + self.help_path = "/usr/local/share/doc/devedeng" else: - self.share_locale="/usr/share/locale" - self.glade="/usr/share/devedeng" - self.font_path="/usr/share/devedeng" - self.pic_path="/usr/share/devedeng" - self.other_path="/usr/share/devedeng" - self.help_path="/usr/share/doc/devedeng" + self.share_locale = "/usr/share/locale" + self.glade = "/usr/share/devedeng" + self.font_path = "/usr/share/devedeng" + self.pic_path = "/usr/share/devedeng" + self.other_path = "/usr/share/devedeng" + self.help_path = "/usr/share/doc/devedeng" self.gettext_domain = "devedeng" @@ -102,67 +104,69 @@ class configuration(GObject.GObject): self.sub_codepage = None self.burner = None self.mkiso = None - self.subt_fill_color = (1,1,1,1) - self.subt_outline_color = (0,0,0,1) + self.subt_fill_color = (1, 1, 1, 1) + self.subt_outline_color = (0, 0, 0, 1) self.subt_outline_thickness = 0.0 - config_path = os.path.join(os.environ.get("HOME"),".devedeng") + config_path = os.path.join(os.environ.get("HOME"), ".devedeng") try: - config_data = open(config_path,"r") + config_data = open(config_path, "r") for linea in config_data: linea = linea.strip() if linea == "": continue if linea[0] == "#": continue - if linea[:13]=="video_format:": - if linea[13:].strip() =="pal": - self.PAL=True - elif linea[13:].strip()=="ntsc": - self.PAL=False + if linea[:13] == "video_format:": + if linea[13:].strip() == "pal": + self.PAL = True + elif linea[13:].strip() == "ntsc": + self.PAL = False continue - if linea[:12]=="temp_folder:": - self.tmp_folder=linea[12:].strip() + if linea[:12] == "temp_folder:": + self.tmp_folder = linea[12:].strip() continue - if linea[:10]=="multicore:": + if linea[:10] == "multicore:": self.multicore = int(linea[10:].strip()) continue - if linea[:13]=="final_folder:": - self.final_folder=linea[13:].strip() + if linea[:13] == "final_folder:": + self.final_folder = linea[13:].strip() continue - if linea[:13]=="sub_language:": - self.sub_language=linea[13:].strip() + if linea[:13] == "sub_language:": + self.sub_language = linea[13:].strip() continue - if linea[:13]=="sub_codepage:": - self.sub_codepage=linea[13:].strip() + if linea[:13] == "sub_codepage:": + self.sub_codepage = linea[13:].strip() continue - if linea[:14]=="film_analizer:": + if linea[:14] == "film_analizer:": self.film_analizer = linea[14:].strip() continue - if linea[:12]=="film_player:": + if linea[:12] == "film_player:": self.film_player = linea[12:].strip() continue - if linea[:15]=="film_converter:": + if linea[:15] == "film_converter:": self.film_converter = linea[15:].strip() continue - if linea[:15]=="menu_converter:": + if linea[:15] == "menu_converter:": self.menu_converter = linea[15:].strip() continue - if linea[:7]=="burner:": + if linea[:7] == "burner:": self.burner = linea[7:].strip() continue - if linea[:6]=="mkiso:": + if linea[:6] == "mkiso:": self.mkiso = linea[6:].strip() continue - if linea[:19]=="subtitle_font_size:": + if linea[:19] == "subtitle_font_size:": self.subtitles_font_size = int(linea[19:].strip()) continue if linea[:20] == "subtitle_fill_color:": c = linea[20:].strip().split(",") - self.subt_fill_color = (float(c[0]), float(c[1]), float(c[2]), 1.0) + self.subt_fill_color = ( + float(c[0]), float(c[1]), float(c[2]), 1.0) if linea[:23] == "subtitle_outline_color:": c = linea[23:].strip().split(",") - self.subt_outline_color = (float(c[0]), float(c[1]), float(c[2]), 1.0) + self.subt_outline_color = ( + float(c[0]), float(c[1]), float(c[2]), 1.0) if linea[:27] == "subtitle_outilne_thickness:": self.subt_outline_thickness = float(linea[27:].strip()) config_data.close() @@ -171,69 +175,78 @@ class configuration(GObject.GObject): return False - - def set_disc_type(self,disc_type): + def set_disc_type(self, disc_type): self.disc_type = disc_type self.clear_static_log() self.clear_log() - self.emit('disc_type',disc_type) - + self.emit('disc_type', disc_type) def save_config(self): - config_path = os.path.join(os.environ.get("HOME"),".devedeng") + config_path = os.path.join(os.environ.get("HOME"), ".devedeng") try: - config_data = open(config_path,"w") + config_data = open(config_path, "w") config_data.write("video_format:") if (self.PAL): config_data.write("pal\n") else: config_data.write("ntsc\n") if (self.tmp_folder is not None): - config_data.write("temp_folder:"+str(self.tmp_folder)+"\n") - config_data.write("multicore:"+str(self.multicore)+"\n") + config_data.write("temp_folder:" + str(self.tmp_folder) + "\n") + config_data.write("multicore:" + str(self.multicore) + "\n") if (self.final_folder is not None): - config_data.write("final_folder:"+str(self.final_folder)+"\n") + config_data.write("final_folder:" + + str(self.final_folder) + "\n") if (self.sub_language is not None): - config_data.write("sub_language:"+str(self.sub_language)+"\n") + config_data.write("sub_language:" + + str(self.sub_language) + "\n") if (self.sub_codepage is not None): - config_data.write("sub_codepage:"+str(self.sub_codepage)+"\n") + config_data.write("sub_codepage:" + + str(self.sub_codepage) + "\n") if (self.film_analizer is not None): - config_data.write("film_analizer:"+str(self.film_analizer)+"\n") + config_data.write("film_analizer:" + + str(self.film_analizer) + "\n") if (self.film_player is not None): - config_data.write("film_player:"+str(self.film_player)+"\n") + config_data.write( + "film_player:" + str(self.film_player) + "\n") if (self.film_converter is not None): - config_data.write("film_converter:"+str(self.film_converter)+"\n") + config_data.write("film_converter:" + + str(self.film_converter) + "\n") if (self.menu_converter is not None): - config_data.write("menu_converter:"+str(self.menu_converter)+"\n") + config_data.write("menu_converter:" + + str(self.menu_converter) + "\n") if self.burner is not None: - config_data.write("burner:"+str(self.burner)+"\n") + config_data.write("burner:" + str(self.burner) + "\n") if self.mkiso is not None: - config_data.write("mkiso:"+str(self.mkiso)+"\n") + config_data.write("mkiso:" + str(self.mkiso) + "\n") if (self.sub_codepage is not None): - config_data.write("sub_codepage:"+str(self.sub_codepage)+"\n") + config_data.write("sub_codepage:" + + str(self.sub_codepage) + "\n") if (self.sub_language is not None): - config_data.write("sub_language:"+str(self.sub_language)+"\n") - config_data.write("subtitle_font_size:"+str(self.subtitles_font_size)+"\n") - config_data.write("subtitle_fill_color:"+str(self.subt_fill_color[0])+","+str(self.subt_fill_color[1])+","+str(self.subt_fill_color[2])+"\n") - config_data.write("subtitle_outline_color:"+str(self.subt_outline_color[0])+","+str(self.subt_outline_color[1])+","+str(self.subt_outline_color[2])+"\n") - config_data.write("subtitle_outilne_thickness:"+str(self.subt_outline_thickness)) + config_data.write("sub_language:" + + str(self.sub_language) + "\n") + config_data.write("subtitle_font_size:" + + str(self.subtitles_font_size) + "\n") + config_data.write("subtitle_fill_color:" + str(self.subt_fill_color[0]) + "," + str( + self.subt_fill_color[1]) + "," + str(self.subt_fill_color[2]) + "\n") + config_data.write("subtitle_outline_color:" + str(self.subt_outline_color[0]) + "," + str( + self.subt_outline_color[1]) + "," + str(self.subt_outline_color[2]) + "\n") + config_data.write("subtitle_outilne_thickness:" + + str(self.subt_outline_thickness)) config_data.close() except: pass - - def append_log(self,data,cr = True): + def append_log(self, data, cr=True): self.log += data if (cr): self.log += "\n" - - def append_static_log(self,data,cr = True): - + def append_static_log(self, data, cr=True): + self.static_log += data if (cr): self.static_log += "\n" @@ -243,7 +256,7 @@ class configuration(GObject.GObject): self.log = "" def clear_static_log(self): - + self.static_log = "" def get_log(self): diff --git a/src/devedeng/converter.py b/src/devedeng/converter.py index ec1ea09..b37cc77 100644 --- a/src/devedeng/converter.py +++ b/src/devedeng/converter.py @@ -28,6 +28,7 @@ import devedeng.mkisofs import devedeng.genisoimage import devedeng.mpv + class converter: current_converter = None @@ -38,7 +39,6 @@ class converter: converter.current_converter = converter() return converter.current_converter - def __init__(self): self.config = devedeng.configuration_data.configuration.get_config() @@ -92,7 +92,6 @@ class converter: if (self.default_burner is None): self.default_burner = element - def get_supported_programs(self): analizers = [] @@ -118,7 +117,6 @@ class converter: return (analizers, players, menuers, converters, burners, mkiso) - def get_available_programs(self): players = [] @@ -143,7 +141,6 @@ class converter: return (analizers, players, menuers, converters, burners, mkiso) - def get_needed_programs(self): """ returns a tupla with six lists. When a list is NONE, there are installed in the system programs that covers the needs for that group; when not, it contains the programs valid @@ -192,7 +189,7 @@ class converter: if (e.supports_mkiso) and (mkiso is not None): mkiso.append(name) - return ( analizers, players, converters, menuers, burners, mkiso ) + return (analizers, players, converters, menuers, burners, mkiso) def get_film_player(self): """ returns a class for the desired film player, or the most priviledged if the desired is not installed """ @@ -221,19 +218,21 @@ class converter: def get_disc_converter(self): """ returns a class for the desired disc converter, or the most priviledged if the desired is not installed """ - # if there is a film converter chosen by the user, and it is installed in the system + # if there is a film converter chosen by the user, and it is installed + # in the system if (self.config.film_converter is not None) and (self.config.film_converter in self.converters): # and that converter supports the current disc type if self.converters[self.config.film_converter].disc_types.count(self.config.disc_type) != 0: # return that converter return self.converters[self.config.film_converter] - # if not, return the first available converter that supports the current disc type + # if not, return the first available converter that supports the + # current disc type for converter in self.converters: if self.converters[converter].disc_types.count(self.config.disc_type) != 0: return self.converters[converter] return None - def get_disc_converter_by_name(self,name): + def get_disc_converter_by_name(self, name): if name in self.converters: return self.converters[name] return None diff --git a/src/devedeng/create_disk_window.py b/src/devedeng/create_disk_window.py index 460e5ed..83feb41 100644 --- a/src/devedeng/create_disk_window.py +++ b/src/devedeng/create_disk_window.py @@ -19,6 +19,7 @@ from gi.repository import Gtk import os import devedeng.configuration_data + class create_disk_window: def __init__(self): @@ -30,7 +31,7 @@ class create_disk_window: builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wcreate.ui")) + builder.add_from_file(os.path.join(self.config.glade, "wcreate.ui")) builder.connect_signals(self) wcreate_window = builder.get_object("dialog_create") self.wpath = builder.get_object("path") @@ -45,7 +46,7 @@ class create_disk_window: self.on_iface_changed(None) retval = wcreate_window.run() self.name = self.wname.get_text() - self.path = os.path.join(self.wpath.get_filename(),self.name) + self.path = os.path.join(self.wpath.get_filename(), self.name) self.shutdown = wshutdown.get_active() if (retval == 1): @@ -57,12 +58,12 @@ class create_disk_window: return True else: return False - - def on_iface_changed(self,b): - + + def on_iface_changed(self, b): + path = self.wpath.get_filename() name = self.wname.get_text() - + if ((path is None) or (path == "") or (name is None) or (name == "")): self.waccept.set_sensitive(False) else: diff --git a/src/devedeng/dvd_menu.py b/src/devedeng/dvd_menu.py index 3372808..fdda9e2 100644 --- a/src/devedeng/dvd_menu.py +++ b/src/devedeng/dvd_menu.py @@ -16,13 +16,14 @@ # along with this program. If not, see import cairo -from gi.repository import Gtk,Gdk,GdkPixbuf +from gi.repository import Gtk, Gdk, GdkPixbuf import os import devedeng.configuration_data import devedeng.interface_manager import devedeng.message import devedeng.mux_dvd_menu + class dvd_menu(devedeng.interface_manager.interface_manager): def __init__(self): @@ -33,20 +34,26 @@ class dvd_menu(devedeng.interface_manager.interface_manager): devedeng.interface_manager.interface_manager.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - self.default_background = os.path.join(self.config.pic_path,"backgrounds","default_bg.png") - self.default_sound = os.path.join(self.config.pic_path,"silence.ogg") + self.default_background = os.path.join( + self.config.pic_path, "backgrounds", "default_bg.png") + self.default_sound = os.path.join(self.config.pic_path, "silence.ogg") - self.add_colorbutton("title_color", (0,0,0,1), self.update_preview) - self.add_colorbutton("title_shadow", (0,0,0,0), self.update_preview) - self.add_colorbutton("unselected_color", (1,1,1,1), self.update_preview) - self.add_colorbutton("shadow_color", (0,0,0,0), self.update_preview) - self.add_colorbutton("selected_color", (0,1,1,1), self.update_preview) - self.add_colorbutton("background_color", (0,0,0,0.75), self.update_preview) + self.add_colorbutton("title_color", (0, 0, 0, 1), self.update_preview) + self.add_colorbutton("title_shadow", (0, 0, 0, 0), self.update_preview) + self.add_colorbutton("unselected_color", + (1, 1, 1, 1), self.update_preview) + self.add_colorbutton("shadow_color", (0, 0, 0, 0), self.update_preview) + self.add_colorbutton( + "selected_color", (0, 1, 1, 1), self.update_preview) + self.add_colorbutton("background_color", + (0, 0, 0, 0.75), self.update_preview) self.add_text("title_text", None, self.update_preview) - self.add_group("position_horizontal", ["left", "center", "right"], "center", self.update_preview) - self.add_group("at_startup", ["menu_show_at_startup", "play_first_title_at_startup"], "menu_show_at_startup") + self.add_group("position_horizontal", [ + "left", "center", "right"], "center", self.update_preview) + self.add_group("at_startup", [ + "menu_show_at_startup", "play_first_title_at_startup"], "menu_show_at_startup") self.add_toggle("play_all_c", False, self.update_preview) self.add_integer_adjustment("sound_length", 30) @@ -63,61 +70,62 @@ class dvd_menu(devedeng.interface_manager.interface_manager): self.add_fontbutton("title_font", "Sans 28", self.update_preview) self.add_fontbutton("entry_font", "Sans 28", self.update_preview) - self.add_filebutton("background_picture", self.default_background, self.update_preview) - self.add_filebutton("background_music", self.default_sound, self.update_music) + self.add_filebutton("background_picture", + self.default_background, self.update_preview) + self.add_filebutton("background_music", + self.default_sound, self.update_music) self.cached_menu_font = None self.cached_menu_size = 0 self.video_rate = 2500 self.audio_rate = 224 - def on_help_clicked(self,b): + def on_help_clicked(self, b): help_file = devedeng.help.help("menu.html") def get_estimated_size(self): - estimated_size = ((self.video_rate + self.audio_rate) * self.sound_length) / 8 + estimated_size = ((self.video_rate + self.audio_rate) + * self.sound_length) / 8 return estimated_size - - def update_music(self,b=None): + def update_music(self, b=None): self.store_ui(self.builder) cv = devedeng.converter.converter.get_converter() film_analizer = (cv.get_film_analizer())() - (video, audio, length) = film_analizer.analize_film_data(self.background_music,True) + (video, audio, length) = film_analizer.analize_film_data( + self.background_music, True) if (video != 0): - devedeng.message.message_window(_("The selected file is a video, not an audio file"),_("Error")) + devedeng.message.message_window( + _("The selected file is a video, not an audio file"), _("Error")) self.on_no_sound_clicked(None) elif (audio == 0): - devedeng.message.message_window(_("The selected file is not an audio file"),_("Error")) + devedeng.message.message_window( + _("The selected file is not an audio file"), _("Error")) self.on_no_sound_clicked(None) else: self.sound_length = length - - def update_preview(self,b=None): + def update_preview(self, b=None): self.store_ui(self.builder) - self.sf = None # force to repaint the menu + self.sf = None # force to repaint the menu self.wdrawing_area.queue_draw() - - def on_default_background_clicked(self,b): + def on_default_background_clicked(self, b): self.background_picture = self.default_background self.update_ui(self.builder) self.update_preview() - - def on_no_sound_clicked(self,b): + def on_no_sound_clicked(self, b): self.background_music = self.default_sound self.sound_length = 30 self.update_ui(self.builder) - def show_configuration(self, file_list): self.builder = Gtk.Builder() @@ -126,39 +134,41 @@ class dvd_menu(devedeng.interface_manager.interface_manager): self.refresh_static_data() - self.builder.add_from_file(os.path.join(self.config.glade,"wmenu.ui")) + self.builder.add_from_file(os.path.join(self.config.glade, "wmenu.ui")) self.builder.connect_signals(self) self.wframe_preview = self.builder.get_object("frame_preview") - self.wframe_preview_controls = self.builder.get_object("frame_preview_controls") + self.wframe_preview_controls = self.builder.get_object( + "frame_preview_controls") self.wmenu = self.builder.get_object("menu") self.wpreview_menu = self.builder.get_object("preview_menu") self.wdrawing_area = self.builder.get_object("drawingarea_preview") self.wcurrent_page = self.builder.get_object("current_page") self.wshow_as_selected = self.builder.get_object("show_as_selected") - self.wshow_as_selected.connect("toggled",self.update_preview) + self.wshow_as_selected.connect("toggled", self.update_preview) - self.wbackground_picture = self.builder.get_object("background_picture") + self.wbackground_picture = self.builder.get_object( + "background_picture") self.wbackground_music = self.builder.get_object("background_music") - file_filter_pictures=Gtk.FileFilter() + file_filter_pictures = Gtk.FileFilter() file_filter_pictures.set_name(_("Picture files")) file_filter_pictures.add_mime_type("image/*") - file_filter_all=Gtk.FileFilter() + file_filter_all = Gtk.FileFilter() file_filter_all.set_name(_("All files")) file_filter_all.add_pattern("*") self.wbackground_picture.add_filter(file_filter_pictures) self.wbackground_picture.add_filter(file_filter_all) - file_filter_music=Gtk.FileFilter() + file_filter_music = Gtk.FileFilter() file_filter_music.set_name(_("Sound files")) file_filter_music.add_mime_type("audio/*") - file_filter_all=Gtk.FileFilter() + file_filter_all = Gtk.FileFilter() file_filter_all.set_name(_("All files")) file_filter_all.add_pattern("*") @@ -171,87 +181,83 @@ class dvd_menu(devedeng.interface_manager.interface_manager): self.update_ui(self.builder) self.save_ui() - - def on_accept_clicked(self,b): + def on_accept_clicked(self, b): self.store_ui(self.builder) self.wmenu.destroy() - - def on_cancel_clicked(self,b): + def on_cancel_clicked(self, b): self.restore_ui() self.wmenu.destroy() + def get_font_params(self, font_name): - def get_font_params(self,font_name): + font_elements = font_name.split(" ") - font_elements=font_name.split(" ") - - if (len(font_elements))<2: - fontname="Sans" - fontstyle=cairo.FONT_WEIGHT_NORMAL - fontslant=cairo.FONT_SLANT_NORMAL - fontsize=12 + if (len(font_elements)) < 2: + fontname = "Sans" + fontstyle = cairo.FONT_WEIGHT_NORMAL + fontslant = cairo.FONT_SLANT_NORMAL + fontsize = 12 else: - fontname="" - fontstyle=cairo.FONT_WEIGHT_NORMAL - fontslant=cairo.FONT_SLANT_NORMAL - for counter2 in range(len(font_elements)-1): - if font_elements[counter2]=="Bold": - fontstyle=cairo.FONT_WEIGHT_BOLD - elif font_elements[counter2]=="Italic": - fontslant=cairo.FONT_SLANT_ITALIC + fontname = "" + fontstyle = cairo.FONT_WEIGHT_NORMAL + fontslant = cairo.FONT_SLANT_NORMAL + for counter2 in range(len(font_elements) - 1): + if font_elements[counter2] == "Bold": + fontstyle = cairo.FONT_WEIGHT_BOLD + elif font_elements[counter2] == "Italic": + fontslant = cairo.FONT_SLANT_ITALIC else: - fontname+=" "+font_elements[counter2] - if fontname!="": - fontname=fontname[1:] + fontname += " " + font_elements[counter2] + if fontname != "": + fontname = fontname[1:] else: - fontname="Sans" + fontname = "Sans" try: - fontsize=float(font_elements[-1]) + fontsize = float(font_elements[-1]) except: - fontsize=12 + fontsize = 12 - return fontname,fontstyle,fontslant,fontsize + return fontname, fontstyle, fontslant, fontsize - - def paint_arrow(self,xl,xr,y,arrow_type,left): + def paint_arrow(self, xl, xr, y, arrow_type, left): if arrow_type == "menu_entry": fgcolor = self.unselected_color elif arrow_type == "menu_entry_selected": fgcolor = self.selected_color elif arrow_type == "menu_entry_activated": - fgcolor = ( 1.0 - self.selected_color[0], 1.0 - self.selected_color[1], 1.0 - self.selected_color[2], self.selected_color[3]) + fgcolor = (1.0 - self.selected_color[0], 1.0 - self.selected_color[ + 1], 1.0 - self.selected_color[2], self.selected_color[3]) else: return - fo=cairo.FontOptions() + fo = cairo.FontOptions() fo.set_antialias(cairo.ANTIALIAS_NONE) self.cr.set_font_options(fo) self.cr.set_antialias(cairo.ANTIALIAS_NONE) x = (xl + xr) / 2.0 h = (self.cached_menu_size / 2.0) - 1.0 - self.cr.set_source_rgba(fgcolor[0],fgcolor[1],fgcolor[2],fgcolor[3]) - self.cr.move_to(x,y-h) + self.cr.set_source_rgba(fgcolor[0], fgcolor[1], fgcolor[2], fgcolor[3]) + self.cr.move_to(x, y - h) if (left): - self.cr.line_to(x-self.cached_menu_size+2,y) + self.cr.line_to(x - self.cached_menu_size + 2, y) else: - self.cr.line_to(x+self.cached_menu_size-2,y) - self.cr.line_to(x,y+h) - self.cr.line_to(x,y-h) + self.cr.line_to(x + self.cached_menu_size - 2, y) + self.cr.line_to(x, y + h) + self.cr.line_to(x, y - h) self.cr.fill() - fo=cairo.FontOptions() + fo = cairo.FontOptions() fo.set_antialias(cairo.ANTIALIAS_DEFAULT) self.cr.set_font_options(fo) self.cr.set_antialias(cairo.ANTIALIAS_DEFAULT) - - def write_text(self,text,text_type,xl,xr,y,alignment): + def write_text(self, text, text_type, xl, xr, y, alignment): """ Renders a line of text, in the rectangle delimited by xl,y-h;xr,y+h, with the specified alignment """ if text is None: @@ -273,7 +279,8 @@ class dvd_menu(devedeng.interface_manager.interface_manager): hard_borders = True font = self.entry_font elif text_type == "menu_entry_activated": - fgcolor = ( 1.0 - self.selected_color[0], 1.0 - self.selected_color[1], 1.0 - self.selected_color[2], self.selected_color[3]) + fgcolor = (1.0 - self.selected_color[0], 1.0 - self.selected_color[ + 1], 1.0 - self.selected_color[2], self.selected_color[3]) bgcolor = None hard_borders = True font = self.entry_font @@ -281,13 +288,13 @@ class dvd_menu(devedeng.interface_manager.interface_manager): return if hard_borders: - fo=cairo.FontOptions() + fo = cairo.FontOptions() fo.set_antialias(cairo.ANTIALIAS_NONE) self.cr.set_font_options(fo) self.cr.set_antialias(cairo.ANTIALIAS_NONE) (fontname, fontstyle, fontslant, fontsize) = self.get_font_params(font) - self.cr.select_font_face(fontname,fontslant, fontstyle) + self.cr.select_font_face(fontname, fontslant, fontstyle) self.cr.set_font_size(fontsize) extents = self.cr.text_extents(text) @@ -299,73 +306,77 @@ class dvd_menu(devedeng.interface_manager.interface_manager): x = ((xl + xr) / 2.0) - (extents[2] / 2.0) if (bgcolor is not None): - self.cr.move_to(x+extents[0]+2,y-(extents[3]/2.0)-extents[1]+2) - self.cr.set_source_rgba(bgcolor[0],bgcolor[1],bgcolor[2],bgcolor[3]) + self.cr.move_to(x + extents[0] + 2, y - + (extents[3] / 2.0) - extents[1] + 2) + self.cr.set_source_rgba( + bgcolor[0], bgcolor[1], bgcolor[2], bgcolor[3]) self.cr.show_text(text) - self.cr.move_to(x+extents[0],y-(extents[3]/2.0)-extents[1]) - self.cr.set_source_rgba(fgcolor[0],fgcolor[1],fgcolor[2],fgcolor[3]) + self.cr.move_to(x + extents[0], y - (extents[3] / 2.0) - extents[1]) + self.cr.set_source_rgba(fgcolor[0], fgcolor[1], fgcolor[2], fgcolor[3]) self.cr.show_text(text) if hard_borders: - fo=cairo.FontOptions() + fo = cairo.FontOptions() fo.set_antialias(cairo.ANTIALIAS_DEFAULT) self.cr.set_font_options(fo) self.cr.set_antialias(cairo.ANTIALIAS_DEFAULT) - def refresh_static_data(self): """ This method sets data that can't be changed from the dvd settings window. It must be called before painting a menu """ if self.config.PAL: - self.y=576.0 + self.y = 576.0 else: - self.y=480.0 + self.y = 480.0 self.title_list = [] counter = 0 for element in self.file_list: if element.show_in_menu: - self.title_list.append( (element, counter) ) + self.title_list.append((element, counter)) counter += 1 self.sf = None self.current_shown_page = 0 self.wcurrent_page = None - - def paint_menu(self,paint_background, paint_selected, paint_activated, page_number): + def paint_menu(self, paint_background, paint_selected, paint_activated, page_number): coordinates = [] if self.sf is None: - self.sf=cairo.ImageSurface(cairo.FORMAT_ARGB32,720,int(self.y)) - self.cr=cairo.Context(self.sf) + self.sf = cairo.ImageSurface(cairo.FORMAT_ARGB32, 720, int(self.y)) + self.cr = cairo.Context(self.sf) if self.cached_menu_font != self.entry_font: # memorize the font sizes - (fontname, fontstyle, fontslant, fontsize) = self.get_font_params(self.entry_font) - self.cr.select_font_face(fontname,fontslant, fontstyle) + (fontname, fontstyle, fontslant, + fontsize) = self.get_font_params(self.entry_font) + self.cr.select_font_face(fontname, fontslant, fontstyle) self.cr.set_font_size(fontsize) extents = self.cr.font_extents() self.cached_menu_size = extents[2] self.cached_menu_font = self.entry_font if paint_background: - extra_pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.background_picture) + extra_pixbuf = GdkPixbuf.Pixbuf.new_from_file( + self.background_picture) extra_x = float(extra_pixbuf.get_width()) extra_y = float(extra_pixbuf.get_height()) self.cr.save() - self.cr.scale(720.0/extra_x,self.y/extra_y) + self.cr.scale(720.0 / extra_x, self.y / extra_y) - surface = Gdk.cairo_surface_create_from_pixbuf(extra_pixbuf,1,None) - self.cr.set_source_surface(surface,0,0) + surface = Gdk.cairo_surface_create_from_pixbuf( + extra_pixbuf, 1, None) + self.cr.set_source_surface(surface, 0, 0) self.cr.paint() self.cr.restore() hmargin = self.title_horizontal * 720.0 / 100.0 - self.write_text(self.title_text, "title", 0 + hmargin, 720 + hmargin, self.title_vertical * self.y / 100.0, "center") + self.write_text(self.title_text, "title", 0 + hmargin, 720 + + hmargin, self.title_vertical * self.y / 100.0, "center") # else: # self.cr.set_source_rgb(1.0,1.0,1.0) # self.cr.paint() @@ -375,8 +386,10 @@ class dvd_menu(devedeng.interface_manager.interface_manager): left_margin_p = 720.0 * self.margin_left / 100.0 right_margin_p = 720.0 * self.margin_right / 100.0 - entry_height = self.cached_menu_size + self.entry_vertical_margin * 2.0 + self.entry_separation - entries_per_page = int((self.y - top_margin_p - bottom_margin_p) / entry_height) + entry_height = self.cached_menu_size + \ + self.entry_vertical_margin * 2.0 + self.entry_separation + entries_per_page = int( + (self.y - top_margin_p - bottom_margin_p) / entry_height) if (self.play_all_c): entries_per_page -= 1 n_entries = len(self.title_list) @@ -393,38 +406,45 @@ class dvd_menu(devedeng.interface_manager.interface_manager): page_number -= 1 if self.wcurrent_page is not None: - self.wcurrent_page.set_text(_("Page %(X)d of %(Y)d") % {"X":page_number+1 , "Y":self.pages}) + self.wcurrent_page.set_text(_("Page %(X)d of %(Y)d") % { + "X": page_number + 1, "Y": self.pages}) xl = left_margin_p xr = 720.0 - right_margin_p - y = top_margin_p + entry_height/2.0 + y = top_margin_p + entry_height / 2.0 height = (self.cached_menu_size + self.entry_vertical_margin) / 2.0 - + if (self.play_all_c): - coordinates.append([xl, y-height, xr, y+height, "play_all"]) + coordinates.append([xl, y - height, xr, y + height, "play_all"]) if paint_background: self.paint_base(xl, xr, y, 0) - self.write_text("Play All", "menu_entry", xl, xr, y, self.position_horizontal) + self.write_text("Play All", "menu_entry", xl, + xr, y, self.position_horizontal) if paint_selected: - self.write_text("Play All", "menu_entry_selected", xl, xr, y, self.position_horizontal) + self.write_text("Play All", "menu_entry_selected", + xl, xr, y, self.position_horizontal) if paint_activated: - self.write_text("Play All", "menu_entry_activated", xl, xr, y, self.position_horizontal) + self.write_text("Play All", "menu_entry_activated", + xl, xr, y, self.position_horizontal) y += entry_height - - for entry in self.title_list[page_number*entries_per_page:(page_number+1)*entries_per_page]: - coordinates.append([xl, y-height, xr, y+height, "entry"]) + + for entry in self.title_list[page_number * entries_per_page:(page_number + 1) * entries_per_page]: + coordinates.append([xl, y - height, xr, y + height, "entry"]) text = entry[0].title_name if paint_background: self.paint_base(xl, xr, y, 0) - self.write_text(text, "menu_entry", xl, xr, y, self.position_horizontal) + self.write_text(text, "menu_entry", xl, xr, + y, self.position_horizontal) if paint_selected: - self.write_text(text, "menu_entry_selected", xl, xr, y, self.position_horizontal) + self.write_text(text, "menu_entry_selected", xl, + xr, y, self.position_horizontal) if paint_activated: - self.write_text(text, "menu_entry_activated", xl, xr, y, self.position_horizontal) + self.write_text(text, "menu_entry_activated", + xl, xr, y, self.position_horizontal) y += entry_height if paint_arrows: if page_number == 0: - coordinates.append([xl, y-height, xr, y+height, "right"]) + coordinates.append([xl, y - height, xr, y + height, "right"]) if paint_background: self.paint_base(xl, xr, y, 0) self.paint_arrow(xl, xr, y, "menu_entry", False) @@ -433,7 +453,7 @@ class dvd_menu(devedeng.interface_manager.interface_manager): if paint_activated: self.paint_arrow(xl, xr, y, "menu_entry_activated", False) elif page_number == (self.pages - 1): - coordinates.append([xl, y-height, xr, y+height, "left"]) + coordinates.append([xl, y - height, xr, y + height, "left"]) if paint_background: self.paint_base(xl, xr, y, 0) self.paint_arrow(xl, xr, y, "menu_entry", True) @@ -443,8 +463,8 @@ class dvd_menu(devedeng.interface_manager.interface_manager): self.paint_arrow(xl, xr, y, "menu_entry_activated", True) else: med = (xl + xr) / 2.0 - coordinates.append([xl, y-height, med, y+height, "left"]) - coordinates.append([med, y-height, xr, y+height, "right"]) + coordinates.append([xl, y - height, med, y + height, "left"]) + coordinates.append([med, y - height, xr, y + height, "right"]) if paint_background: self.paint_base(xl, xr, y, 1) self.paint_base(xl, xr, y, 2) @@ -458,74 +478,75 @@ class dvd_menu(devedeng.interface_manager.interface_manager): self.paint_arrow(xl, med, y, "menu_entry_activated", True) return coordinates - - def paint_base(self,xl, xr, y, type_b): + def paint_base(self, xl, xr, y, type_b): height = self.cached_menu_size + self.entry_vertical_margin radius = (height) / 2.0 y -= radius - if (type_b == 1): # half button, at left - xr = (xl+xr) / 2.0 + if (type_b == 1): # half button, at left + xr = (xl + xr) / 2.0 xr -= radius - elif (type_b == 2): # half button, at right - xl = (xl+xr) / 2.0 + elif (type_b == 2): # half button, at right + xl = (xl + xr) / 2.0 xl += radius - self.cr.set_source_rgba(self.background_color[0],self.background_color[1],self.background_color[2],self.background_color[3]) - self.cr.move_to(xl,y) - self.cr.line_to(xr,y) - self.cr.curve_to(xr+radius,y,xr+radius,y+height,xr,y+height) - self.cr.line_to(xl,y+height) - self.cr.curve_to(xl-radius,y+height,xl-radius,y,xl,y) + self.cr.set_source_rgba(self.background_color[0], self.background_color[ + 1], self.background_color[2], self.background_color[3]) + self.cr.move_to(xl, y) + self.cr.line_to(xr, y) + self.cr.curve_to(xr + radius, y, xr + radius, + y + height, xr, y + height) + self.cr.line_to(xl, y + height) + self.cr.curve_to(xl - radius, y + height, xl - radius, y, xl, y) self.cr.fill() - - def on_next_page_clicked(self,b): + def on_next_page_clicked(self, b): self.current_shown_page += 1 if (self.current_shown_page == self.pages): self.current_shown_page -= 1 self.update_preview() - - def on_previous_page_clicked(self,b): + def on_previous_page_clicked(self, b): self.current_shown_page -= 1 if (self.current_shown_page < 0): self.current_shown_page = 0 self.update_preview() - - def on_drawingarea_preview_draw(self,widget,cr): - + def on_drawingarea_preview_draw(self, widget, cr): """ Callback to repaint the menu preview window when it sends the EXPOSE event """ if (self.sf is None): - self.paint_menu(True, self.wshow_as_selected.get_active(), False, self.current_shown_page) + self.paint_menu(True, self.wshow_as_selected.get_active( + ), False, self.current_shown_page) if (self.current_shown_page >= self.pages): self.current_shown_page = self.pages cr.set_source_surface(self.sf) cr.paint() - - def create_menu_stream(self,path,n_page,coordinates): - + def create_menu_stream(self, path, n_page, coordinates): """ Creates the menu XML file """ - file_name = os.path.join(path,"menu_"+str(n_page)+".xml") + file_name = os.path.join(path, "menu_" + str(n_page) + ".xml") entry_data = {} entry_data["chapters"] = [] entry_data["right"] = None entry_data["left"] = None - xml_file=open(file_name,"w") - xml_file.write('\n\t\n\t\t\n\t\n\t\t\n') n_elements = 0 has_next = False @@ -558,30 +579,36 @@ class dvd_menu(devedeng.interface_manager.interface_manager): yb -= 1 if (element[4] == "left"): - entry_data["left"] = "boton"+str(n_page)+"x"+str(counter) + entry_data["left"] = "boton" + str(n_page) + "x" + str(counter) elif (element[4] == "right"): - entry_data["right"] = "boton"+str(n_page)+"x"+str(counter) + entry_data["right"] = "boton" + \ + str(n_page) + "x" + str(counter) else: - entry_data["chapters"].append("boton"+str(n_page)+"x"+str(counter)) + entry_data["chapters"].append( + "boton" + str(n_page) + "x" + str(counter)) - xml_file.write('\t\t\t\n') counter += 1 @@ -590,13 +617,12 @@ class dvd_menu(devedeng.interface_manager.interface_manager): return entry_data - def create_dvd_menus(self, file_list, base_path): self.file_list = file_list self.refresh_static_data() cv = devedeng.converter.converter.get_converter() - menu_folder = os.path.join(base_path,"menu") + menu_folder = os.path.join(base_path, "menu") try: os.makedirs(menu_folder) except: @@ -609,33 +635,37 @@ class dvd_menu(devedeng.interface_manager.interface_manager): while n_page < self.pages: self.sf = None coordinates = self.paint_menu(True, False, False, n_page) - self.sf.write_to_png(os.path.join(menu_folder,"menu_"+str(n_page)+"_bg.png")) + self.sf.write_to_png(os.path.join( + menu_folder, "menu_" + str(n_page) + "_bg.png")) self.sf = None self.paint_menu(False, False, False, n_page) - self.sf.write_to_png(os.path.join(menu_folder,"menu_"+str(n_page)+"_unselected_bg.png")) + self.sf.write_to_png(os.path.join( + menu_folder, "menu_" + str(n_page) + "_unselected_bg.png")) self.sf = None self.paint_menu(False, True, False, n_page) - self.sf.write_to_png(os.path.join(menu_folder,"menu_"+str(n_page)+"_selected_bg.png")) + self.sf.write_to_png(os.path.join( + menu_folder, "menu_" + str(n_page) + "_selected_bg.png")) self.sf = None self.paint_menu(False, False, True, n_page) - self.sf.write_to_png(os.path.join(menu_folder,"menu_"+str(n_page)+"_active_bg.png")) - entry_data = self.create_menu_stream(menu_folder, n_page, coordinates) + self.sf.write_to_png(os.path.join( + menu_folder, "menu_" + str(n_page) + "_active_bg.png")) + entry_data = self.create_menu_stream( + menu_folder, n_page, coordinates) converter = menu_converter() - final_path = converter.create_menu_mpeg(n_page,self.background_music,self.sound_length,self.config.PAL,self.video_rate,self.audio_rate,menu_folder, self.audio_mp2) + final_path = converter.create_menu_mpeg( + n_page, self.background_music, self.sound_length, self.config.PAL, self.video_rate, self.audio_rate, menu_folder, self.audio_mp2) entry_data["filename"] = final_path menu_entries.append(entry_data) # add this process without dependencies processes.append(converter) n_page += 1 - return processes,menu_entries - + return processes, menu_entries def store_menu(self): return self.serialize() - - def restore_menu(self,data): + def restore_menu(self, data): self.unserialize(data) diff --git a/src/devedeng/dvdauthor_converter.py b/src/devedeng/dvdauthor_converter.py index 13e5df3..bbc8026 100644 --- a/src/devedeng/dvdauthor_converter.py +++ b/src/devedeng/dvdauthor_converter.py @@ -21,6 +21,7 @@ import os import devedeng.configuration_data import devedeng.executor + class dvdauthor_converter(devedeng.executor.executor): def __init__(self): @@ -28,18 +29,18 @@ class dvdauthor_converter(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() + def create_dvd_project(self, path, name, file_movies, menu_entries, start_with_menu, play_all_opt): - def create_dvd_project (self, path, name, file_movies, menu_entries, start_with_menu, play_all_opt): - - movie_path = os.path.join(path,"dvd_tree") + movie_path = os.path.join(path, "dvd_tree") try: os.makedirs(movie_path) except: pass - xml_file = self.create_dvdauthor_xml(path, file_movies, menu_entries, start_with_menu, play_all_opt) + xml_file = self.create_dvdauthor_xml( + path, file_movies, menu_entries, start_with_menu, play_all_opt) - self.command_var=[] + self.command_var = [] self.command_var.append("dvdauthor") self.command_var.append("-o") self.command_var.append(movie_path) @@ -48,22 +49,19 @@ class dvdauthor_converter(devedeng.executor.executor): self.use_pulse_mode = True self.text = _("Creating DVD structure") - - def process_stdout(self,data): + def process_stdout(self, data): return - - def process_stderr(self,data): + def process_stderr(self, data): if (data is not None) and (data[0] != ""): self.progress_bar[1].set_text(data[0]) return + def create_dvdauthor_xml(self, movie_folder, file_movies, menu_entries, start_with_menu, play_all_opt): - def create_dvdauthor_xml(self,movie_folder, file_movies, menu_entries, start_with_menu, play_all_opt): - - xmlpath = os.path.join(movie_folder,"xml_data") - xml_file_path = os.path.join(xmlpath,"dvdauthor.xml") - datapath = os.path.join(movie_folder,"dvd_tree") + xmlpath = os.path.join(movie_folder, "xml_data") + xml_file_path = os.path.join(xmlpath, "dvdauthor.xml") + datapath = os.path.join(movie_folder, "dvd_tree") try: os.makedirs(xmlpath) except: @@ -79,8 +77,8 @@ class dvdauthor_converter(devedeng.executor.executor): else: elements_per_menu = len(menu_entries[0]["chapters"]) - xml_file=open(xml_file_path,"w") - xml_file.write('\n') + xml_file = open(xml_file_path, "w") + xml_file.write('\n') if onlyone: xml_file.write('\t\n') @@ -100,25 +98,25 @@ class dvdauthor_converter(devedeng.executor.executor): # MENU # in the FPC we do a jump to the first menu in the first titleset if we wanted MENU - # or we jump to the second titleset if we didn't want MENU at startup + # or we jump to the second titleset if we didn't want MENU at + # startup xml_file.write('\t\t\n') xml_file.write('\t\t\tg0=100;\n') - xml_file.write('\t\t\tg1=') #goto variable + xml_file.write('\t\t\tg1=') # goto variable if (menu_entries is not None) and (start_with_menu): - xml_file.write('0;\n') #show menu + xml_file.write('0;\n') # show menu else: - xml_file.write('100;\n') #auto play - xml_file.write('\t\t\tg2=1024;\n') #highlight? - xml_file.write('\t\t\tg3=') #play all variable + xml_file.write('100;\n') # auto play + xml_file.write('\t\t\tg2=1024;\n') # highlight? + xml_file.write('\t\t\tg3=') # play all variable if play_all_opt and (menu_entries is not None) and (start_with_menu): - xml_file.write('1;\n') #auto play all + xml_file.write('1;\n') # auto play all else: - xml_file.write('0;\n') #do not play all + xml_file.write('0;\n') # do not play all xml_file.write('\t\t\tjump menu 1;\n') xml_file.write('\t\t\n') - # in the VMGM menu we create a code to jump to the title specified in G0 # but if the title is 100, we jump to the menus. There we show the menu number # contained in G1 @@ -135,24 +133,28 @@ class dvdauthor_converter(devedeng.executor.executor): xml_file.write('\t\t\t\n') xml_file.write('\t\t\t\t
\n')
 
-            counter=1
+            counter = 1
             for element in file_movies:
-                xml_file.write('\t\t\t\t\tif (g0 eq '+str(counter)+') {\n')
-                xml_file.write('\t\t\t\t\t\tjump titleset '+str(1+counter)+' menu;\n')
+                xml_file.write('\t\t\t\t\tif (g0 eq ' + str(counter) + ') {\n')
+                xml_file.write('\t\t\t\t\t\tjump titleset ' +
+                               str(1 + counter) + ' menu;\n')
                 xml_file.write('\t\t\t\t\t}\n')
-                counter+=1
+                counter += 1
             xml_file.write('\t\t\t\t\tif (g0 eq 100) {\n')
             xml_file.write('\t\t\t\t\t\tg2=1024;\n')
             xml_file.write('\t\t\t\t\t\tjump titleset 1 menu;\n')
             xml_file.write('\t\t\t\t\t}\n')
             xml_file.write('\t\t\t\t
\n') - # fake video (one black picture with one second of sound) to ensure 100% compatibility + # fake video (one black picture with one second of sound) to ensure + # 100% compatibility xml_file.write('\t\t\t\t\n') xml_file.write('\t\t\t
\n') @@ -161,8 +163,8 @@ class dvdauthor_converter(devedeng.executor.executor): xml_file.write("\n") - - # the first titleset contains all the menus. G1 allows us to jump to the desired menu + # the first titleset contains all the menus. G1 allows us to jump + # to the desired menu xml_file.write('\t\n') xml_file.write('\t\t\n') @@ -185,23 +187,27 @@ class dvdauthor_converter(devedeng.executor.executor): if (menu_entries is not None): nmenues = len(menu_entries) - title_counter = 0 # A counter for all titles + title_counter = 0 # A counter for all titles for menu_page in menu_entries: - button_counter = 0 # A counter for all buttons on the actual page + button_counter = 0 # A counter for all buttons on the actual page xml_file.write('\t\t\t\n') xml_file.write('\t\t\t\t
\n')
-                    xml_file.write('\t\t\t\t\ts8=g2;\n') # first we recover the currently selected button
-                    xml_file.write('\t\t\t\t\tg3=0;\n') #turnoff play all
+                    # first we recover the currently selected button
+                    xml_file.write('\t\t\t\t\ts8=g2;\n')
+                    xml_file.write('\t\t\t\t\tg3=0;\n')  # turnoff play all
 
-                    if first_entry: # here we add some code to jump to each menu
-                        for menu2 in range(nmenues-1):
-                            xml_file.write('\t\t\t\t\tif (g1 eq '+str(menu2+1)+') {\n')
-                            xml_file.write('\t\t\t\t\t\tjump menu '+str(menu2+2)+';\n')
+                    if first_entry:  # here we add some code to jump to each menu
+                        for menu2 in range(nmenues - 1):
+                            xml_file.write(
+                                '\t\t\t\t\tif (g1 eq ' + str(menu2 + 1) + ') {\n')
+                            xml_file.write(
+                                '\t\t\t\t\t\tjump menu ' + str(menu2 + 2) + ';\n')
                             xml_file.write('\t\t\t\t\t}\n')
 
                         # this code is to fix a bug in some players
                         xml_file.write('\t\t\t\t\tif (g1 eq 100) {\n')
-                        xml_file.write('\t\t\t\t\t\tjump title 1;\n') #menu '+str(self.nmenues+1)+';\n')
+                        # menu '+str(self.nmenues+1)+';\n')
+                        xml_file.write('\t\t\t\t\t\tjump title 1;\n')
                         xml_file.write('\t\t\t\t\t}\n')
                     first_entry = False
 
@@ -213,38 +219,43 @@ class dvdauthor_converter(devedeng.executor.executor):
 
                     for nbutton in menu_page["chapters"]:
                         #xml_file.write('\t\t\t\t\n')
-                        xml_file.write('\t\t\t\t\n')
 
                     if (menu_page["left"] is not None):
-                        xml_file.write('\t\t\t\t\n')
 
                     if (menu_page["right"] is not None):
-                        xml_file.write('\t\t\t\t\n')
 
                     xml_file.write('\t\t\t\t\n')
                     xml_file.write('\t\t\t\t\tg2=s8;\n')
-                    xml_file.write('\t\t\t\t\tg1='+str(menu_number)+';\n')
-                    xml_file.write('\t\t\t\t\tjump menu '+str(menu_number+1)+';\n')
+                    xml_file.write('\t\t\t\t\tg1=' + str(menu_number) + ';\n')
+                    xml_file.write('\t\t\t\t\tjump menu ' +
+                                   str(menu_number + 1) + ';\n')
                     xml_file.write('\t\t\t\t\n')
                     xml_file.write('\t\t\t\n')
                     menu_number += 1
@@ -258,15 +269,18 @@ class dvdauthor_converter(devedeng.executor.executor):
 
                 # this code is to fix a bug in some players
                 xml_file.write('\t\t\t\t\tif (g1 eq 100) {\n')
-                xml_file.write('\t\t\t\t\t\tjump title 1;\n') #menu '+str(self.nmenues+1)+';\n')
+                # menu '+str(self.nmenues+1)+';\n')
+                xml_file.write('\t\t\t\t\t\tjump title 1;\n')
                 xml_file.write('\t\t\t\t\t}\n')
 
                 xml_file.write('\t\t\t\t
\n') xml_file.write('\t\t\t\t\n') xml_file.write('\t\t\t\t\n') @@ -288,9 +302,11 @@ class dvdauthor_converter(devedeng.executor.executor): xml_file.write('\t\t\t\n') xml_file.write('\t\t\t\t\n') xml_file.write('\t\t\t\t\n') xml_file.write('\t\t\t\t\tg0=1;\n') @@ -304,57 +320,58 @@ class dvdauthor_converter(devedeng.executor.executor): xml_file.write("\n") - # Now, create the titleset for each video - total_t=len(file_movies) - titleset=1 - titles=0 - counter=0 + total_t = len(file_movies) + titleset = 1 + titles = 0 + counter = 0 for element in file_movies: - files=0 - action=element.actions + files = 0 + action = element.actions xml_file.write("\n") if element.is_mpeg_ps: - # if it's already an MPEG-2 compliant file, we use the original values + # if it's already an MPEG-2 compliant file, we use the original + # values if element.original_fps == 25: - pal_ntsc="pal" - ispal=True + pal_ntsc = "pal" + ispal = True else: - pal_ntsc="ntsc" - ispal=False + pal_ntsc = "ntsc" + ispal = False if element.original_aspect_ratio > 1.6: - faspect='16:9' - fwide=True + faspect = '16:9' + fwide = True else: - faspect='4:3' - fwide=False + faspect = '4:3' + fwide = False else: # but if we are converting it, we use the desired values if element.format_pal: - pal_ntsc="pal" - ispal=True + pal_ntsc = "pal" + ispal = True else: - pal_ntsc="ntsc" - ispal=False + pal_ntsc = "ntsc" + ispal = False if element.aspect_ratio_final > 1.6: - faspect='16:9' - fwide=True + faspect = '16:9' + fwide = True else: - faspect='4:3' - fwide=False + faspect = '4:3' + fwide = False xml_file.write("\t\n") if not onlyone: xml_file.write("\t\t\n") - xml_file.write('\t\t\t\n') @@ -365,15 +382,18 @@ class dvdauthor_converter(devedeng.executor.executor): xml_file.write('\t\t\t\t\t\tjump vmgm menu entry title;\n') xml_file.write('\t\t\t\t\t}\n') xml_file.write('\t\t\t\t\tg0=100;\n') - xml_file.write('\t\t\t\t\tg1='+str(int(titles/elements_per_menu))+';\n') + xml_file.write('\t\t\t\t\tg1=' + + str(int(titles / elements_per_menu)) + ';\n') xml_file.write('\t\t\t\t\tjump title 1;\n') xml_file.write('\t\t\t\t\n') # fake video to ensure compatibility xml_file.write('\t\t\t\t\n') @@ -381,7 +401,8 @@ class dvdauthor_converter(devedeng.executor.executor): xml_file.write("\t\t\n") xml_file.write("\t\t\n") - xml_file.write('\t\t\t\n') @@ -396,75 +417,83 @@ class dvdauthor_converter(devedeng.executor.executor): # xml_file.write('\t\t\t\t\tsubtitle=64;\n') # xml_file.write('\t\t\t\t\n') - xml_file.write('\t\t\t\t\n') if not onlyone: xml_file.write('\t\t\t\t\n') - files+=1 - xml_file.write('\t\t\t\t\tg1='+str(int(titles/elements_per_menu))+';\n') + files += 1 + xml_file.write('\t\t\t\t\tg1=' + + str(int(titles / elements_per_menu)) + ';\n') - #play all - xml_file.write('\t\t\t\t\tif (g3 eq 1) {\n') #if play all: - if titles==total_t-1: #return to menu if last title + # play all + xml_file.write('\t\t\t\t\tif (g3 eq 1) {\n') # if play all: + if titles == total_t - 1: # return to menu if last title xml_file.write('\t\t\t\t\t\tg0=100;\n') - else: #play next title - xml_file.write('\t\t\t\t\t\tg0='+str(titles + 2)+';\n') + else: # play next title + xml_file.write('\t\t\t\t\t\tg0=' + str(titles + 2) + ';\n') xml_file.write('\t\t\t\t\t} else {\n') - #end of play opt + # end of play opt xml_file.write('\t\t\t\t\t\tg0=') - if action=="action_stop": + if action == "action_stop": xml_file.write('100') - elif action=="action_play_previous": + elif action == "action_play_previous": if titles == 0: prev_t = total_t - 1 else: prev_t = titles - 1 xml_file.write(str(prev_t + 1)) - elif action=="action_play_again": + elif action == "action_play_again": xml_file.write(str(titles + 1)) - elif action=="action_play_next": - if titles==total_t-1: - next_t=0 + elif action == "action_play_next": + if titles == total_t - 1: + next_t = 0 else: - next_t=titles + 1 + next_t = titles + 1 xml_file.write(str(next_t + 1)) - elif action=="action_play_last": + elif action == "action_play_last": xml_file.write(str(total_t)) else: - xml_file.write('1') # first + xml_file.write('1') # first xml_file.write(';\n') xml_file.write('\t\t\t\t\t}\n') - xml_file.write('\t\t\t\t\tcall vmgm menu entry title;\n') #preform action + # preform action + xml_file.write('\t\t\t\t\tcall vmgm menu entry title;\n') xml_file.write('\t\t\t\t\n') xml_file.write("\t\t\t\n") xml_file.write("\t\t\n") xml_file.write("\t
\n") - counter+=1 - titles+=1 + counter += 1 + titles += 1 xml_file.write("
") @@ -472,34 +501,32 @@ class dvdauthor_converter(devedeng.executor.executor): return xml_file_path - - def return_time(self,seconds,empty): - + def return_time(self, seconds, empty): """ cuts a time in seconds into seconds, minutes and hours """ - seconds2=int(seconds) + seconds2 = int(seconds) - hours=str(int(seconds2/3600)) + hours = str(int(seconds2 / 3600)) if empty: - if len(hours)==1: - hours="0"+hours + if len(hours) == 1: + hours = "0" + hours else: - if hours=="0": - hours="" - if hours!="": - hours+=":" + if hours == "0": + hours = "" + if hours != "": + hours += ":" - minutes=str(int((seconds2/60)%60)) - if empty or (hours!=""): - if len(minutes)==1: - minutes="0"+minutes - elif (minutes=="0") and (hours==""): - minutes="" - if minutes!="": - minutes+=":" + minutes = str(int((seconds2 / 60) % 60)) + if empty or (hours != ""): + if len(minutes) == 1: + minutes = "0" + minutes + elif (minutes == "0") and (hours == ""): + minutes = "" + if minutes != "": + minutes += ":" - secs=str(int(seconds2%60)) - if (len(secs)==1) and (minutes!=""): - secs="0"+secs + secs = str(int(seconds2 % 60)) + if (len(secs) == 1) and (minutes != ""): + secs = "0" + secs - return hours+minutes+secs + return hours + minutes + secs diff --git a/src/devedeng/end_job.py b/src/devedeng/end_job.py index 0132647..be00799 100644 --- a/src/devedeng/end_job.py +++ b/src/devedeng/end_job.py @@ -15,22 +15,23 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from gi.repository import Gtk,Gdk +from gi.repository import Gtk, Gdk import os import devedeng.configuration_data + class end_window: def __init__(self): self.config = devedeng.configuration_data.configuration.get_config() - def run(self,time_used, do_burn): + def run(self, time_used, do_burn): builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wdone.ui")) + builder.add_from_file(os.path.join(self.config.glade, "wdone.ui")) builder.connect_signals(self) werror_window = builder.get_object("done") wburn = builder.get_object("button_burn") @@ -43,10 +44,10 @@ class end_window: time_used_str = "" if hours < 10: time_used_str += "0" - time_used_str += str(hours)+":" + time_used_str += str(hours) + ":" if minutes < 10: time_used_str += "0" - time_used_str += str(minutes)+":" + time_used_str += str(minutes) + ":" if seconds < 10: time_used_str += "0" time_used_str += str(seconds) @@ -62,14 +63,13 @@ class end_window: retval = werror_window.run() werror_window.destroy() if retval == 1: - return True # burn disc image + return True # burn disc image else: return False - - def on_copy_clicked(self,b): + def on_copy_clicked(self, b): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) - data =self.config.get_log() - clipboard.set_text(data,len(data)) + data = self.config.get_log() + clipboard.set_text(data, len(data)) return diff --git a/src/devedeng/error.py b/src/devedeng/error.py index cc23c81..56d9054 100644 --- a/src/devedeng/error.py +++ b/src/devedeng/error.py @@ -15,10 +15,11 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from gi.repository import Gtk,Gdk +from gi.repository import Gtk, Gdk import os import devedeng.configuration_data + class error_window: def __init__(self): @@ -28,7 +29,7 @@ class error_window: builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"werror.ui")) + builder.add_from_file(os.path.join(self.config.glade, "werror.ui")) builder.connect_signals(self) werror_window = builder.get_object("dialog_error") wdebug_buffer = builder.get_object("debug_buffer") @@ -38,10 +39,9 @@ class error_window: werror_window.run() werror_window.destroy() - - def on_copy_clicked(self,b): + def on_copy_clicked(self, b): clipboard = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) - data =self.config.get_log() - clipboard.set_text(data,len(data)) + data = self.config.get_log() + clipboard.set_text(data, len(data)) return diff --git a/src/devedeng/executor.py b/src/devedeng/executor.py index c6b8db3..ebefe3f 100644 --- a/src/devedeng/executor.py +++ b/src/devedeng/executor.py @@ -17,16 +17,17 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from gi.repository import GLib,GObject +from gi.repository import GLib, GObject import subprocess import os import signal import devedeng.configuration_data + class executor(GObject.GObject): """ This class encapsulates everything needed for launching processes """ - __gsignals__ = {'ended': (GObject.SIGNAL_RUN_FIRST, None,(int,))} + __gsignals__ = {'ended': (GObject.SIGNAL_RUN_FIRST, None, (int,))} def __init__(self): @@ -51,7 +52,6 @@ class executor(GObject.GObject): self.pulse_text = None self.handle = None - def add_dependency(self, dep): self.add_dependency2(dep) @@ -59,7 +59,6 @@ class executor(GObject.GObject): for child in dep.childs: self.add_dependency2(child) - def add_dependency2(self, dep): if (self.dependencies is None): @@ -68,12 +67,12 @@ class executor(GObject.GObject): if (self.dependencies.count(dep) == 0): self.dependencies.append(dep) - # the childs have the same dependencies than the parent process because, from outside, it is viewed as a single process + # the childs have the same dependencies than the parent process + # because, from outside, it is viewed as a single process for child in self.childs: child.add_dependency(dep) - - def remove_dependency(self,process): + def remove_dependency(self, process): # dependencies are removed only in the parent because the running class have all the processes, parents and childs, and calls # this method on all of them if (self.dependencies is not None): @@ -86,10 +85,10 @@ class executor(GObject.GObject): else: self.dependencies = None + def add_child_process(self, child): - def add_child_process(self,child): - - # the childs have the same dependencies than the parent process because, from outside, it is viewed as a single process + # the childs have the same dependencies than the parent process + # because, from outside, it is viewed as a single process if self.dependencies is not None: for dep in self.dependencies: child.add_dependency(dep) @@ -97,7 +96,6 @@ class executor(GObject.GObject): if (self.childs.count(child) == 0): self.childs.append(child) - def run(self, progress_bar): self.progress_bar = progress_bar @@ -113,40 +111,38 @@ class executor(GObject.GObject): if self.use_pulse_mode != self.pulse_mode: self.set_pulse_mode(self.use_pulse_mode) + def remove_ansi(self, line): - def remove_ansi(self,line): - - output="" + output = "" while True: - pos=line.find("\033[") # try with double-byte ESC - jump=2 - if pos==-1: - pos=line.find("\233") # if not, try with single-byte ESC - jump=1 - if pos==-1: # no ANSI characters; we ended - output+=line + pos = line.find("\033[") # try with double-byte ESC + jump = 2 + if pos == -1: + pos = line.find("\233") # if not, try with single-byte ESC + jump = 1 + if pos == -1: # no ANSI characters; we ended + output += line break - output+=line[:pos] - line=line[pos+jump:] + output += line[:pos] + line = line[pos + jump:] while True: - if len(line)==0: + if len(line) == 0: break - if (ord(line[0])<64) or (ord(line[0])>126): - line=line[1:] + if (ord(line[0]) < 64) or (ord(line[0]) > 126): + line = line[1:] else: - line=line[1:] + line = line[1:] break return output - - def launch_process(self,command,redirect_output = True): + def launch_process(self, command, redirect_output=True): if command is not None: self.launch_command = "\n\nLaunching:" for e in command: - self.launch_command += (" "+e) + self.launch_command += (" " + e) self.launch_command += "\n" self.config.append_log(self.text) @@ -155,12 +151,15 @@ class executor(GObject.GObject): try: if (self.stdin_file is not None): - self.handle = subprocess.Popen(command,stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE) + self.handle = subprocess.Popen( + command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) self.channel_stdin = GLib.IOChannel(self.handle.stdin.fileno()) - self.channel_stdin.add_watch(GLib.IO_OUT | GLib.IO_HUP, self.read_stdin_from_file) - self.file_in = open(self.stdin_file,"rb") + self.channel_stdin.add_watch( + GLib.IO_OUT | GLib.IO_HUP, self.read_stdin_from_file) + self.file_in = open(self.stdin_file, "rb") else: - self.handle = subprocess.Popen(command,stdout = subprocess.PIPE, stderr = subprocess.PIPE) + self.handle = subprocess.Popen( + command, stdout=subprocess.PIPE, stderr=subprocess.PIPE) except Exception as error_launch: self.handle = None self.stderr_data += str(error_launch) @@ -173,11 +172,14 @@ class executor(GObject.GObject): self.channel_stdout = GLib.IOChannel(self.handle.stdout.fileno()) self.channel_stderr = GLib.IOChannel(self.handle.stderr.fileno()) if (self.stdout_file is not None): - self.channel_stdout.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stdout_to_file) - self.file_out = open(self.stdout_file,"wb") + self.channel_stdout.add_watch( + GLib.IO_IN | GLib.IO_HUP, self.read_stdout_to_file) + self.file_out = open(self.stdout_file, "wb") else: - self.channel_stdout.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stdout) - self.channel_stderr.add_watch(GLib.IO_IN | GLib.IO_HUP,self.read_stderr) + self.channel_stdout.add_watch( + GLib.IO_IN | GLib.IO_HUP, self.read_stdout) + self.channel_stderr.add_watch( + GLib.IO_IN | GLib.IO_HUP, self.read_stderr) else: (stdout_r, stderr_r) = self.handle.communicate() self.handle = None @@ -192,8 +194,7 @@ class executor(GObject.GObject): self.config.append_log(stderr_r.decode("latin-1")) return (stdout_r, stderr_r) - - def set_pulse_mode(self,pulse_mode): + def set_pulse_mode(self, pulse_mode): if pulse_mode == self.pulse_mode: return @@ -205,8 +206,7 @@ class executor(GObject.GObject): else: GLib.source_remove(self.timer_pulse) - - def run_pulse(self,v = None): + def run_pulse(self, v=None): if self.progress_bar is None: return @@ -216,8 +216,7 @@ class executor(GObject.GObject): self.progress_bar[1].pulse() return True - - def read_stdout_to_file(self,source,condition): + def read_stdout_to_file(self, source, condition): if (condition != GLib.IO_IN): self.channel_stdout = None @@ -229,8 +228,7 @@ class executor(GObject.GObject): self.file_out.write(line_data) return True - - def read_stdin_from_file(self,source,condition): + def read_stdin_from_file(self, source, condition): line_data = self.file_in.read1(4096) if (len(line_data) == 0): @@ -243,8 +241,7 @@ class executor(GObject.GObject): self.handle.stdin.write(line_data) return True - - def read_stdout(self,source,condition): + def read_stdout(self, source, condition): if (condition != GLib.IO_IN): self.channel_stdout = None @@ -254,11 +251,11 @@ class executor(GObject.GObject): else: read_data = self.handle.stdout.read1(4096) try: - line_data = self.stdout_buf+(read_data.decode("utf-8")) + line_data = self.stdout_buf + (read_data.decode("utf-8")) except: - line_data = self.stdout_buf+(read_data.decode("latin-1")) + line_data = self.stdout_buf + (read_data.decode("latin-1")) self.stdout_data += line_data - data = (line_data).replace("\r","\n").split("\n") + data = (line_data).replace("\r", "\n").split("\n") if (len(data) == 1): final_data = [] self.stdout_buf = data[0] @@ -269,8 +266,7 @@ class executor(GObject.GObject): self.process_stdout(final_data) return True - - def read_stderr(self,source,condition): + def read_stderr(self, source, condition): if (condition != GLib.IO_IN): self.channel_stderr = None @@ -280,11 +276,11 @@ class executor(GObject.GObject): else: read_data = self.handle.stderr.read1(4096) try: - line_data = self.stderr_buf+(read_data.decode("utf-8")) + line_data = self.stderr_buf + (read_data.decode("utf-8")) except: - line_data = self.stderr_buf+(read_data.decode("latin-1")) + line_data = self.stderr_buf + (read_data.decode("latin-1")) self.stderr_data += line_data - data = (line_data).replace("\r","\n").split("\n") + data = (line_data).replace("\r", "\n").split("\n") if (len(data) == 1): final_data = [] self.stderr_buf = data[0] @@ -295,17 +291,14 @@ class executor(GObject.GObject): self.process_stderr(final_data) return True - def cancel(self): - """ Called to kill this process. """ if self.handle is None: return self.killed = True - os.kill(self.handle.pid,signal.SIGKILL) - + os.kill(self.handle.pid, signal.SIGKILL) def wait_end(self): @@ -319,7 +312,7 @@ class executor(GObject.GObject): # call, if it exists, the post-function try: - self.post_function(retval,self.killed) + self.post_function(retval, self.killed) except: pass @@ -329,20 +322,18 @@ class executor(GObject.GObject): self.config.append_log(self.stdout_data) self.config.append_log(self.stderr_data) - self.emit("ended",retval) + self.emit("ended", retval) + def expand_xml(self, text): - def expand_xml(self,text): - - text=text.replace('&','&') - text=text.replace('<','<') - text=text.replace('>','>') - text=text.replace('"','"') - text=text.replace("'",''') + text = text.replace('&', '&') + text = text.replace('<', '<') + text = text.replace('>', '>') + text = text.replace('"', '"') + text = text.replace("'", ''') return text - - def get_division(self,data): + def get_division(self, data): pos = data.find("/") pos2 = data.find(":") @@ -358,16 +349,15 @@ class executor(GObject.GObject): else: try: data1 = float(data[:pos]) - data2 = float(data[pos+1:]) + data2 = float(data[pos + 1:]) except: return 0 if (data2 == 0): return 0 else: - return (float(int((data1 / data2)*1000.0)))/1000.0 + return (float(int((data1 / data2) * 1000.0))) / 1000.0 - - def get_time(self,line): + def get_time(self, line): time_string = "" diff --git a/src/devedeng/ffmpeg.py b/src/devedeng/ffmpeg.py index 34b963a..f0c7f75 100644 --- a/src/devedeng/ffmpeg.py +++ b/src/devedeng/ffmpeg.py @@ -24,528 +24,543 @@ import devedeng.executor import devedeng.mux_dvd_menu import devedeng.project + class ffmpeg(devedeng.executor.executor): - supports_analize = False - supports_play = False - supports_convert = True - supports_menu = True - supports_mkiso = False - supports_burn = False - display_name = "FFMPEG" - disc_types = [] + supports_analize = False + supports_play = False + supports_convert = True + supports_menu = True + supports_mkiso = False + supports_burn = False + display_name = "FFMPEG" + disc_types = [] - @staticmethod - def check_is_installed(): - try: - handle = subprocess.Popen(["ffmpeg","-codecs"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) - (stdout, stderr) = handle.communicate() - if 0==handle.wait(): - mp2 = False - mp3 = False - ac3 = False - mpeg1 = False - mpeg2 = False - divx = False - h264 = False - for line in stdout.decode("latin-1").split("\n"): - parts = line.strip().split(" ") - if len(parts) < 2: - continue - if len(parts[0]) != 6: - continue - capabilities = parts[0] - codec = parts[1] + @staticmethod + def check_is_installed(): + try: + handle = subprocess.Popen( + ["ffmpeg", "-codecs"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + (stdout, stderr) = handle.communicate() + if 0 == handle.wait(): + mp2 = False + mp3 = False + ac3 = False + mpeg1 = False + mpeg2 = False + divx = False + h264 = False + for line in stdout.decode("latin-1").split("\n"): + parts = line.strip().split(" ") + if len(parts) < 2: + continue + if len(parts[0]) != 6: + continue + capabilities = parts[0] + codec = parts[1] - if capabilities[1] != 'E': - continue + if capabilities[1] != 'E': + continue - if (codec == "mpeg1video"): - mpeg1 = True - continue - if (codec == "mpeg2video"): - mpeg2 = True - continue - if (codec == "mp2"): - mp2 = True - continue - if (codec == "mp3"): - mp3 = True - continue - if (codec == "ac3"): - ac3 = True - continue - if (codec == "h264") or (codec == "H264"): - h264 = True - continue - if (codec == "mpeg4"): - divx = True - continue + if (codec == "mpeg1video"): + mpeg1 = True + continue + if (codec == "mpeg2video"): + mpeg2 = True + continue + if (codec == "mp2"): + mp2 = True + continue + if (codec == "mp3"): + mp3 = True + continue + if (codec == "ac3"): + ac3 = True + continue + if (codec == "h264") or (codec == "H264"): + h264 = True + continue + if (codec == "mpeg4"): + divx = True + continue - if (mpeg1 and mp2): - devedeng.ffmpeg.ffmpeg.disc_types.append("vcd") - if (mpeg2 and mp2): - devedeng.ffmpeg.ffmpeg.disc_types.append("svcd") - devedeng.ffmpeg.ffmpeg.disc_types.append("cvd") - if (mpeg2 and mp2 and ac3): - devedeng.ffmpeg.ffmpeg.disc_types.append("dvd") - if (divx and mp3): - devedeng.ffmpeg.ffmpeg.disc_types.append("divx") - if (h264 and mp3): - devedeng.ffmpeg.ffmpeg.disc_types.append("mkv") + if (mpeg1 and mp2): + devedeng.ffmpeg.ffmpeg.disc_types.append("vcd") + if (mpeg2 and mp2): + devedeng.ffmpeg.ffmpeg.disc_types.append("svcd") + devedeng.ffmpeg.ffmpeg.disc_types.append("cvd") + if (mpeg2 and mp2 and ac3): + devedeng.ffmpeg.ffmpeg.disc_types.append("dvd") + if (divx and mp3): + devedeng.ffmpeg.ffmpeg.disc_types.append("divx") + if (h264 and mp3): + devedeng.ffmpeg.ffmpeg.disc_types.append("mkv") - return True - else: - return False - except: - return False + return True + else: + return False + except: + return False - def __init__(self): + def __init__(self): - devedeng.executor.executor.__init__(self) - self.config = devedeng.configuration_data.configuration.get_config() + devedeng.executor.executor.__init__(self) + self.config = devedeng.configuration_data.configuration.get_config() - def convert_file(self,file_project,output_file,video_length,pass2 = False): + def convert_file(self, file_project, output_file, video_length, pass2=False): - if file_project.two_pass_encoding: - if pass2: - self.text = _("Converting %(X)s (pass 2)") % {"X" : file_project.title_name} - else: - self.text = _("Converting %(X)s (pass 1)") % {"X" : file_project.title_name} - # Prepare the converting process for the second pass - tmp = devedeng.ffmpeg.ffmpeg() - tmp.convert_file(file_project, output_file, video_length, True) - # it deppends of this process - tmp.add_dependency(self) - # add it as a child process of this one - self.add_child_process(tmp) - else: - self.text = _("Converting %(X)s") % {"X" : file_project.title_name} + if file_project.two_pass_encoding: + if pass2: + self.text = _("Converting %(X)s (pass 2)") % { + "X": file_project.title_name} + else: + self.text = _("Converting %(X)s (pass 1)") % { + "X": file_project.title_name} + # Prepare the converting process for the second pass + tmp = devedeng.ffmpeg.ffmpeg() + tmp.convert_file(file_project, output_file, video_length, True) + # it deppends of this process + tmp.add_dependency(self) + # add it as a child process of this one + self.add_child_process(tmp) + else: + self.text = _("Converting %(X)s") % {"X": file_project.title_name} - if (pass2 == False) and (file_project.two_pass_encoding == True): - # this is the first pass in a 2-pass codification - second_pass = False - else: - # second_pass is TRUE in the second pass of a 2-pass codification, and also when not doing 2-pass codification - # It is used to remove unnecessary steps during the first pass, but that are needed on the second pass, or when not using 2-pass codification - second_pass = True + if (pass2 == False) and (file_project.two_pass_encoding == True): + # this is the first pass in a 2-pass codification + second_pass = False + else: + # second_pass is TRUE in the second pass of a 2-pass codification, and also when not doing 2-pass codification + # It is used to remove unnecessary steps during the first pass, but + # that are needed on the second pass, or when not using 2-pass + # codification + second_pass = True - if (video_length == 0): - self.final_length = file_project.original_length - else: - self.final_length = video_length - self.command_var=[] - self.command_var.append("ffmpeg") - self.command_var.append("-i") - self.command_var.append(file_project.file_name) + if (video_length == 0): + self.final_length = file_project.original_length + else: + self.final_length = video_length + self.command_var = [] + self.command_var.append("ffmpeg") + self.command_var.append("-i") + self.command_var.append(file_project.file_name) - if (file_project.volume!=100) and second_pass: - self.command_var.append("-vol") - self.command_var.append(str(int((256*file_project.volume)/100))) + if (file_project.volume != 100) and second_pass: + self.command_var.append("-vol") + self.command_var.append( + str(int((256 * file_project.volume) / 100))) - if (file_project.audio_delay != 0.0) and (file_project.copy_sound==False) and (file_project.no_reencode_audio_video==False) and second_pass: - self.command_var.append("-itsoffset") - self.command_var.append(str(file_project.audio_delay)) + if (file_project.audio_delay != 0.0) and (file_project.copy_sound == False) and (file_project.no_reencode_audio_video == False) and second_pass: + self.command_var.append("-itsoffset") + self.command_var.append(str(file_project.audio_delay)) - self.command_var.append("-i") - self.command_var.append(file_project.file_name) - self.command_var.append("-map") - self.command_var.append("1:"+str(file_project.video_list[0])) - if (not file_project.copy_sound) and (not file_project.no_reencode_audio_video): - for l in file_project.audio_list: - self.command_var.append("-map") - self.command_var.append("0:"+str(l)) + self.command_var.append("-i") + self.command_var.append(file_project.file_name) + self.command_var.append("-map") + self.command_var.append("1:" + str(file_project.video_list[0])) + if (not file_project.copy_sound) and (not file_project.no_reencode_audio_video): + for l in file_project.audio_list: + self.command_var.append("-map") + self.command_var.append("0:" + str(l)) - if (file_project.no_reencode_audio_video==False) and second_pass: - cmd_line="" + if (file_project.no_reencode_audio_video == False) and second_pass: + cmd_line = "" - if file_project.deinterlace=="deinterlace_yadif": - cmd_line+="yadif" + if file_project.deinterlace == "deinterlace_yadif": + cmd_line += "yadif" - vflip=False - hflip=False + vflip = False + hflip = False - if (file_project.rotation=="rotation_90"): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="transpose=1" - elif (file_project.rotation=="rotation_270"): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="transpose=2" - elif (file_project.rotation=="rotation_180"): - vflip=True - hflip=True + if (file_project.rotation == "rotation_90"): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "transpose=1" + elif (file_project.rotation == "rotation_270"): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "transpose=2" + elif (file_project.rotation == "rotation_180"): + vflip = True + hflip = True - if (file_project.mirror_vertical): - vflip=not vflip - if (file_project.mirror_horizontal): - hflip=not hflip + if (file_project.mirror_vertical): + vflip = not vflip + if (file_project.mirror_horizontal): + hflip = not hflip - if (vflip): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="vflip" - if (hflip): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="hflip" + if (vflip): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "vflip" + if (hflip): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "hflip" - if (file_project.width_midle != file_project.original_width) or (file_project.height_midle != file_project.original_height): - if (cmd_line!=""): - cmd_line+=",fifo," - x = int((file_project.width_midle - file_project.original_width) /2) - y = int((file_project.height_midle - file_project.original_height) /2) - if (x > 0) or (y > 0): - cmd_line+="pad="+str(file_project.width_midle)+":"+str(file_project.height_midle)+":"+str(x)+":"+str(y)+":0x000000" - else: - cmd_line+="crop="+str(file_project.width_midle)+":"+str(file_project.height_midle)+":"+str(x)+":"+str(y) + if (file_project.width_midle != file_project.original_width) or (file_project.height_midle != file_project.original_height): + if (cmd_line != ""): + cmd_line += ",fifo," + x = int((file_project.width_midle - + file_project.original_width) / 2) + y = int((file_project.height_midle - + file_project.original_height) / 2) + if (x > 0) or (y > 0): + cmd_line += "pad=" + str(file_project.width_midle) + ":" + str( + file_project.height_midle) + ":" + str(x) + ":" + str(y) + ":0x000000" + else: + cmd_line += "crop=" + str(file_project.width_midle) + ":" + str( + file_project.height_midle) + ":" + str(x) + ":" + str(y) - if (file_project.width_final != file_project.width_midle) or (file_project.height_final != file_project.height_midle): - if (cmd_line!=""): - cmd_line+=",fifo," - cmd_line+="scale="+str(file_project.width_final)+":"+str(file_project.height_final) + if (file_project.width_final != file_project.width_midle) or (file_project.height_final != file_project.height_midle): + if (cmd_line != ""): + cmd_line += ",fifo," + cmd_line += "scale=" + \ + str(file_project.width_final) + ":" + \ + str(file_project.height_final) - if cmd_line!="": - self.command_var.append("-vf") - self.command_var.append(cmd_line) + if cmd_line != "": + self.command_var.append("-vf") + self.command_var.append(cmd_line) + self.command_var.append("-y") - self.command_var.append("-y") + vcd = False - vcd = False + maxrate = int(file_project.video_rate_final * 1500) + minrate = int(file_project.video_rate_final * 666.66) - maxrate = int(file_project.video_rate_final * 1500) - minrate = int(file_project.video_rate_final * 666.66) + if (self.config.disc_type == "divx"): + self.command_var.append("-vcodec") + self.command_var.append("mpeg4") + self.command_var.append("-acodec") + self.command_var.append("libmp3lame") + self.command_var.append("-f") + self.command_var.append("avi") + self.command_var.append("-maxrate:v") + self.command_var.append(str(maxrate)) + self.command_var.append("-minrate:v") + if minrate < (devedeng.project.devede_project.divx_min_bps * 1000): + minrate = devedeng.project.devede_project.divx_min_bps * 1000 + self.command_var.append(str(minrate)) + elif (self.config.disc_type == "mkv"): + self.command_var.append("-vcodec") + self.command_var.append("h264") + self.command_var.append("-acodec") + self.command_var.append("libmp3lame") + self.command_var.append("-f") + self.command_var.append("matroska") + self.command_var.append("-maxrate:v") + self.command_var.append(str(maxrate)) + self.command_var.append("-minrate:v") + if minrate < (devedeng.project.devede_project.mkv_min_bps * 1000): + minrate = devedeng.project.devede_project.mkv_min_bps * 1000 + self.command_var.append(str(minrate)) + elif (self.config.disc_type == "dvd"): + if not file_project.no_reencode_audio_video: + self.command_var.append("-c:v") + self.command_var.append("mpeg2video") + if not file_project.copy_sound: + if file_project.sound5_1: + self.command_var.append("-c:a") + self.command_var.append("ac3") + else: + self.command_var.append("-c:a") + if file_project.format_pal: + self.command_var.append("ac3") + else: + self.command_var.append("mp2") + self.command_var.append("-f") + self.command_var.append("dvd") + self.command_var.append("-r") + if file_project.format_pal: + self.command_var.append("25") + else: + if (file_project.original_fps == 24): + self.command_var.append("24000/1001") + else: + self.command_var.append("30000/1001") + self.command_var.append("-pix_fmt") + self.command_var.append("yuv420p") + self.command_var.append("-maxrate:v") + if maxrate > (devedeng.project.devede_project.dvd_max_bps_base[0] * 1000): + maxrate = devedeng.project.devede_project.dvd_max_bps_base[ + 0] * 1000 + self.command_var.append(str(maxrate)) + self.command_var.append("-minrate:v") + if minrate < (devedeng.project.devede_project.dvd_min_bps * 1000): + minrate = devedeng.project.devede_project.dvd_min_bps * 1000 + self.command_var.append(str(minrate)) + self.command_var.append("-bufsize") + self.command_var.append("1835008") + self.command_var.append("-packetsize") + self.command_var.append("2048") + self.command_var.append("-muxrate") + self.command_var.append("10080000") + self.command_var.append("-ar") + self.command_var.append("48000") + elif (self.config.disc_type == "vcd"): + vcd = True + if not file_project.no_reencode_audio_video: + self.command_var.append("-c:v") + self.command_var.append("mpeg1video") + if not file_project.copy_sound: + self.command_var.append("-c:a") + self.command_var.append("mp2") + self.command_var.append("-b:v") + self.command_var.append("1150000") + self.command_var.append("-b:a") + self.command_var.append("224000") + self.command_var.append("-f") + self.command_var.append("vcd") + self.command_var.append("-r") + if file_project.format_pal: + self.command_var.append("25") + else: + if (file_project.original_fps == 24): + self.command_var.append("24000/1001") + else: + self.command_var.append("30000/1001") + self.command_var.append("-g") + if file_project.format_pal: + self.command_var.append("15") + else: + self.command_var.append("18") + self.command_var.append("-s") + if file_project.format_pal: + self.command_var.append("352x288") + else: + self.command_var.append("352x240") + self.command_var.append("-maxrate:v") + self.command_var.append("1150000") + self.command_var.append("-minrate:v") + self.command_var.append("1150000") + self.command_var.append("-bufsize") + self.command_var.append("327680") + self.command_var.append("-packetsize") + self.command_var.append("2324") + self.command_var.append("-muxrate") + self.command_var.append("1411200") + self.command_var.append("-ar") + self.command_var.append("44100") + elif (self.config.disc_type == "svcd") or (self.config.disc_type == "cvd"): + if not file_project.no_reencode_audio_video: + self.command_var.append("-c:v") + self.command_var.append("mpeg2video") + if not file_project.copy_sound: + self.command_var.append("-c:a") + self.command_var.append("mp2") + self.command_var.append("-f") + self.command_var.append("svcd") + self.command_var.append("-r") + if file_project.format_pal: + self.command_var.append("25") + else: + if (file_project.original_fps == 24): + self.command_var.append("24000/1001") + else: + self.command_var.append("30000/1001") + self.command_var.append("-g") + if file_project.format_pal: + self.command_var.append("12") + else: + self.command_var.append("15") + self.command_var.append("-s") + if self.config.disc_type == "cvd": + if file_project.format_pal: + self.command_var.append("352x576") + else: + self.command_var.append("352x480") + else: + if file_project.format_pal: + self.command_var.append("480x576") + else: + self.command_var.append("480x480") + self.command_var.append("-pix_fmt") + self.command_var.append("yuv420p") + self.command_var.append("-maxrate:v") + if maxrate > (devedeng.project.devede_project.svcd_max_bps_base[0] * 1000): + maxrate = devedeng.project.devede_project.svcd_max_bps_base[ + 0] * 1000 + self.command_var.append(str(maxrate)) + self.command_var.append("-minrate:v") + if minrate < (devedeng.project.devede_project.svcd_min_bps * 1000): + minrate = (devedeng.project.devede_project.svcd_min_bps * 1000) + self.command_var.append(str(minrate)) + self.command_var.append("-bufsize") + self.command_var.append("1835008") + self.command_var.append("-packetsize") + self.command_var.append("2324") + self.command_var.append("-ar") + self.command_var.append("44100") + self.command_var.append("-scan_offset") + self.command_var.append("1") - if (self.config.disc_type == "divx"): - self.command_var.append("-vcodec") - self.command_var.append("mpeg4") - self.command_var.append("-acodec") - self.command_var.append("libmp3lame") - self.command_var.append("-f") - self.command_var.append("avi") - self.command_var.append("-maxrate:v") - self.command_var.append(str(maxrate)) - self.command_var.append("-minrate:v") - if minrate < (devedeng.project.devede_project.divx_min_bps * 1000): - minrate = devedeng.project.devede_project.divx_min_bps * 1000 - self.command_var.append(str(minrate)) - elif (self.config.disc_type == "mkv"): - self.command_var.append("-vcodec") - self.command_var.append("h264") - self.command_var.append("-acodec") - self.command_var.append("libmp3lame") - self.command_var.append("-f") - self.command_var.append("matroska") - self.command_var.append("-maxrate:v") - self.command_var.append(str(maxrate)) - self.command_var.append("-minrate:v") - if minrate < (devedeng.project.devede_project.mkv_min_bps * 1000): - minrate = devedeng.project.devede_project.mkv_min_bps * 1000 - self.command_var.append(str(minrate)) - elif (self.config.disc_type=="dvd"): - if not file_project.no_reencode_audio_video: - self.command_var.append("-c:v") - self.command_var.append("mpeg2video") - if not file_project.copy_sound: - if file_project.sound5_1: - self.command_var.append("-c:a") - self.command_var.append("ac3") - else: - self.command_var.append("-c:a") - if file_project.format_pal: - self.command_var.append("ac3") - else: - self.command_var.append("mp2") - self.command_var.append("-f") - self.command_var.append("dvd") - self.command_var.append("-r") - if file_project.format_pal: - self.command_var.append("25") - else: - if (file_project.original_fps == 24): - self.command_var.append("24000/1001") - else: - self.command_var.append("30000/1001") - self.command_var.append("-pix_fmt") - self.command_var.append("yuv420p") - self.command_var.append("-maxrate:v") - if maxrate > (devedeng.project.devede_project.dvd_max_bps_base[0] * 1000): - maxrate = devedeng.project.devede_project.dvd_max_bps_base[0] * 1000 - self.command_var.append(str(maxrate)) - self.command_var.append("-minrate:v") - if minrate < (devedeng.project.devede_project.dvd_min_bps * 1000): - minrate = devedeng.project.devede_project.dvd_min_bps * 1000 - self.command_var.append(str(minrate)) - self.command_var.append("-bufsize") - self.command_var.append("1835008") - self.command_var.append("-packetsize") - self.command_var.append("2048") - self.command_var.append("-muxrate") - self.command_var.append("10080000") - self.command_var.append("-ar") - self.command_var.append("48000") - elif (self.config.disc_type=="vcd"): - vcd = True - if not file_project.no_reencode_audio_video: - self.command_var.append("-c:v") - self.command_var.append("mpeg1video") - if not file_project.copy_sound: - self.command_var.append("-c:a") - self.command_var.append("mp2") - self.command_var.append("-b:v") - self.command_var.append("1150000") - self.command_var.append("-b:a") - self.command_var.append("224000") - self.command_var.append("-f") - self.command_var.append("vcd") - self.command_var.append("-r") - if file_project.format_pal: - self.command_var.append("25") - else: - if (file_project.original_fps == 24): - self.command_var.append("24000/1001") - else: - self.command_var.append("30000/1001") - self.command_var.append("-g") - if file_project.format_pal: - self.command_var.append("15") - else: - self.command_var.append("18") - self.command_var.append("-s") - if file_project.format_pal: - self.command_var.append("352x288") - else: - self.command_var.append("352x240") - self.command_var.append("-maxrate:v") - self.command_var.append("1150000") - self.command_var.append("-minrate:v") - self.command_var.append("1150000") - self.command_var.append("-bufsize") - self.command_var.append("327680") - self.command_var.append("-packetsize") - self.command_var.append("2324") - self.command_var.append("-muxrate") - self.command_var.append("1411200") - self.command_var.append("-ar") - self.command_var.append("44100") - elif (self.config.disc_type=="svcd") or (self.config.disc_type=="cvd"): - if not file_project.no_reencode_audio_video: - self.command_var.append("-c:v") - self.command_var.append("mpeg2video") - if not file_project.copy_sound: - self.command_var.append("-c:a") - self.command_var.append("mp2") - self.command_var.append("-f") - self.command_var.append("svcd") - self.command_var.append("-r") - if file_project.format_pal: - self.command_var.append("25") - else: - if (file_project.original_fps == 24): - self.command_var.append("24000/1001") - else: - self.command_var.append("30000/1001") - self.command_var.append("-g") - if file_project.format_pal: - self.command_var.append("12") - else: - self.command_var.append("15") - self.command_var.append("-s") - if self.config.disc_type == "cvd": - if file_project.format_pal: - self.command_var.append("352x576") - else: - self.command_var.append("352x480") - else: - if file_project.format_pal: - self.command_var.append("480x576") - else: - self.command_var.append("480x480") - self.command_var.append("-pix_fmt") - self.command_var.append("yuv420p") - self.command_var.append("-maxrate:v") - if maxrate > (devedeng.project.devede_project.svcd_max_bps_base[0] * 1000): - maxrate = devedeng.project.devede_project.svcd_max_bps_base[0] * 1000 - self.command_var.append(str(maxrate)) - self.command_var.append("-minrate:v") - if minrate < (devedeng.project.devede_project.svcd_min_bps * 1000): - minrate = (devedeng.project.devede_project.svcd_min_bps * 1000) - self.command_var.append(str(minrate)) - self.command_var.append("-bufsize") - self.command_var.append("1835008") - self.command_var.append("-packetsize") - self.command_var.append("2324") - self.command_var.append("-ar") - self.command_var.append("44100") - self.command_var.append("-scan_offset") - self.command_var.append("1") + if (not file_project.no_reencode_audio_video): + self.command_var.append("-sn") # no subtitles - if (not file_project.no_reencode_audio_video): - self.command_var.append("-sn") # no subtitles + if file_project.copy_sound or file_project.no_reencode_audio_video: + self.command_var.append("-c:a") + self.command_var.append("copy") - if file_project.copy_sound or file_project.no_reencode_audio_video: - self.command_var.append("-c:a") - self.command_var.append("copy") + if file_project.no_reencode_audio_video: + self.command_var.append("-c:v") + self.command_var.append("copy") - if file_project.no_reencode_audio_video: - self.command_var.append("-c:v") - self.command_var.append("copy") + if (not vcd): + if not file_project.format_pal: + if (file_project.original_fps == 24) and ((self.config.disc_type == "dvd")): + keyintv = 15 + else: + keyintv = 18 + else: + keyintv = 15 - if (not vcd): - if not file_project.format_pal: - if (file_project.original_fps==24) and ((self.config.disc_type=="dvd")): - keyintv=15 - else: - keyintv=18 - else: - keyintv=15 + if (not file_project.gop12) and (not(self.config.disc_type == "divx")) and (not(self.config.disc_type == "mkv")): + self.command_var.append("-g") + self.command_var.append(str(keyintv)) - if (not file_project.gop12) and (not(self.config.disc_type == "divx")) and (not(self.config.disc_type == "mkv")): - self.command_var.append("-g") - self.command_var.append(str(keyintv)) + if (self.config.disc_type == "divx") or (self.config.disc_type == "mkv"): + self.command_var.append("-g") + self.command_var.append("300") + elif file_project.gop12 and (not file_project.no_reencode_audio_video): + self.command_var.append("-g") + self.command_var.append("12") - if (self.config.disc_type=="divx") or (self.config.disc_type=="mkv"): - self.command_var.append("-g") - self.command_var.append("300") - elif file_project.gop12 and (not file_project.no_reencode_audio_video): - self.command_var.append("-g") - self.command_var.append("12") + self.command_var.append("-bf") + self.command_var.append("2") + self.command_var.append("-strict") + self.command_var.append("1") - self.command_var.append("-bf") - self.command_var.append("2") - self.command_var.append("-strict") - self.command_var.append("1") + if video_length != 0: + self.command_var.append("-t") + self.command_var.append(str(video_length)) - if video_length != 0: - self.command_var.append("-t") - self.command_var.append(str(video_length)) + self.command_var.append("-ac") + if (file_project.sound5_1) and ((self.config.disc_type == "dvd") or (self.config.disc_type == "divx") or (self.config.disc_type == "mkv")): + self.command_var.append("6") + else: + self.command_var.append("2") - self.command_var.append("-ac") - if (file_project.sound5_1) and ((self.config.disc_type=="dvd") or (self.config.disc_type=="divx") or (self.config.disc_type=="mkv")): - self.command_var.append("6") - else: - self.command_var.append("2") + self.command_var.append("-aspect") + self.command_var.append(str(file_project.aspect_ratio_final)) - self.command_var.append("-aspect") - self.command_var.append(str(file_project.aspect_ratio_final)) + if self.config.disc_type == "divx": + self.command_var.append("-vtag") + self.command_var.append("DX50") - if self.config.disc_type=="divx": - self.command_var.append("-vtag") - self.command_var.append("DX50") + if (file_project.deinterlace == "deinterlace_ffmpeg") and (file_project.no_reencode_audio_video == False) and second_pass: + self.command_var.append("-deinterlace") - if (file_project.deinterlace == "deinterlace_ffmpeg") and (file_project.no_reencode_audio_video==False) and second_pass: - self.command_var.append("-deinterlace") + if (file_project.no_reencode_audio_video == False) and (vcd == False) and second_pass: + self.command_var.append("-s") + self.command_var.append( + str(file_project.width_final) + "x" + str(file_project.height_final)) - if (file_project.no_reencode_audio_video==False) and (vcd==False) and second_pass: - self.command_var.append("-s") - self.command_var.append(str(file_project.width_final)+"x"+str(file_project.height_final)) + if second_pass: + self.command_var.append("-trellis") + self.command_var.append("1") + self.command_var.append("-mbd") + self.command_var.append("2") + else: + self.command_var.append("-trellis") + self.command_var.append("0") + self.command_var.append("-mbd") + self.command_var.append("0") - if second_pass: - self.command_var.append("-trellis") - self.command_var.append("1") - self.command_var.append("-mbd") - self.command_var.append("2") - else: - self.command_var.append("-trellis") - self.command_var.append("0") - self.command_var.append("-mbd") - self.command_var.append("0") + if (vcd == False) and (file_project.no_reencode_audio_video == False): + self.command_var.append("-b:a") + self.command_var.append(str(file_project.audio_rate_final) + "k") - if (vcd == False) and (file_project.no_reencode_audio_video == False): - self.command_var.append("-b:a") - self.command_var.append(str(file_project.audio_rate_final)+"k") + self.command_var.append("-b:v") + self.command_var.append(str(file_project.video_rate_final) + "k") - self.command_var.append("-b:v") - self.command_var.append(str(file_project.video_rate_final)+"k") + if file_project.two_pass_encoding == True: + self.command_var.append("-passlogfile") + self.command_var.append(output_file) + self.command_var.append("-pass") + if pass2: + self.command_var.append("2") + else: + self.command_var.append("1") - if file_project.two_pass_encoding == True: - self.command_var.append("-passlogfile") - self.command_var.append(output_file) - self.command_var.append("-pass") - if pass2: - self.command_var.append("2") - else: - self.command_var.append("1") + self.command_var.append(output_file) - self.command_var.append(output_file) + def create_menu_mpeg(self, n_page, background_music, sound_length, pal, video_rate, audio_rate, output_path, use_mp2): + self.n_page = n_page + self.final_length = float(sound_length) + self.text = _("Creating menu %(X)d") % {"X": self.n_page} - def create_menu_mpeg(self,n_page,background_music,sound_length,pal,video_rate, audio_rate,output_path, use_mp2): + self.command_var = [] + self.command_var.append("ffmpeg") - self.n_page = n_page - self.final_length = float(sound_length) - self.text = _("Creating menu %(X)d") % {"X": self.n_page} + self.command_var.append("-loop") + self.command_var.append("1") - self.command_var=[] - self.command_var.append("ffmpeg") + self.command_var.append("-f") + self.command_var.append("image2") + self.command_var.append("-i") + self.command_var.append(os.path.join( + output_path, "menu_" + str(n_page) + "_bg.png")) + self.command_var.append("-i") + self.command_var.append(background_music) - self.command_var.append("-loop") - self.command_var.append("1") + self.command_var.append("-y") + self.command_var.append("-target") + if pal: + self.command_var.append("pal-dvd") + else: + self.command_var.append("ntsc-dvd") + self.command_var.append("-acodec") + if use_mp2: + self.command_var.append("mp2") + else: + self.command_var.append("ac3") + self.command_var.append("-s") + if pal: + self.command_var.append("720x576") + else: + self.command_var.append("720x480") + self.command_var.append("-g") + self.command_var.append("12") + self.command_var.append("-b:v") + self.command_var.append(str(video_rate) + "k") + self.command_var.append("-b:a") + self.command_var.append(str(audio_rate) + "k") + self.command_var.append("-aspect") + self.command_var.append("4:3") - self.command_var.append("-f") - self.command_var.append("image2") - self.command_var.append("-i") - self.command_var.append(os.path.join(output_path,"menu_"+str(n_page)+"_bg.png")) - self.command_var.append("-i") - self.command_var.append(background_music) + self.command_var.append("-t") + self.command_var.append(str(1 + sound_length)) - self.command_var.append("-y") - self.command_var.append("-target") - if pal: - self.command_var.append("pal-dvd") - else: - self.command_var.append("ntsc-dvd") - self.command_var.append("-acodec") - if use_mp2: - self.command_var.append("mp2") - else: - self.command_var.append("ac3") - self.command_var.append("-s") - if pal: - self.command_var.append("720x576") - else: - self.command_var.append("720x480") - self.command_var.append("-g") - self.command_var.append("12") - self.command_var.append("-b:v") - self.command_var.append(str(video_rate)+"k") - self.command_var.append("-b:a") - self.command_var.append(str(audio_rate)+"k") - self.command_var.append("-aspect") - self.command_var.append("4:3") + movie_path = os.path.join(output_path, "menu_" + str(n_page) + ".mpg") + self.command_var.append(movie_path) - self.command_var.append("-t") - self.command_var.append(str(1+sound_length)) + muxer = devedeng.mux_dvd_menu.mux_dvd_menu() + final_path = muxer.create_mpg(n_page, output_path, movie_path) + # the muxer process depends of the converter process + muxer.add_dependency(self) + self.add_child_process(muxer) - movie_path = os.path.join(output_path,"menu_"+str(n_page)+".mpg") - self.command_var.append(movie_path) + return (final_path) - muxer = devedeng.mux_dvd_menu.mux_dvd_menu() - final_path = muxer.create_mpg(n_page,output_path,movie_path) - # the muxer process depends of the converter process - muxer.add_dependency(self) - self.add_child_process(muxer) + def process_stdout(self, data): - return (final_path) + return - def process_stdout(self,data): + def process_stderr(self, data): - return - - def process_stderr(self,data): - - pos = data[0].find("time=") - if (pos != -1): - pos+=5 - pos2 = data[0].find(" ",pos) - if (pos2 != -1): - parts = data[0][pos:pos2].split(":") - t = 0.0 - for e in parts: - t *= 60.0 - t += float(e) - t /= self.final_length - self.progress_bar[1].set_fraction(t) - self.progress_bar[1].set_text("%.1f%%" % (100.0 * t)) + pos = data[0].find("time=") + if (pos != -1): + pos += 5 + pos2 = data[0].find(" ", pos) + if (pos2 != -1): + parts = data[0][pos:pos2].split(":") + t = 0.0 + for e in parts: + t *= 60.0 + t += float(e) + t /= self.final_length + self.progress_bar[1].set_fraction(t) + self.progress_bar[1].set_text("%.1f%%" % (100.0 * t)) diff --git a/src/devedeng/ffprobe.py b/src/devedeng/ffprobe.py index 646803a..c8a90a6 100644 --- a/src/devedeng/ffprobe.py +++ b/src/devedeng/ffprobe.py @@ -23,6 +23,7 @@ import devedeng.executor import os import json + class ffprobe(devedeng.executor.executor): supports_analize = True @@ -36,9 +37,10 @@ class ffprobe(devedeng.executor.executor): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["ffprobe","-h"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["ffprobe", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -50,10 +52,10 @@ class ffprobe(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): return def get_film_data(self, file_name): @@ -62,22 +64,22 @@ class ffprobe(devedeng.executor.executor): self.original_file_size = os.path.getsize(file_name) - command_line = ["ffprobe",file_name,"-of","json","-show_streams", "-loglevel", "quiet"] + command_line = ["ffprobe", file_name, "-of", + "json", "-show_streams", "-loglevel", "quiet"] (stdout, stderr) = self.launch_process(command_line, False) try: stdout2 = stdout.decode("utf-8") except: stdout2 = stdout.decode("latin1") - self.config.append_static_log("FFProbe JSON data: "+str(stdout2)) - return self.process_json(file_name,stdout2) + self.config.append_static_log("FFProbe JSON data: " + str(stdout2)) + return self.process_json(file_name, stdout2) + def process_json(self, file_name, stdout2): - def process_json(self,file_name,stdout2): - - self.audio_list=[] + self.audio_list = [] self.audio_streams = 0 - self.video_list=[] + self.video_list = [] self.video_streams = 0 self.original_width = 0 self.original_height = 0 @@ -88,14 +90,15 @@ class ffprobe(devedeng.executor.executor): self.original_fps = 0 self.original_aspect_ratio = 0 - self.config.append_static_log("Getting data for {:s} with ffprobe".format(file_name)) + self.config.append_static_log( + "Getting data for {:s} with ffprobe".format(file_name)) try: video_data = json.loads(stdout2) except: - return True # There was an error reading the JSON data + return True # There was an error reading the JSON data if not("streams" in video_data): - return True # There are no streams!!!!! + return True # There are no streams!!!!! for element in video_data["streams"]: @@ -105,50 +108,62 @@ class ffprobe(devedeng.executor.executor): except: self.original_length = -1 - if (element["codec_type"]=="video"): + if (element["codec_type"] == "video"): self.video_streams += 1 self.video_list.append(element["index"]) if (self.video_streams == 1): self.original_width = int(float(element["width"])) self.original_height = int(float(element["height"])) if ("bit_rate" in element): - self.original_videorate = int(float(element["bit_rate"]))/1000 - self.original_fps = self.get_division(element["avg_frame_rate"]) + self.original_videorate = int( + float(element["bit_rate"])) / 1000 + self.original_fps = self.get_division( + element["avg_frame_rate"]) if ("display_aspect_ratio" in element): - self.original_aspect_ratio = self.get_division(element["display_aspect_ratio"]) + self.original_aspect_ratio = self.get_division( + element["display_aspect_ratio"]) - elif (element["codec_type"]=="audio"): + elif (element["codec_type"] == "audio"): self.audio_streams += 1 self.audio_list.append(element["index"]) if (self.audio_streams == 1): if ("bit_rate" in element): - self.original_audiorate = int(float(element["bit_rate"]))/1000 - self.original_audiorate_uncompressed = int(float(element["sample_rate"])) + self.original_audiorate = int( + float(element["bit_rate"])) / 1000 + self.original_audiorate_uncompressed = int( + float(element["sample_rate"])) - self.original_size = str(self.original_width)+"x"+str(self.original_height) + self.original_size = str(self.original_width) + \ + "x" + str(self.original_height) if (self.original_aspect_ratio is None) or (self.original_aspect_ratio <= 1.0): if (self.original_height != 0): - self.original_aspect_ratio = (float(self.original_width))/(float(self.original_height)) + self.original_aspect_ratio = ( + float(self.original_width)) / (float(self.original_height)) if (self.original_aspect_ratio is not None): - self.original_aspect_ratio = (float(int(self.original_aspect_ratio*1000.0)))/1000.0 + self.original_aspect_ratio = ( + float(int(self.original_aspect_ratio * 1000.0))) / 1000.0 if (len(self.video_list) == 0): - return True # the file is not a video file; maybe an audio-only file or another thing + return True # the file is not a video file; maybe an audio-only file or another thing - if self.original_length == -1: # if it was unable to detect the duration, try to use the human readable format - command_line = ["ffprobe",file_name] + if self.original_length == -1: # if it was unable to detect the duration, try to use the human readable format + command_line = ["ffprobe", file_name] (stdout, stderr) = self.launch_process(command_line, False) try: - stdout2 = stdout.decode("utf-8") + "\n" + stderr.decode("utf-8") + stdout2 = stdout.decode("utf-8") + \ + "\n" + stderr.decode("utf-8") except: - stdout2 = stdout.decode("latin1") + "\n" + stderr.decode("latin1") - self.config.append_static_log("Using ffprobe human readable format: "+str(stdout2)) + stdout2 = stdout.decode("latin1") + \ + "\n" + stderr.decode("latin1") + self.config.append_static_log( + "Using ffprobe human readable format: " + str(stdout2)) for line in stdout2.split("\n"): line = line.strip() if line.startswith("Duration: "): self.original_length = self.get_time(line[10:]) break - self.config.append_static_log("Estimated length: {:d}; Resolution: {:s}".format(self.original_length,self.original_size)) - return False # no error + self.config.append_static_log("Estimated length: {:d}; Resolution: {:s}".format( + self.original_length, self.original_size)) + return False # no error diff --git a/src/devedeng/file_copy.py b/src/devedeng/file_copy.py index d0bdf41..38aded8 100644 --- a/src/devedeng/file_copy.py +++ b/src/devedeng/file_copy.py @@ -21,22 +21,23 @@ import os import devedeng.configuration_data import devedeng.executor + class file_copy(devedeng.executor.executor): - def __init__(self,input_path, output_path): + def __init__(self, input_path, output_path): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - self.text = _("Copying file %(X)s") % {"X": os.path.basename(input_path)} + self.text = _("Copying file %(X)s") % { + "X": os.path.basename(input_path)} - self.command_var=[] + self.command_var = [] self.command_var.append("copy_files_verbose.py") self.command_var.append(input_path) self.command_var.append(output_path) - - def process_stdout(self,data): + def process_stdout(self, data): if (data is None) or (len(data) == 0): return @@ -45,10 +46,10 @@ class file_copy(devedeng.executor.executor): if (pos == -1): return p = float(data[0][7:pos]) - self.progress_bar[1].set_fraction(p/ 100.0) + self.progress_bar[1].set_fraction(p / 100.0) self.progress_bar[1].set_text("%.1f%%" % (p)) return - def process_stderr(self,data): + def process_stderr(self, data): return diff --git a/src/devedeng/file_movie.py b/src/devedeng/file_movie.py index 8225be1..a2fd3ae 100644 --- a/src/devedeng/file_movie.py +++ b/src/devedeng/file_movie.py @@ -15,7 +15,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from gi.repository import Gtk,GObject +from gi.repository import Gtk, GObject import os import devedeng.configuration_data @@ -26,723 +26,742 @@ import devedeng.preview import devedeng.file_copy import devedeng.subtitles_mux + class file_movie(devedeng.interface_manager.interface_manager): - __gsignals__ = {'title_changed': (GObject.SIGNAL_RUN_FIRST, None,(str,)), 'in_menu_changed': (GObject.SIGNAL_RUN_FIRST, None,(bool,))} - - def __init__(self,file_name, list_files = None): - - self.list_files = list_files - - devedeng.interface_manager.interface_manager.__init__(self) - - self.wfile_properties = None - self.builder = None - - self.config = devedeng.configuration_data.configuration.get_config() - self.set_type(None, self.config.disc_type) - self.config.connect('disc_type',self.set_type) - - if list_files is None: - self.add_text("file_name", file_name) - self.add_text("title_name", os.path.splitext(os.path.basename(file_name))[0]) - self.add_label("original_size",None) - self.add_label("original_length",None) - self.add_label("original_videorate",None) - self.add_label("original_audiorate",None) - self.add_label("original_aspect_ratio",None) - self.add_label("original_fps",None) - self.add_toggle("show_in_menu", True) - else: - self.original_aspect_ratio = 1.777 # dummy value - - self.add_text("chapter_list_entry", None); - - self.add_dualtoggle("format_pal","format_ntsc",self.config.PAL) - self.add_toggle("video_rate_automatic", True) - self.add_toggle("audio_rate_automatic", True) - self.add_toggle("divide_in_chapters", True) - self.add_toggle("force_subtitles", False) - self.add_toggle("mirror_horizontal", False) - self.add_toggle("mirror_vertical", False) - self.add_toggle("two_pass_encoding", False) - self.add_toggle("sound5_1", False) - self.add_toggle("copy_sound", False) - self.add_toggle("is_mpeg_ps", False) - self.add_toggle("no_reencode_audio_video", False) - if (self.disc_type == "divx") or (self.disc_type == "mkv"): - self.add_toggle("gop12", False) - else: - self.add_toggle("gop12", True) - - self.add_group("final_size_pal", ["size_auto", "size_1920x1080", "size_1280x720", "size_720x576", "size_704x576", "size_480x576","size_352x576", "size_352x288"], "size_auto") - self.add_group("final_size_ntsc", ["size_auto_ntsc", "size_1920x1080_ntsc", "size_1280x720_ntsc", "size_720x480_ntsc", "size_704x480_ntsc", "size_480x480_ntsc","size_352x480_ntsc", "size_352x240_ntsc"], "size_auto_ntsc") - self.add_group("aspect_ratio", ["aspect_auto", "aspect_classic", "aspect_wide"], "aspect_auto") - self.add_group("scaling", ["add_black_bars", "scale_picture" ,"cut_picture"], "add_black_bars") - self.add_group("rotation",["rotation_0","rotation_90","rotation_180","rotation_270"], "rotation_0") - self.add_group("deinterlace", ["deinterlace_none", "deinterlace_ffmpeg", "deinterlace_yadif"], "deinterlace_none") - self.add_group("actions", ["action_stop","action_play_first","action_play_previous","action_play_again","action_play_next","action_play_last"], "action_stop") - - self.add_integer_adjustment("volume", 100) - if (self.disc_type == "dvd"): - self.add_integer_adjustment("video_rate", 5000) - elif (self.disc_type == "vcd"): - self.add_integer_adjustment("video_rate", 1152) - else: - self.add_integer_adjustment("video_rate", 2000) - - self.add_integer_adjustment("audio_rate", 224) - self.add_integer_adjustment("subt_font_size", 28) - self.add_float_adjustment("audio_delay", 0.0) - self.add_integer_adjustment("chapter_size", 5) - - self.add_colorbutton("subt_fill_color", self.config.subt_fill_color) - self.add_colorbutton("subt_outline_color", self.config.subt_outline_color) - self.add_float_adjustment("subt_thickness", self.config.subt_outline_thickness) - - if list_files is None: - self.add_list("subtitles_list") - else: - self.add_list("files_to_set") - for e in list_files: - self.files_to_set.append([e.title_name, e]) - - self.add_show_hide("format_pal", ["size_pal"], ["size_ntsc"]) - - self.add_enable_disable("divide_in_chapters", ["chapter_size_spinbutton", "chapter_list_entry"], []) - self.add_enable_disable("video_rate_automatic", [], ["video_spinbutton"]) - self.add_enable_disable("audio_rate_automatic", [], ["audio_spinbutton"]) - self.add_enable_disable("sound5_1", ["copy_sound"], []) - - if (self.disc_type == "dvd"): - self.add_enable_disable("aspect_wide", [], ["size_704x576", "size_480x576","size_352x576", "size_352x288","size_704x480_ntsc", "size_480x480_ntsc","size_352x480_ntsc", "size_352x240_ntsc"]) - - self.add_enable_disable("copy_sound", [], ["audio_delay_spinbutton","audio_rate_automatic","audio_spinbutton","spinbutton_volume","scale_volume","reset_volume"]) - - common_elements = ["gop12","video_rate_automatic","video_spinbutton","audio_rate_automatic","audio_spinbutton","format_pal","format_ntsc","spinbutton_volume","scale_volume","reset_volume", - "size_auto", "size_1920x1080", "size_1280x720", "size_720x576", "size_704x576", "size_480x576","size_352x576", "size_352x288", - "size_auto_ntsc", "size_1920x1080_ntsc", "size_1280x720_ntsc", "size_720x480_ntsc", "size_704x480_ntsc", "size_480x480_ntsc","size_352x480_ntsc", "size_352x240_ntsc", - "aspect_auto","aspect_classic","aspect_wide","mirror_horizontal","mirror_vertical","add_black_bars","scale_picture","cut_picture", - "rotation_0","rotation_90","rotation_180","rotation_270","two_pass_encoding","deinterlace_none","deinterlace_ffmpeg","deinterlace_yadif", - "audio_delay_spinbutton","sound5_1","copy_sound"] - - is_mpeg_ps_list = common_elements[:] - is_mpeg_ps_list.append("no_reencode_audio_video") - is_mpeg_ps_list.append("font_size_spinbutton") - is_mpeg_ps_list.append("force_subtitles") - is_mpeg_ps_list.append("add_subtitles") - is_mpeg_ps_list.append("del_subtitles") - no_reencode_audio_video_list = common_elements[:] - no_reencode_audio_video_list.append("is_mpeg_ps") - - self.add_enable_disable("is_mpeg_ps", [], is_mpeg_ps_list) - self.add_enable_disable("no_reencode_audio_video", [], no_reencode_audio_video_list) - - if list_files is None: - cv = devedeng.converter.converter.get_converter() - film_analizer = (cv.get_film_analizer())() - if (film_analizer.get_film_data(self.file_name)): - self.error = True - else: - self.error = False - self.audio_list = film_analizer.audio_list[:] - self.video_list = film_analizer.video_list[:] - self.audio_streams = film_analizer.audio_streams - self.video_streams = film_analizer.video_streams - self.original_width = film_analizer.original_width - self.original_height = film_analizer.original_height - self.original_length = film_analizer.original_length - self.original_size = film_analizer.original_size - self.original_aspect_ratio = film_analizer.original_aspect_ratio - self.original_videorate = film_analizer.original_videorate - self.original_audiorate = film_analizer.original_audiorate - - self.original_audiorate_uncompressed = film_analizer.original_audiorate_uncompressed - self.original_fps = film_analizer.original_fps - self.original_file_size = film_analizer.original_file_size - - if self.original_audiorate <= 0: - # just a guess, but usually correct - self.original_audiorate = 224 - if self.original_videorate <= 0: - # presume that there are only video and audio streams - self.original_videorate = ((8 * self.original_file_size) / self.original_length) - (self.original_audiorate * self.audio_streams) - # to avoid division by zero when a clip is very short - if self.original_length <= 0: - self.original_length = 1 - - self.width_midle = -1 - self.height_midle = -1 - self.width_final = -1 - self.height_final = -1 - self.video_rate_auto = self.video_rate - self.audio_rate_auto = self.audio_rate - self.video_rate_final = self.video_rate - self.audio_rate_final = self.audio_rate - self.aspect_ratio_final = None - self.converted_filename = None - - - def set_title(self,new_title): - self.title_name = new_title - self.emit('title_changed',self.title_name) - - - def set_show_in_menu(self,show): - self.show_in_menu = show - self.emit('in_menu_changed',self.show_in_menu) - - - def get_duration(self): - return self.original_length - - - def get_estimated_size(self): - """ Returns the estimated final file size, in kBytes, based on the final audio and video rate, and the subtitles """ - - self.set_final_rates() - self.set_final_size_aspect() - - if self.is_mpeg_ps: - estimated_size = self.original_file_size / 1000 - else: - # let's asume 8kbps for each subtitle - sub_rate = 8 * len(self.subtitles_list) - estimated_size = ((self.video_rate_final + (self.audio_rate_final * self.audio_streams) + sub_rate) * self.original_length) / 8 - - return estimated_size - - - def get_size_data(self): - - estimated_size = self.get_estimated_size() - if self.is_mpeg_ps or self.no_reencode_audio_video: - videorate_fixed_size = True - else: - videorate_fixed_size = False - - # let's asume 8kbps for each subtitle - sub_rate = 8 * len(self.subtitles_list) - - return estimated_size, videorate_fixed_size, self.audio_rate_final * self.audio_streams, sub_rate, self.width_final, self.height_final, self.original_length - - - def set_auto_video_audio_rate(self, new_video_rate, new_audio_rate): - - self.video_rate_auto = int(new_video_rate) - self.audio_rate_auto = int(new_audio_rate) - - - def get_max_resolution(self,rx,ry,aspect): - - tmpx = ry*aspect - tmpy = rx/aspect - if (tmpx > rx): - return tmpx,ry - else: - return rx,tmpy - - - def set_final_rates(self): - - if (self.disc_type == "divx") or (self.disc_type == "mkv"): - self.audio_rate_auto = 192 - elif (self.disc_type == "vcd") or (self.disc_type == "svcd") or (self.disc_type == "cvd"): - self.audio_rate_auto = 224 - else: # dvd - if self.sound5_1: - self.audio_rate_auto = 384 - else: - self.audio_rate_auto = 224 - - if self.is_mpeg_ps or self.no_reencode_audio_video: - self.video_rate_final = self.original_videorate - self.audio_rate_final = self.original_audiorate - else: - if self.video_rate_automatic: - self.video_rate_final = self.video_rate_auto - else: - self.video_rate_final = self.video_rate - - if self.copy_sound: - self.audio_rate_final = self.original_audiorate - else: - if self.audio_rate_automatic: - self.audio_rate_final = self.audio_rate_auto - else: - self.audio_rate_final = self.audio_rate - - - def set_final_size_aspect(self): - - if self.is_mpeg_ps: - self.width_midle = self.original_width - self.width_final = self.original_width - self.height_midle = self.original_height - self.height_final = self.original_height - self.aspect_ratio_final = self.original_aspect_ratio - return - - if self.format_pal: - final_size = self.final_size_pal - else: - final_size = self.final_size_ntsc[:-5] # remove the "_ntsc" from the string - - # for divx or matroska, if the size and the aspect ratio is automatic, just don't change them - if ((self.disc_type == "divx") or (self.disc_type == "mkv")) and (final_size == "size_auto") and (self.aspect_ratio == "aspect_auto"): - self.width_midle = self.original_width - self.width_final = self.original_width - self.height_midle = self.original_height - self.height_final = self.original_height - self.aspect_ratio_final = self.original_aspect_ratio - return - - # The steps are: - # - Decide the final aspect ratio - # - Calculate the midle size: the original video will be cut to this size, or black bars will be added - # - Calculate the final size: the midle video will be scaled to this size - - aspect_wide = False - # first, decide the final aspect ratio - if (self.disc_type == "vcd") or (self.disc_type == "svcd") or (self.disc_type == "cvd"): - self.aspect_ratio_final = 4.0/3.0 - else: - if (self.aspect_ratio == "aspect_auto"): - if (self.disc_type != "dvd"): - self.aspect_ratio_final = self.original_aspect_ratio - else: - if self.original_aspect_ratio >= 1.7: - self.aspect_ratio_final = 16.0/9.0 - aspect_wide = True - else: - self.aspect_ratio_final = 4.0/3.0 - elif (self.aspect_ratio == "aspect_classic"): - self.aspect_ratio_final = 4.0/3.0 - else: - self.aspect_ratio_final = 16.0/9.0 - aspect_wide = True - - # now, the final resolution - if self.disc_type == "vcd": - self.width_final = 352 - if (self.format_pal): - self.height_final = 288 - else: - self.height_final = 240 - else: - if final_size == "size_auto": - if self.disc_type == "svcd": - self.width_final =480 - if (self.format_pal): - self.height_final = 576 - else: - self.height_final = 480 - elif self.disc_type == "cvd": - self.width_final =352 - if (self.format_pal): - self.height_final = 576 - else: - self.height_final = 480 - elif self.disc_type == "dvd": - if aspect_wide: - self.width_final = 720 - if (self.format_pal): - self.height_final = 576 - else: - self.height_final = 480 - else: - tx, ty = self.get_max_resolution(self.original_width,self.original_height,self.original_aspect_ratio) - if (self.format_pal): - th = 576 - th2 = 288 - else: - th = 480 - th2 = 240 - if ( tx <= 352 ) and (ty <= th2): - self.width_final = 352 - self.height_final = th2 - elif (tx <= 352) and (ty <= th): - self.width_final = 352 - self.height_final = th - elif (tx <= 704) and (ty <= th): - self.width_final = 704 - self.height_final = th - else: - self.width_final = 720 - self.height_final = th - else: - self.width_final , self.height_final = self.get_max_resolution(self.original_width,self.original_height,self.original_aspect_ratio) - else: - values = final_size[5:].split("x") - self.width_final = int(values[0]) - self.height_final = int(values[1]) - - self.width_final = int(self.width_final) - self.height_final = int(self.height_final) - - # finally, calculate the midle size - - if (self.rotation == "rotation_90") or (self.rotation == "rotation_270"): - midle_aspect_ratio = 1.0 / self.original_aspect_ratio - else: - midle_aspect_ratio = self.original_aspect_ratio - - if self.scaling == "scale_picture": - self.width_midle = int(self.original_width) - self.height_midle = int(self.original_height) - elif self.scaling == "add_black_bars": - if midle_aspect_ratio > self.aspect_ratio_final: # add horizontal black bars, at top and bottom - self.width_midle = int(self.original_width) - self.height_midle = int(self.original_height * midle_aspect_ratio / self.aspect_ratio_final) - else: # add vertical black bars, at left and right - self.width_midle = int(self.original_width * self.aspect_ratio_final / midle_aspect_ratio) - self.height_midle = int(self.original_height) - else: # cut picture - if midle_aspect_ratio > self.aspect_ratio_final: - self.width_midle = int(self.original_width * self.aspect_ratio_final / midle_aspect_ratio) - self.height_midle = int(self.original_height) - else: - self.width_midle = int(self.original_width) - self.height_midle = int(self.original_height * midle_aspect_ratio / self.aspect_ratio_final) - - - def set_type(self,obj = None,disc_type = None): - - if (disc_type is not None): - self.disc_type = disc_type - - - def delete_file(self): - - return - - def on_help_clicked(self,b): - - help_file = devedeng.help.help("file.html") - - - def properties(self): - - if (self.wfile_properties is not None): - self.wfile_properties.present() - return - - self.builder = Gtk.Builder() - self.builder.set_translation_domain(self.config.gettext_domain) - - self.builder.add_from_file(os.path.join(self.config.glade,"wfile_properties.ui")) - self.builder.connect_signals(self) - self.wfile_properties = self.builder.get_object("file_properties") - self.wfile_properties.show_all() - - self.wframe_title = self.builder.get_object("frame_title") - self.wframe_fileinfo = self.builder.get_object("frame_fileinfo") - self.wframe_multiproperties = self.builder.get_object("frame_multiproperties") - self.wtreeview_multiproperties = self.builder.get_object("treeview_multiproperties") - self.wbutton_preview = self.builder.get_object("button_preview") - - self.wshow_in_menu = self.builder.get_object("show_in_menu") - - self.wnotebook = self.builder.get_object("notebook") - - # elements in page GENERAL - self.wformat_pal = self.builder.get_object("format_pal") - self.wformat_ntsc = self.builder.get_object("format_ntsc") - self.wframe_video_rate = self.builder.get_object("frame_video_rate") - self.wframe_audio_rate = self.builder.get_object("frame_audio_rate") - self.waudio_rate = self.builder.get_object("audio_rate") - self.wframe_division_chapters = self.builder.get_object("frame_division_chapters") - - if (self.disc_type == "dvd") or (self.disc_type == "divx") or (self.disc_type == "mkv"): - self.waudio_rate.set_upper(448.0) - else: - self.waudio_rate.set_upper(384.0) - - # elements in page SUBTITLES - self.wsubtitles_list = self.builder.get_object("subtitles_list") - self.wtreview_subtitles = self.builder.get_object("treeview_subtitles") - self.wscrolledwindow_subtitles = self.builder.get_object("scrolledwindow_subtitles") - self.wadd_subtitles = self.builder.get_object("add_subtitles") - self.wdel_subtitles = self.builder.get_object("del_subtitles") - - selection = self.wtreview_subtitles.get_selection() - selection.set_mode(Gtk.SelectionMode.BROWSE) - - # elements in page VIDEO OPTIONS - self.wsize_1920x1080 = self.builder.get_object("size_1920x1080") - self.wsize_1280x720 = self.builder.get_object("size_1280x720") - self.wsize_1920x1080_ntsc = self.builder.get_object("size_1920x1080_ntsc") - self.wsize_1280x720_ntsc = self.builder.get_object("size_1280x720_ntsc") - self.wframe_final_size = self.builder.get_object("frame_final_size") - self.wframe_aspect_ratio = self.builder.get_object("frame_aspect_ratio") - self.waspect_classic = self.builder.get_object("aspect_classic") - self.waspect_wide = self.builder.get_object("aspect_wide") - self.wadd_black_bars_pic = self.builder.get_object("add_black_bars_pic") - self.wscale_picture_pic = self.builder.get_object("scale_picture_pic") - self.wcut_picture_pic = self.builder.get_object("cut_picture_pic") - - # elements in page AUDIO - self.wsound5_1 = self.builder.get_object("sound5_1") - self.wcopy_sound = self.builder.get_object("copy_sound") - - # Adjust the interface UI to the kind of disc - - if (self.disc_type == 'dvd'): - self.wsize_1920x1080.hide() - self.wsize_1280x720.hide() - self.wsize_1920x1080_ntsc.hide() - self.wsize_1280x720_ntsc.hide() - elif (self.disc_type == 'vcd'): - self.wshow_in_menu.hide() - self.wframe_video_rate.hide() - self.wframe_audio_rate.hide() - self.wframe_division_chapters.hide() - self.wframe_final_size.hide() - self.wframe_aspect_ratio.hide() - self.wsound5_1.hide() - self.wcopy_sound.hide() - self.wnotebook.remove_page(5) - elif (self.disc_type == 'svcd'): - self.wsize_1920x1080.hide() - self.wsize_1280x720.hide() - self.wsize_1920x1080_ntsc.hide() - self.wsize_1280x720_ntsc.hide() - self.wshow_in_menu.hide() - self.wframe_division_chapters.hide() - self.wframe_aspect_ratio.hide() - self.wsound5_1.hide() - self.wcopy_sound.hide() - self.wnotebook.remove_page(5) - elif (self.disc_type == 'cvd'): - self.wsize_1920x1080.hide() - self.wsize_1280x720.hide() - self.wsize_1920x1080_ntsc.hide() - self.wsize_1280x720_ntsc.hide() - self.wshow_in_menu.hide() - self.wframe_division_chapters.hide() - self.wframe_aspect_ratio.hide() - self.wsound5_1.hide() - self.wcopy_sound.hide() - self.wnotebook.remove_page(5) - elif (self.disc_type == 'divx'): - self.wshow_in_menu.hide() - self.wframe_division_chapters.hide() - self.wsound5_1.hide() - self.wcopy_sound.hide() - self.wnotebook.remove_page(5) - self.wnotebook.remove_page(1) - elif (self.disc_type == 'mkv'): - self.wshow_in_menu.hide() - self.wframe_division_chapters.hide() - self.wnotebook.remove_page(5) - - if self.list_files is None: - self.wframe_title.show() - self.wframe_fileinfo.show() - self.wframe_multiproperties.hide() - else: - self.wframe_title.hide() - self.wframe_fileinfo.hide() - self.wframe_multiproperties.show() - self.wscrolledwindow_subtitles.hide() - self.wbutton_preview.hide() - self.wadd_subtitles.hide() - self.wdel_subtitles.hide() - sel = self.wtreeview_multiproperties.get_selection() - sel.set_mode(Gtk.SelectionMode.MULTIPLE) - self.wtreeview_multiproperties.set_rubber_banding(True) - - - self.save_ui() - self.update_ui(self.builder) - self.on_aspect_classic_toggled(None) - self.on_treeview_subtitles_cursor_changed(None) - - - def on_aspect_classic_toggled(self,b): - - status1 = self.waspect_classic.get_active() - status2 = self.waspect_wide.get_active() - if (status1): - final_aspect = 4.0/3.0 - elif (status2): - final_aspect = 16.0/9.0 - else: - if self.original_aspect_ratio >= 1.7: - final_aspect = 16.0/9.0 - else: - final_aspect = 4.0/3.0 - if (final_aspect < self.original_aspect_ratio): - self.wadd_black_bars_pic.set_from_file(os.path.join(self.config.pic_path,"to_classic_blackbars.png")) - self.wcut_picture_pic.set_from_file(os.path.join(self.config.pic_path,"to_classic_cut.png")) - self.wscale_picture_pic.set_from_file(os.path.join(self.config.pic_path,"to_classic_scale.png")) - else: - self.wadd_black_bars_pic.set_from_file(os.path.join(self.config.pic_path,"to_wide_blackbars.png")) - self.wcut_picture_pic.set_from_file(os.path.join(self.config.pic_path,"to_wide_cut.png")) - self.wscale_picture_pic.set_from_file(os.path.join(self.config.pic_path,"to_wide_scale.png")) - - - def on_button_accept_clicked(self,b): - - self.store_ui(self.builder) - self.config.subt_fill_color = self.subt_fill_color - self.config.subt_outline_color = self.subt_outline_color - self.config.subt_outline_thickness = self.subt_thickness - if self.list_files is None: - # editing file properties - self.set_final_rates() - self.set_final_size_aspect() - self.emit('title_changed',self.title_name) - self.emit('in_menu_changed',self.show_in_menu) - else: - # editing properties for a group of files - data = self.store_file() - sel = self.wtreeview_multiproperties.get_selection() - model, pathlist = sel.get_selected_rows() - for file_path in pathlist: - obj = model[file_path][1] - obj.restore_file(data) - - self.wfile_properties.destroy() - self.wfile_properties = None - self.builder = None - - - def on_button_cancel_clicked(self,b): - - if self.list_files is None: - self.restore_ui() - - self.wfile_properties.destroy() - self.wfile_properties = None - self.builder = None - - - def on_add_subtitles_clicked(self,b): - - subt = devedeng.ask_subtitles.ask_subtitles() - if (subt.run()): - self.wsubtitles_list.append([subt.filename, subt.encoding, subt.language, subt.put_upper]) - - - def get_selected_subtitle(self): - - selection = self.wtreview_subtitles.get_selection() - model, treeiter = selection.get_selected() - - if treeiter is not None: - return ( (model, treeiter) ) - else: - return ( (None, None) ) - - - def on_del_subtitles_clicked(self,b): - - model, treeiter = self.get_selected_subtitle() - if (model is not None): - model.remove(treeiter) - - - def on_treeview_subtitles_cursor_changed(self,b): - - model, treeiter = self.get_selected_subtitle() - if (model is None): - self.wdel_subtitles.set_sensitive(False) - else: - self.wdel_subtitles.set_sensitive(True) - - - def do_conversion(self, output_path, duration = 0): - - self.converted_filename = output_path - if self.is_mpeg_ps: - converter = devedeng.file_copy.file_copy(self.file_name,output_path) - else: - self.set_final_size_aspect() - self.set_final_rates() - - cv = devedeng.converter.converter.get_converter() - disc_converter = cv.get_disc_converter() - converter = disc_converter() - converter.convert_file(self,output_path,duration) - - if len(self.subtitles_list) != 0: - last_process = converter - #if duration == 0: - # it seems that SPUMUX always fills the entire subtitles - duration2 = self.original_length - #else: - # duration2 = duration - stream_id = 0 - for subt in self.subtitles_list: - subt_file = subt[0] - subt_codepage = subt[1] - subt_lang = subt[2] - subt_upper = subt[3] - if self.aspect_ratio_final >= 1.7: - final_aspect = "16:9" - else: - final_aspect = "4:3" - subt_mux = devedeng.subtitles_mux.subtitles_mux() - subt_mux.multiplex_subtitles( output_path, subt_file, subt_codepage, subt_lang, subt_upper, - self.subt_font_size,self.format_pal,self.force_subtitles, - final_aspect, duration2, stream_id, - self.subt_fill_color, self.subt_outline_color, self.subt_thickness) - subt_mux.add_dependency(last_process) - converter.add_child_process(subt_mux) - last_process = subt_mux - stream_id += 1 - - return converter - - - def on_button_preview_clicked(self,b): - self.store_ui(self.builder) - self.do_preview() - - - def do_preview(self): - - wpreview = devedeng.preview.preview_window() - if (wpreview.run() == False): - return - - run_window = devedeng.runner.runner() - p = self.do_conversion(os.path.join(self.config.tmp_folder,"movie_preview.mpg"),wpreview.lvalue) - run_window.add_process(p) - run_window.connect("done",self.preview_done) - run_window.run() - - - def preview_done(self,o,retval): - - if (retval == 0): - cv = devedeng.converter.converter.get_converter() - disc_player = (cv.get_film_player())() - disc_player.play_film(os.path.join(self.config.tmp_folder,"movie_preview.mpg")) - - - def store_file(self): - - data = self.serialize() - if "files_to_set" in data: - del data["files_to_set"] - - return data - - - def restore_file(self,data): - - self.unserialize(data) - - - def on_select_all_clicked(self,b): - - sel = self.wtreeview_multiproperties.get_selection() - sel.select_all() - - - def on_unselect_all_clicked(self,b): - - sel = self.wtreeview_multiproperties.get_selection() - sel.unselect_all() + __gsignals__ = {'title_changed': (GObject.SIGNAL_RUN_FIRST, None, (str,)), 'in_menu_changed': ( + GObject.SIGNAL_RUN_FIRST, None, (bool,))} + + def __init__(self, file_name, list_files=None): + + self.list_files = list_files + + devedeng.interface_manager.interface_manager.__init__(self) + + self.wfile_properties = None + self.builder = None + + self.config = devedeng.configuration_data.configuration.get_config() + self.set_type(None, self.config.disc_type) + self.config.connect('disc_type', self.set_type) + + if list_files is None: + self.add_text("file_name", file_name) + self.add_text("title_name", os.path.splitext( + os.path.basename(file_name))[0]) + self.add_label("original_size", None) + self.add_label("original_length", None) + self.add_label("original_videorate", None) + self.add_label("original_audiorate", None) + self.add_label("original_aspect_ratio", None) + self.add_label("original_fps", None) + self.add_toggle("show_in_menu", True) + else: + self.original_aspect_ratio = 1.777 # dummy value + + self.add_text("chapter_list_entry", None) + + self.add_dualtoggle("format_pal", "format_ntsc", self.config.PAL) + self.add_toggle("video_rate_automatic", True) + self.add_toggle("audio_rate_automatic", True) + self.add_toggle("divide_in_chapters", True) + self.add_toggle("force_subtitles", False) + self.add_toggle("mirror_horizontal", False) + self.add_toggle("mirror_vertical", False) + self.add_toggle("two_pass_encoding", False) + self.add_toggle("sound5_1", False) + self.add_toggle("copy_sound", False) + self.add_toggle("is_mpeg_ps", False) + self.add_toggle("no_reencode_audio_video", False) + if (self.disc_type == "divx") or (self.disc_type == "mkv"): + self.add_toggle("gop12", False) + else: + self.add_toggle("gop12", True) + + self.add_group("final_size_pal", ["size_auto", "size_1920x1080", "size_1280x720", "size_720x576", + "size_704x576", "size_480x576", "size_352x576", "size_352x288"], "size_auto") + self.add_group("final_size_ntsc", ["size_auto_ntsc", "size_1920x1080_ntsc", "size_1280x720_ntsc", "size_720x480_ntsc", + "size_704x480_ntsc", "size_480x480_ntsc", "size_352x480_ntsc", "size_352x240_ntsc"], "size_auto_ntsc") + self.add_group("aspect_ratio", [ + "aspect_auto", "aspect_classic", "aspect_wide"], "aspect_auto") + self.add_group( + "scaling", ["add_black_bars", "scale_picture", "cut_picture"], "add_black_bars") + self.add_group("rotation", [ + "rotation_0", "rotation_90", "rotation_180", "rotation_270"], "rotation_0") + self.add_group("deinterlace", [ + "deinterlace_none", "deinterlace_ffmpeg", "deinterlace_yadif"], "deinterlace_none") + self.add_group("actions", ["action_stop", "action_play_first", "action_play_previous", + "action_play_again", "action_play_next", "action_play_last"], "action_stop") + + self.add_integer_adjustment("volume", 100) + if (self.disc_type == "dvd"): + self.add_integer_adjustment("video_rate", 5000) + elif (self.disc_type == "vcd"): + self.add_integer_adjustment("video_rate", 1152) + else: + self.add_integer_adjustment("video_rate", 2000) + + self.add_integer_adjustment("audio_rate", 224) + self.add_integer_adjustment("subt_font_size", 28) + self.add_float_adjustment("audio_delay", 0.0) + self.add_integer_adjustment("chapter_size", 5) + + self.add_colorbutton("subt_fill_color", self.config.subt_fill_color) + self.add_colorbutton("subt_outline_color", + self.config.subt_outline_color) + self.add_float_adjustment( + "subt_thickness", self.config.subt_outline_thickness) + + if list_files is None: + self.add_list("subtitles_list") + else: + self.add_list("files_to_set") + for e in list_files: + self.files_to_set.append([e.title_name, e]) + + self.add_show_hide("format_pal", ["size_pal"], ["size_ntsc"]) + + self.add_enable_disable("divide_in_chapters", [ + "chapter_size_spinbutton", "chapter_list_entry"], []) + self.add_enable_disable("video_rate_automatic", + [], ["video_spinbutton"]) + self.add_enable_disable("audio_rate_automatic", + [], ["audio_spinbutton"]) + self.add_enable_disable("sound5_1", ["copy_sound"], []) + + if (self.disc_type == "dvd"): + self.add_enable_disable("aspect_wide", [], ["size_704x576", "size_480x576", "size_352x576", "size_352x288", + "size_704x480_ntsc", "size_480x480_ntsc", "size_352x480_ntsc", "size_352x240_ntsc"]) + + self.add_enable_disable("copy_sound", [], ["audio_delay_spinbutton", "audio_rate_automatic", + "audio_spinbutton", "spinbutton_volume", "scale_volume", "reset_volume"]) + + common_elements = ["gop12", "video_rate_automatic", "video_spinbutton", "audio_rate_automatic", "audio_spinbutton", "format_pal", "format_ntsc", "spinbutton_volume", "scale_volume", "reset_volume", + "size_auto", "size_1920x1080", "size_1280x720", "size_720x576", "size_704x576", "size_480x576", "size_352x576", "size_352x288", + "size_auto_ntsc", "size_1920x1080_ntsc", "size_1280x720_ntsc", "size_720x480_ntsc", "size_704x480_ntsc", "size_480x480_ntsc", "size_352x480_ntsc", "size_352x240_ntsc", + "aspect_auto", "aspect_classic", "aspect_wide", "mirror_horizontal", "mirror_vertical", "add_black_bars", "scale_picture", "cut_picture", + "rotation_0", "rotation_90", "rotation_180", "rotation_270", "two_pass_encoding", "deinterlace_none", "deinterlace_ffmpeg", "deinterlace_yadif", + "audio_delay_spinbutton", "sound5_1", "copy_sound"] + + is_mpeg_ps_list = common_elements[:] + is_mpeg_ps_list.append("no_reencode_audio_video") + is_mpeg_ps_list.append("font_size_spinbutton") + is_mpeg_ps_list.append("force_subtitles") + is_mpeg_ps_list.append("add_subtitles") + is_mpeg_ps_list.append("del_subtitles") + no_reencode_audio_video_list = common_elements[:] + no_reencode_audio_video_list.append("is_mpeg_ps") + + self.add_enable_disable("is_mpeg_ps", [], is_mpeg_ps_list) + self.add_enable_disable("no_reencode_audio_video", + [], no_reencode_audio_video_list) + + if list_files is None: + cv = devedeng.converter.converter.get_converter() + film_analizer = (cv.get_film_analizer())() + if (film_analizer.get_film_data(self.file_name)): + self.error = True + else: + self.error = False + self.audio_list = film_analizer.audio_list[:] + self.video_list = film_analizer.video_list[:] + self.audio_streams = film_analizer.audio_streams + self.video_streams = film_analizer.video_streams + self.original_width = film_analizer.original_width + self.original_height = film_analizer.original_height + self.original_length = film_analizer.original_length + self.original_size = film_analizer.original_size + self.original_aspect_ratio = film_analizer.original_aspect_ratio + self.original_videorate = film_analizer.original_videorate + self.original_audiorate = film_analizer.original_audiorate + + self.original_audiorate_uncompressed = film_analizer.original_audiorate_uncompressed + self.original_fps = film_analizer.original_fps + self.original_file_size = film_analizer.original_file_size + + if self.original_audiorate <= 0: + # just a guess, but usually correct + self.original_audiorate = 224 + if self.original_videorate <= 0: + # presume that there are only video and audio streams + self.original_videorate = ((8 * self.original_file_size) / self.original_length) - ( + self.original_audiorate * self.audio_streams) + # to avoid division by zero when a clip is very short + if self.original_length <= 0: + self.original_length = 1 + + self.width_midle = -1 + self.height_midle = -1 + self.width_final = -1 + self.height_final = -1 + self.video_rate_auto = self.video_rate + self.audio_rate_auto = self.audio_rate + self.video_rate_final = self.video_rate + self.audio_rate_final = self.audio_rate + self.aspect_ratio_final = None + self.converted_filename = None + + def set_title(self, new_title): + self.title_name = new_title + self.emit('title_changed', self.title_name) + + def set_show_in_menu(self, show): + self.show_in_menu = show + self.emit('in_menu_changed', self.show_in_menu) + + def get_duration(self): + return self.original_length + + def get_estimated_size(self): + """ Returns the estimated final file size, in kBytes, based on the final audio and video rate, and the subtitles """ + + self.set_final_rates() + self.set_final_size_aspect() + + if self.is_mpeg_ps: + estimated_size = self.original_file_size / 1000 + else: + # let's asume 8kbps for each subtitle + sub_rate = 8 * len(self.subtitles_list) + estimated_size = ((self.video_rate_final + (self.audio_rate_final * + self.audio_streams) + sub_rate) * self.original_length) / 8 + + return estimated_size + + def get_size_data(self): + + estimated_size = self.get_estimated_size() + if self.is_mpeg_ps or self.no_reencode_audio_video: + videorate_fixed_size = True + else: + videorate_fixed_size = False + + # let's asume 8kbps for each subtitle + sub_rate = 8 * len(self.subtitles_list) + + return estimated_size, videorate_fixed_size, self.audio_rate_final * self.audio_streams, sub_rate, self.width_final, self.height_final, self.original_length + + def set_auto_video_audio_rate(self, new_video_rate, new_audio_rate): + + self.video_rate_auto = int(new_video_rate) + self.audio_rate_auto = int(new_audio_rate) + + def get_max_resolution(self, rx, ry, aspect): + + tmpx = ry * aspect + tmpy = rx / aspect + if (tmpx > rx): + return tmpx, ry + else: + return rx, tmpy + + def set_final_rates(self): + + if (self.disc_type == "divx") or (self.disc_type == "mkv"): + self.audio_rate_auto = 192 + elif (self.disc_type == "vcd") or (self.disc_type == "svcd") or (self.disc_type == "cvd"): + self.audio_rate_auto = 224 + else: # dvd + if self.sound5_1: + self.audio_rate_auto = 384 + else: + self.audio_rate_auto = 224 + + if self.is_mpeg_ps or self.no_reencode_audio_video: + self.video_rate_final = self.original_videorate + self.audio_rate_final = self.original_audiorate + else: + if self.video_rate_automatic: + self.video_rate_final = self.video_rate_auto + else: + self.video_rate_final = self.video_rate + + if self.copy_sound: + self.audio_rate_final = self.original_audiorate + else: + if self.audio_rate_automatic: + self.audio_rate_final = self.audio_rate_auto + else: + self.audio_rate_final = self.audio_rate + + def set_final_size_aspect(self): + + if self.is_mpeg_ps: + self.width_midle = self.original_width + self.width_final = self.original_width + self.height_midle = self.original_height + self.height_final = self.original_height + self.aspect_ratio_final = self.original_aspect_ratio + return + + if self.format_pal: + final_size = self.final_size_pal + else: + # remove the "_ntsc" from the string + final_size = self.final_size_ntsc[:-5] + + # for divx or matroska, if the size and the aspect ratio is automatic, + # just don't change them + if ((self.disc_type == "divx") or (self.disc_type == "mkv")) and (final_size == "size_auto") and (self.aspect_ratio == "aspect_auto"): + self.width_midle = self.original_width + self.width_final = self.original_width + self.height_midle = self.original_height + self.height_final = self.original_height + self.aspect_ratio_final = self.original_aspect_ratio + return + + # The steps are: + # - Decide the final aspect ratio + # - Calculate the midle size: the original video will be cut to this size, or black bars will be added + # - Calculate the final size: the midle video will be scaled to this size + + aspect_wide = False + # first, decide the final aspect ratio + if (self.disc_type == "vcd") or (self.disc_type == "svcd") or (self.disc_type == "cvd"): + self.aspect_ratio_final = 4.0 / 3.0 + else: + if (self.aspect_ratio == "aspect_auto"): + if (self.disc_type != "dvd"): + self.aspect_ratio_final = self.original_aspect_ratio + else: + if self.original_aspect_ratio >= 1.7: + self.aspect_ratio_final = 16.0 / 9.0 + aspect_wide = True + else: + self.aspect_ratio_final = 4.0 / 3.0 + elif (self.aspect_ratio == "aspect_classic"): + self.aspect_ratio_final = 4.0 / 3.0 + else: + self.aspect_ratio_final = 16.0 / 9.0 + aspect_wide = True + + # now, the final resolution + if self.disc_type == "vcd": + self.width_final = 352 + if (self.format_pal): + self.height_final = 288 + else: + self.height_final = 240 + else: + if final_size == "size_auto": + if self.disc_type == "svcd": + self.width_final = 480 + if (self.format_pal): + self.height_final = 576 + else: + self.height_final = 480 + elif self.disc_type == "cvd": + self.width_final = 352 + if (self.format_pal): + self.height_final = 576 + else: + self.height_final = 480 + elif self.disc_type == "dvd": + if aspect_wide: + self.width_final = 720 + if (self.format_pal): + self.height_final = 576 + else: + self.height_final = 480 + else: + tx, ty = self.get_max_resolution( + self.original_width, self.original_height, self.original_aspect_ratio) + if (self.format_pal): + th = 576 + th2 = 288 + else: + th = 480 + th2 = 240 + if (tx <= 352) and (ty <= th2): + self.width_final = 352 + self.height_final = th2 + elif (tx <= 352) and (ty <= th): + self.width_final = 352 + self.height_final = th + elif (tx <= 704) and (ty <= th): + self.width_final = 704 + self.height_final = th + else: + self.width_final = 720 + self.height_final = th + else: + self.width_final, self.height_final = self.get_max_resolution( + self.original_width, self.original_height, self.original_aspect_ratio) + else: + values = final_size[5:].split("x") + self.width_final = int(values[0]) + self.height_final = int(values[1]) + + self.width_final = int(self.width_final) + self.height_final = int(self.height_final) + + # finally, calculate the midle size + + if (self.rotation == "rotation_90") or (self.rotation == "rotation_270"): + midle_aspect_ratio = 1.0 / self.original_aspect_ratio + else: + midle_aspect_ratio = self.original_aspect_ratio + + if self.scaling == "scale_picture": + self.width_midle = int(self.original_width) + self.height_midle = int(self.original_height) + elif self.scaling == "add_black_bars": + if midle_aspect_ratio > self.aspect_ratio_final: # add horizontal black bars, at top and bottom + self.width_midle = int(self.original_width) + self.height_midle = int( + self.original_height * midle_aspect_ratio / self.aspect_ratio_final) + else: # add vertical black bars, at left and right + self.width_midle = int( + self.original_width * self.aspect_ratio_final / midle_aspect_ratio) + self.height_midle = int(self.original_height) + else: # cut picture + if midle_aspect_ratio > self.aspect_ratio_final: + self.width_midle = int( + self.original_width * self.aspect_ratio_final / midle_aspect_ratio) + self.height_midle = int(self.original_height) + else: + self.width_midle = int(self.original_width) + self.height_midle = int( + self.original_height * midle_aspect_ratio / self.aspect_ratio_final) + + def set_type(self, obj=None, disc_type=None): + + if (disc_type is not None): + self.disc_type = disc_type + + def delete_file(self): + + return + + def on_help_clicked(self, b): + + help_file = devedeng.help.help("file.html") + + def properties(self): + + if (self.wfile_properties is not None): + self.wfile_properties.present() + return + + self.builder = Gtk.Builder() + self.builder.set_translation_domain(self.config.gettext_domain) + + self.builder.add_from_file(os.path.join( + self.config.glade, "wfile_properties.ui")) + self.builder.connect_signals(self) + self.wfile_properties = self.builder.get_object("file_properties") + self.wfile_properties.show_all() + + self.wframe_title = self.builder.get_object("frame_title") + self.wframe_fileinfo = self.builder.get_object("frame_fileinfo") + self.wframe_multiproperties = self.builder.get_object( + "frame_multiproperties") + self.wtreeview_multiproperties = self.builder.get_object( + "treeview_multiproperties") + self.wbutton_preview = self.builder.get_object("button_preview") + + self.wshow_in_menu = self.builder.get_object("show_in_menu") + + self.wnotebook = self.builder.get_object("notebook") + + # elements in page GENERAL + self.wformat_pal = self.builder.get_object("format_pal") + self.wformat_ntsc = self.builder.get_object("format_ntsc") + self.wframe_video_rate = self.builder.get_object("frame_video_rate") + self.wframe_audio_rate = self.builder.get_object("frame_audio_rate") + self.waudio_rate = self.builder.get_object("audio_rate") + self.wframe_division_chapters = self.builder.get_object( + "frame_division_chapters") + + if (self.disc_type == "dvd") or (self.disc_type == "divx") or (self.disc_type == "mkv"): + self.waudio_rate.set_upper(448.0) + else: + self.waudio_rate.set_upper(384.0) + + # elements in page SUBTITLES + self.wsubtitles_list = self.builder.get_object("subtitles_list") + self.wtreview_subtitles = self.builder.get_object("treeview_subtitles") + self.wscrolledwindow_subtitles = self.builder.get_object( + "scrolledwindow_subtitles") + self.wadd_subtitles = self.builder.get_object("add_subtitles") + self.wdel_subtitles = self.builder.get_object("del_subtitles") + + selection = self.wtreview_subtitles.get_selection() + selection.set_mode(Gtk.SelectionMode.BROWSE) + + # elements in page VIDEO OPTIONS + self.wsize_1920x1080 = self.builder.get_object("size_1920x1080") + self.wsize_1280x720 = self.builder.get_object("size_1280x720") + self.wsize_1920x1080_ntsc = self.builder.get_object( + "size_1920x1080_ntsc") + self.wsize_1280x720_ntsc = self.builder.get_object( + "size_1280x720_ntsc") + self.wframe_final_size = self.builder.get_object("frame_final_size") + self.wframe_aspect_ratio = self.builder.get_object( + "frame_aspect_ratio") + self.waspect_classic = self.builder.get_object("aspect_classic") + self.waspect_wide = self.builder.get_object("aspect_wide") + self.wadd_black_bars_pic = self.builder.get_object( + "add_black_bars_pic") + self.wscale_picture_pic = self.builder.get_object("scale_picture_pic") + self.wcut_picture_pic = self.builder.get_object("cut_picture_pic") + + # elements in page AUDIO + self.wsound5_1 = self.builder.get_object("sound5_1") + self.wcopy_sound = self.builder.get_object("copy_sound") + + # Adjust the interface UI to the kind of disc + + if (self.disc_type == 'dvd'): + self.wsize_1920x1080.hide() + self.wsize_1280x720.hide() + self.wsize_1920x1080_ntsc.hide() + self.wsize_1280x720_ntsc.hide() + elif (self.disc_type == 'vcd'): + self.wshow_in_menu.hide() + self.wframe_video_rate.hide() + self.wframe_audio_rate.hide() + self.wframe_division_chapters.hide() + self.wframe_final_size.hide() + self.wframe_aspect_ratio.hide() + self.wsound5_1.hide() + self.wcopy_sound.hide() + self.wnotebook.remove_page(5) + elif (self.disc_type == 'svcd'): + self.wsize_1920x1080.hide() + self.wsize_1280x720.hide() + self.wsize_1920x1080_ntsc.hide() + self.wsize_1280x720_ntsc.hide() + self.wshow_in_menu.hide() + self.wframe_division_chapters.hide() + self.wframe_aspect_ratio.hide() + self.wsound5_1.hide() + self.wcopy_sound.hide() + self.wnotebook.remove_page(5) + elif (self.disc_type == 'cvd'): + self.wsize_1920x1080.hide() + self.wsize_1280x720.hide() + self.wsize_1920x1080_ntsc.hide() + self.wsize_1280x720_ntsc.hide() + self.wshow_in_menu.hide() + self.wframe_division_chapters.hide() + self.wframe_aspect_ratio.hide() + self.wsound5_1.hide() + self.wcopy_sound.hide() + self.wnotebook.remove_page(5) + elif (self.disc_type == 'divx'): + self.wshow_in_menu.hide() + self.wframe_division_chapters.hide() + self.wsound5_1.hide() + self.wcopy_sound.hide() + self.wnotebook.remove_page(5) + self.wnotebook.remove_page(1) + elif (self.disc_type == 'mkv'): + self.wshow_in_menu.hide() + self.wframe_division_chapters.hide() + self.wnotebook.remove_page(5) + + if self.list_files is None: + self.wframe_title.show() + self.wframe_fileinfo.show() + self.wframe_multiproperties.hide() + else: + self.wframe_title.hide() + self.wframe_fileinfo.hide() + self.wframe_multiproperties.show() + self.wscrolledwindow_subtitles.hide() + self.wbutton_preview.hide() + self.wadd_subtitles.hide() + self.wdel_subtitles.hide() + sel = self.wtreeview_multiproperties.get_selection() + sel.set_mode(Gtk.SelectionMode.MULTIPLE) + self.wtreeview_multiproperties.set_rubber_banding(True) + + self.save_ui() + self.update_ui(self.builder) + self.on_aspect_classic_toggled(None) + self.on_treeview_subtitles_cursor_changed(None) + + def on_aspect_classic_toggled(self, b): + + status1 = self.waspect_classic.get_active() + status2 = self.waspect_wide.get_active() + if (status1): + final_aspect = 4.0 / 3.0 + elif (status2): + final_aspect = 16.0 / 9.0 + else: + if self.original_aspect_ratio >= 1.7: + final_aspect = 16.0 / 9.0 + else: + final_aspect = 4.0 / 3.0 + if (final_aspect < self.original_aspect_ratio): + self.wadd_black_bars_pic.set_from_file(os.path.join( + self.config.pic_path, "to_classic_blackbars.png")) + self.wcut_picture_pic.set_from_file(os.path.join( + self.config.pic_path, "to_classic_cut.png")) + self.wscale_picture_pic.set_from_file(os.path.join( + self.config.pic_path, "to_classic_scale.png")) + else: + self.wadd_black_bars_pic.set_from_file(os.path.join( + self.config.pic_path, "to_wide_blackbars.png")) + self.wcut_picture_pic.set_from_file( + os.path.join(self.config.pic_path, "to_wide_cut.png")) + self.wscale_picture_pic.set_from_file( + os.path.join(self.config.pic_path, "to_wide_scale.png")) + + def on_button_accept_clicked(self, b): + + self.store_ui(self.builder) + self.config.subt_fill_color = self.subt_fill_color + self.config.subt_outline_color = self.subt_outline_color + self.config.subt_outline_thickness = self.subt_thickness + if self.list_files is None: + # editing file properties + self.set_final_rates() + self.set_final_size_aspect() + self.emit('title_changed', self.title_name) + self.emit('in_menu_changed', self.show_in_menu) + else: + # editing properties for a group of files + data = self.store_file() + sel = self.wtreeview_multiproperties.get_selection() + model, pathlist = sel.get_selected_rows() + for file_path in pathlist: + obj = model[file_path][1] + obj.restore_file(data) + + self.wfile_properties.destroy() + self.wfile_properties = None + self.builder = None + + def on_button_cancel_clicked(self, b): + + if self.list_files is None: + self.restore_ui() + + self.wfile_properties.destroy() + self.wfile_properties = None + self.builder = None + + def on_add_subtitles_clicked(self, b): + + subt = devedeng.ask_subtitles.ask_subtitles() + if (subt.run()): + self.wsubtitles_list.append( + [subt.filename, subt.encoding, subt.language, subt.put_upper]) + + def get_selected_subtitle(self): + + selection = self.wtreview_subtitles.get_selection() + model, treeiter = selection.get_selected() + + if treeiter is not None: + return ((model, treeiter)) + else: + return ((None, None)) + + def on_del_subtitles_clicked(self, b): + + model, treeiter = self.get_selected_subtitle() + if (model is not None): + model.remove(treeiter) + + def on_treeview_subtitles_cursor_changed(self, b): + + model, treeiter = self.get_selected_subtitle() + if (model is None): + self.wdel_subtitles.set_sensitive(False) + else: + self.wdel_subtitles.set_sensitive(True) + + def do_conversion(self, output_path, duration=0): + + self.converted_filename = output_path + if self.is_mpeg_ps: + converter = devedeng.file_copy.file_copy( + self.file_name, output_path) + else: + self.set_final_size_aspect() + self.set_final_rates() + + cv = devedeng.converter.converter.get_converter() + disc_converter = cv.get_disc_converter() + converter = disc_converter() + converter.convert_file(self, output_path, duration) + + if len(self.subtitles_list) != 0: + last_process = converter + # if duration == 0: + # it seems that SPUMUX always fills the entire subtitles + duration2 = self.original_length + # else: + # duration2 = duration + stream_id = 0 + for subt in self.subtitles_list: + subt_file = subt[0] + subt_codepage = subt[1] + subt_lang = subt[2] + subt_upper = subt[3] + if self.aspect_ratio_final >= 1.7: + final_aspect = "16:9" + else: + final_aspect = "4:3" + subt_mux = devedeng.subtitles_mux.subtitles_mux() + subt_mux.multiplex_subtitles(output_path, subt_file, subt_codepage, subt_lang, subt_upper, + self.subt_font_size, self.format_pal, self.force_subtitles, + final_aspect, duration2, stream_id, + self.subt_fill_color, self.subt_outline_color, self.subt_thickness) + subt_mux.add_dependency(last_process) + converter.add_child_process(subt_mux) + last_process = subt_mux + stream_id += 1 + + return converter + + def on_button_preview_clicked(self, b): + self.store_ui(self.builder) + self.do_preview() + + def do_preview(self): + + wpreview = devedeng.preview.preview_window() + if (wpreview.run() == False): + return + + run_window = devedeng.runner.runner() + p = self.do_conversion(os.path.join( + self.config.tmp_folder, "movie_preview.mpg"), wpreview.lvalue) + run_window.add_process(p) + run_window.connect("done", self.preview_done) + run_window.run() + + def preview_done(self, o, retval): + + if (retval == 0): + cv = devedeng.converter.converter.get_converter() + disc_player = (cv.get_film_player())() + disc_player.play_film(os.path.join( + self.config.tmp_folder, "movie_preview.mpg")) + + def store_file(self): + + data = self.serialize() + if "files_to_set" in data: + del data["files_to_set"] + + return data + + def restore_file(self, data): + + self.unserialize(data) + + def on_select_all_clicked(self, b): + + sel = self.wtreeview_multiproperties.get_selection() + sel.select_all() + + def on_unselect_all_clicked(self, b): + + sel = self.wtreeview_multiproperties.get_selection() + sel.unselect_all() diff --git a/src/devedeng/genisoimage.py b/src/devedeng/genisoimage.py index 363c2a2..a565097 100644 --- a/src/devedeng/genisoimage.py +++ b/src/devedeng/genisoimage.py @@ -22,6 +22,7 @@ import devedeng.configuration_data import subprocess import devedeng.executor + class genisoimage(devedeng.executor.executor): supports_analize = False @@ -35,9 +36,10 @@ class genisoimage(devedeng.executor.executor): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["genisoimage","--help"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["genisoimage", "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -49,12 +51,12 @@ class genisoimage(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def create_iso (self, path, name): + def create_iso(self, path, name): - filesystem_path = os.path.join(path,"dvd_tree") - final_path = os.path.join(path,name+".iso") + filesystem_path = os.path.join(path, "dvd_tree") + final_path = os.path.join(path, name + ".iso") - self.command_var=[] + self.command_var = [] self.command_var.append("genisoimage") self.command_var.append("-dvd-video") self.command_var.append("-V") @@ -66,18 +68,17 @@ class genisoimage(devedeng.executor.executor): self.command_var.append(filesystem_path) self.text = _("Creating ISO image") - - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): if (data[0].find("% done") == -1): return l = data[0].split("%") p = float(l[0]) - self.progress_bar[1].set_fraction(p/100.0) + self.progress_bar[1].set_fraction(p / 100.0) self.progress_bar[1].set_text("%.1f%%" % (p)) return diff --git a/src/devedeng/help.py b/src/devedeng/help.py index 796bd9e..dfae777 100644 --- a/src/devedeng/help.py +++ b/src/devedeng/help.py @@ -1,17 +1,20 @@ #!/usr/bin/env python3 -from gi.repository import Gtk,Gdk +from gi.repository import Gtk, Gdk import devedeng.configuration_data import os + class help: - - def __init__(self,help_page): + + def __init__(self, help_page): self.config = devedeng.configuration_data.configuration.get_config() - file="file://"+os.path.join(self.config.help_path,"html",help_page) + file = "file://" + \ + os.path.join(self.config.help_path, "html", help_page) - retval = Gtk.show_uri(None,file,Gdk.CURRENT_TIME) + retval = Gtk.show_uri(None, file, Gdk.CURRENT_TIME) if retval == False: - msg=devede_dialogs.show_error(gladefile,_("Can't open the help files.")) + msg = devede_dialogs.show_error( + gladefile, _("Can't open the help files.")) diff --git a/src/devedeng/interface_manager.py b/src/devedeng/interface_manager.py index 08d1f64..b49a06d 100644 --- a/src/devedeng/interface_manager.py +++ b/src/devedeng/interface_manager.py @@ -15,7 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from gi.repository import GObject,Gdk +from gi.repository import GObject, Gdk + class interface_manager(GObject.GObject): """ This class allows to automatically generate variables for a GLADE interface, @@ -40,111 +41,112 @@ class interface_manager(GObject.GObject): self.interface_filebuttons = [] self.interface_comboboxes = [] - def add_group(self,group_name,radiobutton_list,default_value,callback = None): + def add_group(self, group_name, radiobutton_list, default_value, callback=None): """ Adds a group of radiobuttons and creates an internal variable with the name group_name, setting it to default_value. The value for the variable will be the name of the active radiobutton """ if (default_value is not None): - exec('self.'+group_name+' = "'+str(default_value)+'"') + exec('self.' + group_name + ' = "' + str(default_value) + '"') else: - exec('self.'+group_name+' = None') - self.interface_groups[group_name] = ( radiobutton_list, callback ) + exec('self.' + group_name + ' = None') + self.interface_groups[group_name] = (radiobutton_list, callback) - def add_toggle(self,toggle_name,default_value,callback = None): + def add_toggle(self, toggle_name, default_value, callback=None): """ Adds an internal variable with the name toggle_name, linked to a widget element with the same name (must be or inherint from Gtk.ToogleButton). The default value can be True of False """ - exec('self.'+toggle_name+' = '+str(default_value)) - self.interface_toggles.append( (toggle_name, callback) ) + exec('self.' + toggle_name + ' = ' + str(default_value)) + self.interface_toggles.append((toggle_name, callback)) - def add_dualtoggle(self,toggle_name,toggle2,default_value,callback = None): + def add_dualtoggle(self, toggle_name, toggle2, default_value, callback=None): """ Adds an internal variable with the name toggle_name, linked to widget elements with names toggle_name and toggle2 (must be or inherint from Gtk.ToogleButton). The default value can be True of False, with True being toggle_name active, and False being toggle2 active """ - exec('self.'+toggle_name+' = '+str(default_value)) - self.interface_dualtoggles.append( (toggle_name, toggle2, callback) ) + exec('self.' + toggle_name + ' = ' + str(default_value)) + self.interface_dualtoggles.append((toggle_name, toggle2, callback)) - def add_text(self,text_name,default_value,callback = None): + def add_text(self, text_name, default_value, callback=None): """ Adds an internal variable with the name text_name, linked to an element with the same name (must be a Gtk.TextEntry or a Gtk.Label). The default value can be a text or None """ if (default_value is not None): - exec('self.'+text_name+' = "'+str(default_value).replace('\"','\\"')+'"') + exec('self.' + text_name + ' = "' + + str(default_value).replace('\"', '\\"') + '"') else: - exec('self.'+text_name+' = None') - self.interface_text.append( (text_name, callback) ) + exec('self.' + text_name + ' = None') + self.interface_text.append((text_name, callback)) - def add_label(self,text_name,default_value): + def add_label(self, text_name, default_value): """ Adds an internal variable with the name text_name, linked to an element with the same name (must be a Gtk.TextEntry or a Gtk.Label). The default value can be a text or None. This element is copied to the UI, but is never updated from the UI if the user changes it """ - exec('self.'+text_name+' = default_value') + exec('self.' + text_name + ' = default_value') self.interface_labels.append(text_name) - def add_integer_adjustment(self,adjustment_name,default_value,callback = None): + def add_integer_adjustment(self, adjustment_name, default_value, callback=None): """ Adds an internal variable with the name text_name, linked to an element with the same name (must be a Gtk.Adjustment). The default value must be an integer """ - exec('self.'+adjustment_name+' = '+str(default_value)) - self.interface_integer_adjustments.append( (adjustment_name, callback) ) + exec('self.' + adjustment_name + ' = ' + str(default_value)) + self.interface_integer_adjustments.append((adjustment_name, callback)) - def add_float_adjustment(self,adjustment_name,default_value,callback = None): + def add_float_adjustment(self, adjustment_name, default_value, callback=None): """ Adds an internal variable with the name text_name, linked to an element with the same name (must be a Gtk.Adjustment). The default value must be an float """ - exec('self.'+adjustment_name+' = '+str(default_value)) - self.interface_float_adjustments.append( (adjustment_name, callback)) + exec('self.' + adjustment_name + ' = ' + str(default_value)) + self.interface_float_adjustments.append((adjustment_name, callback)) - def add_list(self,liststore_name,callback = None): + def add_list(self, liststore_name, callback=None): """ Adds an internal variable with the name liststore_name, linked to an element with the same name (must be a Gtk.ListStore). """ - exec('self.'+liststore_name+' = []') - self.interface_lists.append( (liststore_name, callback )) + exec('self.' + liststore_name + ' = []') + self.interface_lists.append((liststore_name, callback)) - def add_colorbutton(self,colorbutton_name, default_value,callback = None): + def add_colorbutton(self, colorbutton_name, default_value, callback=None): """ Adds an internal variable with the name colorbutton_name, linked to an element with the same name (must be a Gtk.ColorButton). The default value must be a set with RGBA values """ - exec('self.'+colorbutton_name+' = default_value') - self.interface_colorbuttons.append( (colorbutton_name, callback )) + exec('self.' + colorbutton_name + ' = default_value') + self.interface_colorbuttons.append((colorbutton_name, callback)) - def add_fontbutton(self,fontbutton_name, default_value, callback = None): + def add_fontbutton(self, fontbutton_name, default_value, callback=None): """ Adds an internal variable with the name fontbutton_name, linked to an element with the same name (must be a Gtk.FontButton). The default value must be a string with the font values """ - exec('self.'+fontbutton_name+' = default_value') - self.interface_fontbuttons.append( (fontbutton_name, callback )) + exec('self.' + fontbutton_name + ' = default_value') + self.interface_fontbuttons.append((fontbutton_name, callback)) - def add_filebutton(self,filebutton_name, default_value, callback = None): + def add_filebutton(self, filebutton_name, default_value, callback=None): """ Adds an internal variable with the name filebutton_name, linked to an element with the same name (must be a Gtk.FileButton). The default value must be a string with the font values """ - exec('self.'+filebutton_name+' = default_value') - self.interface_filebuttons.append( (filebutton_name, callback ) ) + exec('self.' + filebutton_name + ' = default_value') + self.interface_filebuttons.append((filebutton_name, callback)) - def add_combobox(self,combobox_name,values,default_value,callback = None): + def add_combobox(self, combobox_name, values, default_value, callback=None): """ Adds an internal variable with the name combobox_name, linked to an element with the same name (must be a Gtk.Combobox). The default value must be an integer with the entry selected """ - exec('self.'+combobox_name+' = default_value') - self.interface_comboboxes.append ( (combobox_name, values, callback) ) + exec('self.' + combobox_name + ' = default_value') + self.interface_comboboxes.append((combobox_name, values, callback)) - def add_show_hide(self,element_name,to_show,to_hide): + def add_show_hide(self, element_name, to_show, to_hide): """ Adds an element that can be active or inactive, and two lists of elements. The first one contains elements that will be visible when the element is active, and invisible when it is inactive, and the second one contains @@ -153,37 +155,38 @@ class interface_manager(GObject.GObject): self.interface_show_hide.append([element_name, to_show, to_hide]) - def add_enable_disable(self,element_name,to_enable,to_disable): + def add_enable_disable(self, element_name, to_enable, to_disable): """ Adds an element that can be active or inactive, and two lists of elements. The first one contains elements that will be enabled when the element is active, and disabled when it is inactive, and the second one contains elements that will be enabled when the element is inactive, and disabled when the element is active """ - self.interface_enable_disable.append([element_name, to_enable, to_disable]) + self.interface_enable_disable.append( + [element_name, to_enable, to_disable]) - def update_ui(self,builder): + def update_ui(self, builder): """ Sets the value of the widgets in base of the internal variables """ for key in self.interface_groups: - obj = eval('self.'+key) + obj = eval('self.' + key) builder.get_object(obj).set_active(True) callback = self.interface_groups[key][1] if (callback is not None): for element in self.interface_groups[key][0]: obj = builder.get_object(element) - obj.connect("toggled",callback) + obj.connect("toggled", callback) for element in self.interface_toggles: - value = eval('self.'+element[0]) + value = eval('self.' + element[0]) obj = builder.get_object(element[0]) obj.set_active(value) callback = element[1] if (callback is not None): - obj.connect("toggled",callback) + obj.connect("toggled", callback) for element in self.interface_dualtoggles: - value = eval('self.'+element[0]) + value = eval('self.' + element[0]) obj = builder.get_object(element[0]) obj2 = builder.get_object(element[1]) if value: @@ -192,10 +195,10 @@ class interface_manager(GObject.GObject): obj2.set_active(True) callback = element[2] if (callback is not None): - obj.connect("toggled",callback) + obj.connect("toggled", callback) for element in self.interface_text: - value = eval('self.'+element[0]) + value = eval('self.' + element[0]) obj = builder.get_object(element[0]) if (value is not None): obj.set_text(value) @@ -203,10 +206,10 @@ class interface_manager(GObject.GObject): obj.set_text("") callback = element[1] if (callback is not None): - obj.connect("changed",callback) + obj.connect("changed", callback) for element in self.interface_labels: - value = eval('self.'+element) + value = eval('self.' + element) obj = builder.get_object(element) if obj is not None: if (value is not None): @@ -217,64 +220,65 @@ class interface_manager(GObject.GObject): for element in self.interface_integer_adjustments: obj = builder.get_object(element[0]) if obj is not None: - value = eval('self.'+element[0]) + value = eval('self.' + element[0]) obj.set_value(float(value)) callback = element[1] if (callback is not None): - obj.connect("value_changed",callback) + obj.connect("value_changed", callback) for element in self.interface_float_adjustments: obj = builder.get_object(element[0]) if obj is not None: - value = eval('self.'+element[0]) + value = eval('self.' + element[0]) obj.set_value(value) callback = element[1] if (callback is not None): - obj.connect("value_changed",callback) + obj.connect("value_changed", callback) for element in self.interface_lists: - obj = eval('self.'+element[0]) + obj = eval('self.' + element[0]) the_liststore = builder.get_object(element[0]) the_liststore.clear() for item in obj: the_liststore.append(item) callback = element[1] if (callback is not None): - the_liststore.connect("row_changed",callback) - the_liststore.connect("row_deleted",callback) - the_liststore.connect("row_inserted",callback) - the_liststore.connect("row_reordered",callback) + the_liststore.connect("row_changed", callback) + the_liststore.connect("row_deleted", callback) + the_liststore.connect("row_inserted", callback) + the_liststore.connect("row_reordered", callback) for element in self.interface_colorbuttons: - value = eval('self.'+element[0]) + value = eval('self.' + element[0]) obj = builder.get_object(element[0]) - objcolor = Gdk.Color(int(value[0]*65535.0),int(value[1]*65535.0),int(value[2]*65535.0)) + objcolor = Gdk.Color( + int(value[0] * 65535.0), int(value[1] * 65535.0), int(value[2] * 65535.0)) obj.set_color(objcolor) - obj.set_alpha(int(value[3]*65535.0)) + obj.set_alpha(int(value[3] * 65535.0)) callback = element[1] if (callback is not None): - obj.connect("color_set",callback) + obj.connect("color_set", callback) for element in self.interface_fontbuttons: - value = eval('self.'+element[0]) + value = eval('self.' + element[0]) obj = builder.get_object(element[0]) if (value is not None): obj.set_font(value) callback = element[1] if (callback is not None): - obj.connect("font_set",callback) + obj.connect("font_set", callback) for element in self.interface_filebuttons: - value = eval('self.'+element[0]) + value = eval('self.' + element[0]) obj = builder.get_object(element[0]) if (value is not None): obj.set_filename(value) callback = element[1] if (callback is not None): - obj.connect("file_set",callback) + obj.connect("file_set", callback) for element in self.interface_comboboxes: - obj = eval('self.'+element[0]) + obj = eval('self.' + element[0]) the_combo = builder.get_object(element[0]) the_list = the_combo.get_model() the_list.clear() @@ -288,7 +292,7 @@ class interface_manager(GObject.GObject): the_combo.set_active(dv) callback = element[2] if (callback is not None): - the_combo.connect("changed",callback) + the_combo.connect("changed", callback) self.interface_show_hide_obj = {} for element in self.interface_show_hide: @@ -300,7 +304,7 @@ class interface_manager(GObject.GObject): for e3 in element[2]: to_hide.append(builder.get_object(e3)) self.interface_show_hide_obj[obj] = [to_show, to_hide] - obj.connect('toggled',self.toggled_element) + obj.connect('toggled', self.toggled_element) self.toggled_element(obj) self.interface_enable_disable_obj = {} @@ -313,11 +317,10 @@ class interface_manager(GObject.GObject): for e3 in element[2]: to_disable.append(builder.get_object(e3)) self.interface_enable_disable_obj[obj] = [to_enable, to_disable] - obj.connect('toggled',self.toggled_element2) + obj.connect('toggled', self.toggled_element2) self.toggled_element2(obj) - - def toggled_element(self,element): + def toggled_element(self, element): """ Wenever an element with 'hide' or 'show' needs is toggled, this callback is called """ # First, show all items for each possible element @@ -337,7 +340,8 @@ class interface_manager(GObject.GObject): # And now, hide all items that must be hiden # This is done this way because this allows to have an item being hiden by - # one widget, and being shown by another: in that case, it will be hiden always + # one widget, and being shown by another: in that case, it will be + # hiden always for key in self.interface_show_hide_obj: to_show = self.interface_show_hide_obj[key][0] to_hide = self.interface_show_hide_obj[key][1] @@ -352,8 +356,7 @@ class interface_manager(GObject.GObject): if active: item.hide() - - def toggled_element2(self,element): + def toggled_element2(self, element): """ Wenever an element with 'enable' or 'disable' needs is toggled, this callback is called """ # First enable all items that must be enabled @@ -371,7 +374,8 @@ class interface_manager(GObject.GObject): # And now, disable all items that must be disabled # This is done this way because this allows to have an item being disabled by - # one widget, and being enabled by another: in that case, it will be disabled always + # one widget, and being enabled by another: in that case, it will be + # disabled always for key in self.interface_enable_disable_obj: to_enable = self.interface_enable_disable_obj[key][0] to_disable = self.interface_enable_disable_obj[key][1] @@ -384,126 +388,124 @@ class interface_manager(GObject.GObject): for item in to_disable: item.set_sensitive(False) - - def store_ui(self,builder): + def store_ui(self, builder): """ Takes the values of the widgets and stores them in the internal variables """ for key in self.interface_groups: for element in self.interface_groups[key][0]: obj = builder.get_object(element) if obj.get_active(): - exec('self.'+key+' = "'+element+'"') + exec('self.' + key + ' = "' + element + '"') break for element in self.interface_toggles: obj = builder.get_object(element[0]) if obj.get_active(): - exec('self.'+element[0]+' = True') + exec('self.' + element[0] + ' = True') else: - exec('self.'+element[0]+' = False') + exec('self.' + element[0] + ' = False') for element in self.interface_dualtoggles: obj = builder.get_object(element[0]) if obj.get_active(): - exec('self.'+element[0]+' = True') + exec('self.' + element[0] + ' = True') else: - exec('self.'+element[0]+' = False') + exec('self.' + element[0] + ' = False') for element in self.interface_text: obj = builder.get_object(element[0]) - exec('self.'+element[0]+' = obj.get_text()') + exec('self.' + element[0] + ' = obj.get_text()') for element in self.interface_integer_adjustments: obj = builder.get_object(element[0]) if obj is not None: - exec('self.'+element[0]+' = int(obj.get_value())') + exec('self.' + element[0] + ' = int(obj.get_value())') for element in self.interface_float_adjustments: obj = builder.get_object(element[0]) if obj is not None: - exec('self.'+element[0]+' = obj.get_value()') + exec('self.' + element[0] + ' = obj.get_value()') for element in self.interface_colorbuttons: obj = builder.get_object(element[0]) objcolor = obj.get_color() alpha = obj.get_alpha() - exec('self.'+element[0]+' = ((float(objcolor.red))/65535.0, (float(objcolor.green))/65535.0, (float(objcolor.blue))/65535.0, (float(alpha))/65535.0)') + exec( + 'self.' + element[0] + ' = ((float(objcolor.red))/65535.0, (float(objcolor.green))/65535.0, (float(objcolor.blue))/65535.0, (float(alpha))/65535.0)') for element in self.interface_fontbuttons: obj = builder.get_object(element[0]) - exec('self.'+element[0]+' = obj.get_font()') + exec('self.' + element[0] + ' = obj.get_font()') for element in self.interface_filebuttons: obj = builder.get_object(element[0]) - exec('self.'+element[0]+' = obj.get_filename()') + exec('self.' + element[0] + ' = obj.get_filename()') for element in self.interface_lists: - exec('self.'+element[0]+' = []') + exec('self.' + element[0] + ' = []') the_liststore = builder.get_object(element[0]) ncolumns = the_liststore.get_n_columns() for row in the_liststore: final_row = [] - for c in range(0,ncolumns): + for c in range(0, ncolumns): final_row.append(row.model[row.iter][c]) - exec('self.'+element[0]+'.append(final_row)') + exec('self.' + element[0] + '.append(final_row)') for element in self.interface_comboboxes: obj = builder.get_object(element[0]) - exec('self.'+element[0]+' = element[1][obj.get_active()]') - + exec('self.' + element[0] + ' = element[1][obj.get_active()]') def save_ui(self): """ Makes a copy of all the UI variables """ for element in self.interface_groups: - exec('self.'+element+'_backup = self.'+element) + exec('self.' + element + '_backup = self.' + element) for element in self.interface_toggles: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_dualtoggles: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_text: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_integer_adjustments: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_float_adjustments: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_colorbuttons: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_fontbuttons: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_filebuttons: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_lists: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) for element in self.interface_comboboxes: - exec('self.'+element[0]+'_backup = self.'+element[0]) + exec('self.' + element[0] + '_backup = self.' + element[0]) def restore_ui(self): """ Restores a copy of all the UI variables """ for element in self.interface_groups: - exec('self.'+element+' = self.'+element+'_backup') + exec('self.' + element + ' = self.' + element + '_backup') for element in self.interface_toggles: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_dualtoggles: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_text: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_integer_adjustments: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_float_adjustments: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_colorbuttons: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_fontbuttons: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_filebuttons: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_lists: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') for element in self.interface_comboboxes: - exec('self.'+element[0]+' = self.'+element[0]+'_backup') - + exec('self.' + element[0] + ' = self.' + element[0] + '_backup') def serialize(self): """ Returns a dictionary with both the variables of the interface and its values, @@ -512,65 +514,74 @@ class interface_manager(GObject.GObject): output = {} for element in self.interface_groups: - output[element] = eval('self.'+element) + output[element] = eval('self.' + element) for element in self.interface_toggles: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_dualtoggles: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_text: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_integer_adjustments: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_float_adjustments: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_colorbuttons: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_fontbuttons: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_filebuttons: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_lists: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) for element in self.interface_comboboxes: - output[element[0]] = eval('self.'+element[0]) + output[element[0]] = eval('self.' + element[0]) return output - - def unserialize(self,data_list): + def unserialize(self, data_list): """ Takes a dictionary with the variables of the interface and its values, and restores them into their variables """ for element in self.interface_groups: if element in data_list: - exec('self.'+element+' = data_list["'+element+'"]') + exec('self.' + element + ' = data_list["' + element + '"]') for element in self.interface_toggles: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_dualtoggles: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_text: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_integer_adjustments: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_float_adjustments: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_colorbuttons: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_fontbuttons: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_filebuttons: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_lists: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') for element in self.interface_comboboxes: if element[0] in data_list: - exec('self.'+element[0]+' = data_list["'+element[0]+'"]') + exec('self.' + element[0] + + ' = data_list["' + element[0] + '"]') diff --git a/src/devedeng/k3b.py b/src/devedeng/k3b.py index d564dc7..7974662 100644 --- a/src/devedeng/k3b.py +++ b/src/devedeng/k3b.py @@ -19,6 +19,7 @@ import subprocess import devedeng.configuration_data import devedeng.executor + class k3b(devedeng.executor.executor): supports_analize = False @@ -32,9 +33,10 @@ class k3b(devedeng.executor.executor): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["k3b","--help"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["k3b", "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -46,12 +48,12 @@ class k3b(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def burn(self,file_name): + def burn(self, file_name): self.command_var = ["k3b", file_name] - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): return diff --git a/src/devedeng/message.py b/src/devedeng/message.py index 9b873eb..4d8bd9d 100644 --- a/src/devedeng/message.py +++ b/src/devedeng/message.py @@ -19,16 +19,17 @@ from gi.repository import Gtk import os import devedeng.configuration_data + class message_window: - def __init__(self,text,title,list_data = None): + def __init__(self, text, title, list_data=None): self.config = devedeng.configuration_data.configuration.get_config() builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wmessage.ui")) + builder.add_from_file(os.path.join(self.config.glade, "wmessage.ui")) builder.connect_signals(self) wmessage_window = builder.get_object("dialog_message") wmessage_window.set_title(title) diff --git a/src/devedeng/mkisofs.py b/src/devedeng/mkisofs.py index 8f925c8..d32cd26 100644 --- a/src/devedeng/mkisofs.py +++ b/src/devedeng/mkisofs.py @@ -22,6 +22,7 @@ import devedeng.configuration_data import subprocess import devedeng.executor + class mkisofs(devedeng.executor.executor): supports_analize = False @@ -35,9 +36,10 @@ class mkisofs(devedeng.executor.executor): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["mkisofs","--help"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["mkisofs", "--help"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -49,12 +51,12 @@ class mkisofs(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def create_iso (self, path, name): + def create_iso(self, path, name): - filesystem_path = os.path.join(path,"dvd_tree") - final_path = os.path.join(path,name+".iso") + filesystem_path = os.path.join(path, "dvd_tree") + final_path = os.path.join(path, name + ".iso") - self.command_var=[] + self.command_var = [] self.command_var.append("mkisofs") self.command_var.append("-dvd-video") self.command_var.append("-V") @@ -66,18 +68,17 @@ class mkisofs(devedeng.executor.executor): self.command_var.append(filesystem_path) self.text = _("Creating ISO image") - - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): if (data[0].find("% done") == -1): return l = data[0].split("%") p = float(l[0]) - self.progress_bar[1].set_fraction(p/100.0) + self.progress_bar[1].set_fraction(p / 100.0) self.progress_bar[1].set_text("%.1f%%" % (p)) return diff --git a/src/devedeng/mplayer.py b/src/devedeng/mplayer.py index 4c2c2ef..091e4d5 100644 --- a/src/devedeng/mplayer.py +++ b/src/devedeng/mplayer.py @@ -22,6 +22,7 @@ import devedeng.configuration_data import devedeng.executor import os + class mplayer(devedeng.executor.executor): supports_analize = False @@ -35,9 +36,10 @@ class mplayer(devedeng.executor.executor): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["mplayer","-v"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["mplayer", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -49,13 +51,13 @@ class mplayer(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def play_film(self,file_name): + def play_film(self, file_name): command_line = ["mplayer", file_name] self.launch_process(command_line) - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): return diff --git a/src/devedeng/mpv.py b/src/devedeng/mpv.py index 5359526..3655ef4 100644 --- a/src/devedeng/mpv.py +++ b/src/devedeng/mpv.py @@ -21,6 +21,7 @@ import subprocess import devedeng.configuration_data import devedeng.executor + class mpv(devedeng.executor.executor): supports_analize = False @@ -34,9 +35,10 @@ class mpv(devedeng.executor.executor): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["mpv","-v"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["mpv", "-v"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -48,13 +50,13 @@ class mpv(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def play_film(self,file_name): + def play_film(self, file_name): command_line = ["mpv", file_name] self.launch_process(command_line) - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): return diff --git a/src/devedeng/mux_dvd_menu.py b/src/devedeng/mux_dvd_menu.py index bc0bd09..e8e62e1 100644 --- a/src/devedeng/mux_dvd_menu.py +++ b/src/devedeng/mux_dvd_menu.py @@ -21,6 +21,7 @@ import os import devedeng.configuration_data import devedeng.executor + class mux_dvd_menu(devedeng.executor.executor): def __init__(self): @@ -28,21 +29,22 @@ class mux_dvd_menu(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def create_mpg(self,n_page,output_path,movie_path): + def create_mpg(self, n_page, output_path, movie_path): self.n_page = n_page self.text = _("Mixing menu %(X)d") % {"X": self.n_page} - final_path = os.path.join(output_path,"menu_"+str(n_page)+"B.mpg") + final_path = os.path.join(output_path, "menu_" + str(n_page) + "B.mpg") - self.command_var=[] + self.command_var = [] self.command_var.append("spumux") - self.command_var.append(os.path.join(output_path,"menu_"+str(n_page)+".xml")) + self.command_var.append(os.path.join( + output_path, "menu_" + str(n_page) + ".xml")) self.stdin_file = movie_path self.stdout_file = final_path return final_path - def process_stderr(self,data): + def process_stderr(self, data): - return \ No newline at end of file + return diff --git a/src/devedeng/opensave.py b/src/devedeng/opensave.py index 8b3352d..ceb7770 100644 --- a/src/devedeng/opensave.py +++ b/src/devedeng/opensave.py @@ -19,6 +19,7 @@ from gi.repository import Gtk import os import devedeng.configuration_data + class opensave_window: def __init__(self, save): @@ -26,26 +27,27 @@ class opensave_window: self.config = devedeng.configuration_data.configuration.get_config() self.save = save - - def run(self,current_file = None): + def run(self, current_file=None): builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) if self.save: - builder.add_from_file(os.path.join(self.config.glade,"wsave_project.ui")) + builder.add_from_file(os.path.join( + self.config.glade, "wsave_project.ui")) else: - builder.add_from_file(os.path.join(self.config.glade,"wopen_project.ui")) + builder.add_from_file(os.path.join( + self.config.glade, "wopen_project.ui")) builder.connect_signals(self) w_window = builder.get_object("data_project") if current_file is not None: w_window.set_filename(current_file) - file_filter_projects=Gtk.FileFilter() + file_filter_projects = Gtk.FileFilter() file_filter_projects.set_name(_("DevedeNG projects")) file_filter_projects.add_pattern("*.devedeng") - file_filter_all=Gtk.FileFilter() + file_filter_all = Gtk.FileFilter() file_filter_all.set_name(_("All files")) file_filter_all.add_pattern("*") diff --git a/src/devedeng/preview.py b/src/devedeng/preview.py index ac9f9f8..bdc55bb 100644 --- a/src/devedeng/preview.py +++ b/src/devedeng/preview.py @@ -19,6 +19,7 @@ from gi.repository import Gtk import os import devedeng.configuration_data + class preview_window: def __init__(self): @@ -30,7 +31,7 @@ class preview_window: builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wpreview.ui")) + builder.add_from_file(os.path.join(self.config.glade, "wpreview.ui")) builder.connect_signals(self) wpreview_window = builder.get_object("dialog_preview") wlength = builder.get_object("length") @@ -43,4 +44,4 @@ class preview_window: if (retval == 1): return True else: - return False \ No newline at end of file + return False diff --git a/src/devedeng/project.py b/src/devedeng/project.py index f88be7f..d9892fe 100644 --- a/src/devedeng/project.py +++ b/src/devedeng/project.py @@ -40,729 +40,705 @@ import devedeng.about import devedeng.opensave import devedeng.help + class devede_project: - dvd_max_bps_base = {0: 9000} - dvd_min_bps = 300 - dvd_max_total = 10000 - - svcd_max_bps_base = {0: 2700} - svcd_min_bps = 200 - svcd_max_total = 2700 - - divx_max_bps_base = {0: 4854, 720: 9708, 1080: 20000} - divx_min_bps = 300 - divx_max_total = -1 - - mkv_max_bps_base = {0: 192, 240: 2000, 480: 14000, 720: 50000, 1080: 240000} - mkv_min_bps = 192 - mkv_max_total = -1 - - def_max_bps_base = {0: 9000} - def_min_bps = 300 - def_max_total = -1 - - def __init__(self): - - self.config = devedeng.configuration_data.configuration.get_config() - - self.disc_type = self.config.disc_type - self.menu = devedeng.dvd_menu.dvd_menu() - - self.current_title = None - self.project_file = None - - builder = Gtk.Builder() - builder.set_translation_domain(self.config.gettext_domain) - - builder.add_from_file(os.path.join(self.config.glade,"wmain.ui")) - builder.connect_signals(self) - - # Interface widgets - self.wmain_window = builder.get_object("wmain_window") - self.wdisc_size = builder.get_object("disc_size") - self.wliststore_files = builder.get_object("liststore_files") - self.wfiles = builder.get_object("files") - self.wdisc_fill_level = builder.get_object("disc_fill_level") - self.wuse_pal = builder.get_object("use_pal") - self.wuse_ntsc = builder.get_object("use_ntsc") - self.wframe_titles = builder.get_object("frame_titles") - - self.winmenu = builder.get_object("treeviewcolumn3") - - self.wframe_menu = builder.get_object("frame_menu") - self.wcreate_menu = builder.get_object("create_menu") - self.wmenu_options = builder.get_object("menu_options") - - - self.wadd_file = builder.get_object("add_file") - self.wdelete_file = builder.get_object("delete_file") - self.wup_file = builder.get_object("up_file") - self.wdown_file = builder.get_object("down_file") - self.wproperties_file = builder.get_object("properties_file") - self.wpreview_file = builder.get_object("preview_file") - - self.wcreate_disc = builder.get_object("create_disc") - - selection = self.wfiles.get_selection() - selection.set_mode(Gtk.SelectionMode.BROWSE) - - if (self.config.PAL): - self.wuse_pal.set_active(True) - self.pal = True - else: - self.wuse_ntsc.set_active(True) - self.pal = False - - self.wcreate_menu.set_active(True) - - self.config.connect('disc_type',self.set_type) - if (self.disc_type is not None): - self.set_type(None, self.disc_type) - - self.wmain_window.drag_dest_set(Gtk.DestDefaults.ALL,[],Gdk.DragAction.COPY) - targets = Gtk.TargetList.new([]) - targets.add(Gdk.Atom.intern("text/uri-list", False),0,0) - self.wmain_window.drag_dest_set_target_list(targets) - - - def set_type(self,obj=None,disc_type=None): - """ this method sets the disk type to the specified one and adapts the interface - in the main window to it. Also leaves everything ready to start creating a - new disc """ - - if (disc_type is not None): - self.disc_type = disc_type - self.wmain_window.show_all() - self.set_interface_status(None) - - # Set the default disc size - if (self.disc_type == "dvd") or (self.disc_type == "mkv"): - self.wdisc_size.set_active(1) # 4.7 GB DVD - else: - self.wdisc_size.set_active(3) # 700 MB CD - - if (self.disc_type == "dvd"): - self.winmenu.set_visible(True) - self.wframe_menu.show_all() - self.wcreate_menu.set_active(True) - else: - self.winmenu.set_visible(False) - self.wframe_menu.hide() - self.wcreate_menu.set_active(False) - - - def get_current_file(self): - - """ returns the currently selected file """ - - selection = self.wfiles.get_selection() - model, treeiter = selection.get_selected() - - if treeiter is not None: - element = model[treeiter][0] - position = 0 - for row in self.wfiles.get_model(): - item = row.model[row.iter][0] - if element == item: - break - position += 1 - return ( (element, position, model, treeiter) ) - else: - return ( (None, -1, None, None) ) - - - def get_all_files(self): - - retval = [] - - for row in self.wfiles.get_model(): - retval.append(row.model[row.iter][0]) - return retval - - - def set_interface_status(self,b): - - self.wadd_file.set_sensitive(True) - self.wdelete_file.set_sensitive(True) - self.wup_file.set_sensitive(True) - self.wdown_file.set_sensitive(True) - self.wproperties_file.set_sensitive(True) - self.wpreview_file.set_sensitive(True) - - status = self.wcreate_menu.get_active() - self.wmenu_options.set_sensitive(status) - - self.pal = self.wuse_pal.get_active() - - (element, position, model, treeiter) = self.get_current_file() - if (element is None): - self.wdelete_file.set_sensitive(False) - self.wup_file.set_sensitive(False) - self.wdown_file.set_sensitive(False) - self.wproperties_file.set_sensitive(False) - self.wpreview_file.set_sensitive(False) - else: - nfiles = len(self.wfiles.get_model()) - if (nfiles < 1): - self.wdelete_file.set_sensitive(False) - if (position == 0): - self.wup_file.set_sensitive(False) - if (position == (nfiles-1)): - self.wdown_file.set_sensitive(False) - - - def on_cellrenderertext3_edited(self, widget, path, text): - self.wliststore_files[path][0].set_title(text) - - def on_cellrenderertext4_toggled(self,widget,path): - self.wliststore_files[path][0].set_show_in_menu(False if widget.get_active() else True) - - def on_use_pal_toggled(self,b): - - self.config.PAL = self.wuse_pal.get_active() - self.set_interface_status(None) - - - def on_wmain_window_delete_event(self,b,e=None): - - ask = devedeng.ask.ask_window() - if (ask.run(_("Abort the current DVD and exit?"),_("Exit DeVeDe"))): - Gtk.main_quit() - return True - - def title_changed(self,obj,new_title): - - for item in self.wliststore_files: - element = item.model[item.iter][0] - if element == obj: - item.model.set_value(item.iter,1,new_title) - self.refresh_disc_usage() - - - def in_menu_changed(self,obj,new_inmenu): - for item in self.wliststore_files: - element = item.model[item.iter][0] - if element == obj: - item.model.set_value(item.iter,4,new_inmenu) - self.refresh_disc_usage() - - - def on_help_clicked(self,b): - - help_file = devedeng.help.help("main.html") - - def on_help_index_activate(self,b): - - help_file = devedeng.help.help("index.html") - - - def on_add_file_clicked(self,b): - - ask_files = devedeng.add_files.add_files() - if (ask_files.run()): - self.add_several_files(ask_files.files) - - - def duration_to_string(self,duration): - - seconds = math.floor(duration%60) - minutes = math.floor((duration/60)%60) - hours = math.floor(duration/3600) - - output = str(seconds)+"s" - if ((hours != 0) or (minutes != 0)): - output = str(minutes)+"m "+output - if (hours != 0): - output = str(hours)+"h "+output - return output - - - def add_several_files(self,file_list): - error_list = [] - for efile in file_list: - if efile.startswith("file://"): - efile = urllib.parse.unquote(efile[7:]) - new_file = devedeng.file_movie.file_movie(efile) - if (new_file.error): - error_list.append(os.path.basename(efile)) - else: - new_file.connect('title_changed',self.title_changed) - new_file.connect('in_menu_changed',self.in_menu_changed) - self.wliststore_files.append([new_file, new_file.title_name,True,self.duration_to_string(new_file.get_duration()),new_file.show_in_menu]) - if (len(error_list)!=0): - devedeng.message.message_window(_("The following files could not be added:"),_("Error while adding files"),error_list) - self.set_interface_status(None) - self.refresh_disc_usage() - - - def on_delete_file_clicked(self,b): - - (element, position, model, treeiter) = self.get_current_file() - if (element is None): - return - - ask_w = devedeng.ask.ask_window() - if (ask_w.run(_("The file %(X)s (%(Y)s) will be removed.") % {"X":element.title_name, "Y":element.file_name},_("Delete file"))): - element.delete_file() - model.remove(treeiter) - self.set_interface_status(None) - self.refresh_disc_usage() - - - def on_up_file_clicked(self,b): - - (element, position, model, treeiter) = self.get_current_file() - if (element is None) or (position == 0): - return - - last_element = self.wfiles.get_model()[position-1] - self.wfiles.get_model().swap(last_element.iter,treeiter) - self.set_interface_status(None) - - - def on_down_file_clicked(self,b): - - (element, position, model, treeiter) = self.get_current_file() - if (element is None) or (position == (len(self.wfiles.get_model())-1)): - return - - last_element = self.wfiles.get_model()[position+1] - self.wfiles.get_model().swap(last_element.iter,treeiter) - self.set_interface_status(None) - - - def on_properties_file_clicked(self,b): - (element, position, model, treeiter) = self.get_current_file() - if (element is None): - return - element.properties() - - - def on_create_menu_toggled(self,b): - self.set_interface_status(None) - self.refresh_disc_usage() - - - def on_adjust_disc_usage_clicked(self,b): - - total_resolution = 0 - fixed_size = 0 - to_adjust = [] - for f in self.get_all_files(): - estimated_size, videorate_fixed_size, audio_rate, sub_rate, width, height, time_length = f.get_size_data() - if videorate_fixed_size: - fixed_size += estimated_size - else: - fixed_size += ((audio_rate + sub_rate) * time_length) - # 76800 = 320x240, which is the smallest resolution - surface = ((float(width) * float(height)) / 76800.0) * float(time_length) - to_adjust.append( (f, surface, time_length, audio_rate, height) ) - total_resolution += surface - - if (self.disc_type == "dvd") and (self.wcreate_menu.get_active()): - fixed_size += self.menu.get_estimated_size() * 8.0 - - if (self.disc_type == "dvd"): - max_bps_base = devede_project.dvd_max_bps_base.copy() - min_bps = devede_project.dvd_min_bps - max_total = devede_project.dvd_max_total - elif (self.disc_type == "svcd") or (self.disc_type == "cvd"): - max_bps_base = devede_project.svcd_max_bps_base.copy() - min_bps = devede_project.svcd_min_bps - max_total = devede_project.svcd_max_total - elif (self.disc_type == "divx"): - max_bps_base = devede_project.divx_max_bps_base.copy() - min_bps = devede_project.divx_min_bps - max_total = devede_project.divx_max_total - elif (self.disc_type == "mkv"): - max_bps_base = devede_project.mkv_max_bps_base.copy() - min_bps = devede_project.mkv_min_bps - max_total = devede_project.mkv_max_total - else: - max_bps_base = devede_project.def_max_bps_base.copy() - min_bps = devede_project.def_min_bps - max_total = devede_project.def_max_total - - if (total_resolution != 0): - remaining_disc_size = ((8000.0 * self.get_dvd_size()[0]) - fixed_size) # in kbits - for l in to_adjust: - f = l[0] - surface = l[1] - length = l[2] - audio_rate = l[3] - height = l[4] - - max_bps = max_bps_base[0] - resy = 0 - for bitrates in max_bps_base: - if (height >= bitrates) and (resy < bitrates): - resy = bitrates - max_bps = max_bps_base[bitrates] - - video_rate = (remaining_disc_size * surface) / ( length * total_resolution) - if max_total != -1: - max2 = max_total - audio_rate - if (max2 > max_bps): - max2 = max_bps - else: - max2 = max_bps - if (video_rate > max2): - video_rate = max2 - if (video_rate < min_bps): - video_rate = min_bps - f.set_auto_video_audio_rate(video_rate, audio_rate) - - self.refresh_disc_usage() - - - def refresh_disc_usage(self): - - used = 0.0 - - for f in self.get_all_files(): - estimated_size = f.get_estimated_size() - used += float(estimated_size) - - if self.wcreate_menu.get_active(): - used += float(self.menu.get_estimated_size()) - - used /= 1000.0 - - disc_size,minvrate,maxvrate = self.get_dvd_size() - - if used > disc_size: - self.wdisc_fill_level.set_fraction(1.0) - addv=1 - else: - self.wdisc_fill_level.set_fraction(used / disc_size) - addv=0 - - self.wdisc_fill_level.set_text(str(addv+int((used / disc_size)*100))+"%") - self.wdisc_fill_level.set_show_text(True) - - - def on_menu_options_clicked(self,b): - - self.menu.show_configuration(self.get_all_files()) - - - def get_dvd_size(self): - - """ Returns the size for the currently selected disk type, and the minimum and maximum - videorate for the current video disk """ - - active = self.wdisc_size.get_active() - - # here we choose the size in Mbytes for the media - if 5==active: - size=170.0 - elif 4==active: - size=700.0 - elif 3==active: - size=750.0 - elif 2==active: - size=1100.0 - elif 1==active: - size=4200.0 - else: - size=8000.0 - - if self.disc_type=="vcd": - minvrate=1152 - maxvrate=1152 - elif (self.disc_type == "svcd") or (self.disc_type == "cvd"): - minvrate=400 - maxvrate=2300 - elif (self.disc_type == "dvd"): - minvrate=400 - maxvrate=8500 - elif (self.disc_type == "divx") or (self.disc_type == "mkv"): - minvrate=300 - maxvrate=6000 - else: - minvrate = 0 - maxvrate = 8000 - - size *= 0.90 # a safe margin of 10% to ensure that it never will be bigger - # (it's important to have in mind the space needed by disk structures like - # directories, file entries, and so on) - - return size,minvrate,maxvrate - - - def on_disc_size_changed(self,c): - - self.refresh_disc_usage() - - - def on_create_disc_clicked(self,b): - - if self.disc_type == "dvd": - max_files = 62 - else: - max_files = -1 - - file_movies = self.get_all_files() - t = len(file_movies) - if (max_files != -1) and (t > max_files): - devedeng.message.message_window(_("The limit for this format is %(l)d files, but your project has %(h)d.") % {"l": max_files, "h" : t}, _("Too many files in the project")) - return - - data = devedeng.create_disk_window.create_disk_window() - if (not data.run()): - return - - if os.path.exists(data.path): - ask_w = devedeng.ask.ask_window() - retval = ask_w.run(_("The selected folder already exists. To create the project, Devede must delete it.\nIf you continue, the folder\n\n %s\n\n and all its contents will be deleted. Continue?") % data.path,_("Delete folder")) - if retval: - # delete only the bare minimun needed - shutil.rmtree(os.path.join(data.path,"dvd_tree"),True) - shutil.rmtree(os.path.join(data.path,"menu"),True) - shutil.rmtree(os.path.join(data.path,"movies"),True) - shutil.rmtree(os.path.join(data.path,"xml_data"),True) - if self.config.disc_type == "dvd": - try: - os.unlink(os.path.join(data.path,data.name+".iso")) - except: - pass - if (self.config.disc_type == "vcd") or (self.config.disc_type == "svcd") or (self.config.disc_type == "cvd"): - try: - os.unlink(os.path.join(data.path,data.name+".bin")) - except: - pass - try: - os.unlink(os.path.join(data.path,data.name+".cue")) - except: - pass - else: - return - - self.shutdown = data.shutdown - - run_window = devedeng.runner.runner() - - final_dependencies = [] - - if (self.disc_type == "dvd") and (self.wcreate_menu.get_active()): - processes,menu_entries = self.menu.create_dvd_menus(file_movies, data.path) - for p in processes: - run_window.add_process(p) - final_dependencies.append(p) - else: - menu_entries = None - - movie_folder = os.path.join(data.path,"movies") - try: - os.makedirs(movie_folder) - except: - pass - counter = 0 - if self.disc_type == "divx": - extension = "avi" - elif self.disc_type == "mkv": - extension = "mkv" - else: - extension = "mpg" - for movie in file_movies: - p = movie.do_conversion(os.path.join(movie_folder,"movie_{:d}.{:s}".format(counter,extension))) - run_window.add_process(p) - final_dependencies.append(p) - counter += 1 - - if (self.disc_type == "dvd"): - if (self.menu.at_startup == "menu_show_at_startup"): - start_with_menu = True - else: - start_with_menu = False - dvdauthor = devedeng.dvdauthor_converter.dvdauthor_converter() - dvdauthor.create_dvd_project(data.path, data.name, file_movies, menu_entries, start_with_menu, self.menu.play_all_c) - # dvdauthor must wait until all the files have been converted - for element in final_dependencies: - dvdauthor.add_dependency(element) - run_window.add_process(dvdauthor) - - cv = devedeng.converter.converter.get_converter() - isocreator = cv.get_mkiso()() - isocreator.create_iso(data.path, data.name) - isocreator.add_dependency(dvdauthor) - run_window.add_process(isocreator) - self.disc_image_name = os.path.join(data.path,data.name+".iso") - elif (self.disc_type == "vcd") or (self.disc_type == "svcd") or (self.disc_type == "cvd"): - vcdcreator = devedeng.vcdimager_converter.vcdimager_converter() - vcdcreator.create_cd_project(data.path, data.name, file_movies) - for element in final_dependencies: - vcdcreator.add_dependency(element) - run_window.add_process(vcdcreator) - self.disc_image_name = os.path.join(data.path,data.name+".cue") - else: - self.disc_image_name = None - - run_window.connect("done",self.disc_done) - self.wmain_window.hide() - self.time_start = time.time() - run_window.run() - - - def disc_done(self,object,value): - - if self.shutdown: - Gtk.main_quit() - devedeng.shutdown.shutdown() - - if value == 0: - ended = devedeng.end_job.end_window() - if self.disc_image_name is None: - do_burn = False - else: - do_burn = True - if (ended.run(time.time() - self.time_start, do_burn)): - cv = devedeng.converter.converter.get_converter() - burner = cv.get_burner()() - burner.burn(self.disc_image_name) - run_window = devedeng.runner.runner(False) - run_window.add_process(burner) - run_window.connect("done", self.disc_done2) - run_window.run() - return - - self.wmain_window.show() - - - def disc_done2(self,object, value): - - self.wmain_window.show() - - - def on_preview_file_clicked(self,b): - - (element, position, model, treeiter) = self.get_current_file() - if (element is None): - return - element.do_preview() - - - def on_settings_activate(self,b): - - w = devedeng.settings.settings_window() - - - def on_about_activate(self,b): - - w = devedeng.about.about_window() - - - def on_new_activate(self,b): - - w = devedeng.ask.ask_window() - if w.run(_("Close current project and start a fresh one?"), _("New project")): - self.wliststore_files.clear() - self.project_file = None - self.wmain_window.hide() - devedeng.choose_disc_type.choose_disc_type() - - - def on_wmain_window_drag_motion(self,wid, context, x, y, time): - Gdk.drag_status(context, Gdk.DragAction.COPY, time) - return True - - - def on_wmain_window_drag_drop(self, wid, context, x, y, time): - # Used with windows drag and drop - return True - - - def on_wmain_window_drag_data_received(self, widget, drag_context, x,y, data, info, time): - uris = data.get_uris() - self.add_several_files(uris) - Gtk.drag_finish (drag_context, True, Gdk.DragAction.COPY, time); - - - def on_save_activate(self,b): - if self.project_file is not None: - self.save_current_project() - else: - self.on_save_as_activate(None) - - - def on_save_as_activate(self,b): - - while True: - w = devedeng.opensave.opensave_window(True) - retval = w.run(self.project_file) - if retval is None: - return - if not retval.endswith(".devedeng"): - retval += ".devedeng" - if os.path.isfile(retval): - w = devedeng.ask.ask_window() - if not w.run(_("The file already exists. Overwrite it?"), _("The file already exists")): - continue - self.project_file = retval - self.save_current_project() - return - - - def on_load_activate(self,b): - w = devedeng.opensave.opensave_window(False) - retval = w.run() - if retval is not None: - self.load_project(retval) - - - def save_current_project(self): - - project = {} - - project["PAL"] = self.wuse_pal.get_active() - project["create_menu"] = self.wcreate_menu.get_active() - project["disc_type"] = self.config.disc_type - project["disc_size"] = self.wdisc_size.get_active() - project["files"] = [] - f = self.get_all_files() - for i in f: - project["files"].append(i.store_file()) - if self.disc_type == "dvd": - project["menu"] = self.menu.store_menu() - - with open(self.project_file, 'wb') as f: - pickle.dump(project, f, 3) - - - def load_project(self,project_file): - - self.wliststore_files.clear() - self.project_file = project_file - with open(project_file, 'rb') as f: - project = pickle.load(f) - if "disc_type" in project: - self.config.set_disc_type(project["disc_type"]) - if "PAL" in project: - self.wuse_pal.set_active(project["PAL"]) - if "create_menu" in project: - self.wcreate_menu.set_active(project["create_menu"]) - if "disc_size" in project: - self.wdisc_size.set_active(project["disc_size"]) - if "menu" in project: - self.menu.restore_menu(project["menu"]) - if "files" in project: - error_list = [] - for efile in project["files"]: - new_file = devedeng.file_movie.file_movie(efile["file_name"]) - if (new_file.error): - error_list.append(os.path.basename(efile["file_name"])) - else: - new_file.restore_file(efile) - new_file.connect('title_changed',self.title_changed) - self.wliststore_files.append([new_file, new_file.title_name,True,self.duration_to_string(new_file.get_duration()),new_file.show_in_menu]) - if (len(error_list)!=0): - devedeng.message.message_window(_("The following files in the project could not be added again:"),_("Error while adding files"),error_list) - self.set_interface_status(None) - self.refresh_disc_usage() - - - def on_multiproperties_activate(self,b): - - e = devedeng.file_movie.file_movie(None,self.get_all_files()) - e.properties() + dvd_max_bps_base = {0: 9000} + dvd_min_bps = 300 + dvd_max_total = 10000 + + svcd_max_bps_base = {0: 2700} + svcd_min_bps = 200 + svcd_max_total = 2700 + + divx_max_bps_base = {0: 4854, 720: 9708, 1080: 20000} + divx_min_bps = 300 + divx_max_total = -1 + + mkv_max_bps_base = {0: 192, 240: 2000, + 480: 14000, 720: 50000, 1080: 240000} + mkv_min_bps = 192 + mkv_max_total = -1 + + def_max_bps_base = {0: 9000} + def_min_bps = 300 + def_max_total = -1 + + def __init__(self): + + self.config = devedeng.configuration_data.configuration.get_config() + + self.disc_type = self.config.disc_type + self.menu = devedeng.dvd_menu.dvd_menu() + + self.current_title = None + self.project_file = None + + builder = Gtk.Builder() + builder.set_translation_domain(self.config.gettext_domain) + + builder.add_from_file(os.path.join(self.config.glade, "wmain.ui")) + builder.connect_signals(self) + + # Interface widgets + self.wmain_window = builder.get_object("wmain_window") + self.wdisc_size = builder.get_object("disc_size") + self.wliststore_files = builder.get_object("liststore_files") + self.wfiles = builder.get_object("files") + self.wdisc_fill_level = builder.get_object("disc_fill_level") + self.wuse_pal = builder.get_object("use_pal") + self.wuse_ntsc = builder.get_object("use_ntsc") + self.wframe_titles = builder.get_object("frame_titles") + + self.winmenu = builder.get_object("treeviewcolumn3") + + self.wframe_menu = builder.get_object("frame_menu") + self.wcreate_menu = builder.get_object("create_menu") + self.wmenu_options = builder.get_object("menu_options") + + self.wadd_file = builder.get_object("add_file") + self.wdelete_file = builder.get_object("delete_file") + self.wup_file = builder.get_object("up_file") + self.wdown_file = builder.get_object("down_file") + self.wproperties_file = builder.get_object("properties_file") + self.wpreview_file = builder.get_object("preview_file") + + self.wcreate_disc = builder.get_object("create_disc") + + selection = self.wfiles.get_selection() + selection.set_mode(Gtk.SelectionMode.BROWSE) + + if (self.config.PAL): + self.wuse_pal.set_active(True) + self.pal = True + else: + self.wuse_ntsc.set_active(True) + self.pal = False + + self.wcreate_menu.set_active(True) + + self.config.connect('disc_type', self.set_type) + if (self.disc_type is not None): + self.set_type(None, self.disc_type) + + self.wmain_window.drag_dest_set( + Gtk.DestDefaults.ALL, [], Gdk.DragAction.COPY) + targets = Gtk.TargetList.new([]) + targets.add(Gdk.Atom.intern("text/uri-list", False), 0, 0) + self.wmain_window.drag_dest_set_target_list(targets) + + def set_type(self, obj=None, disc_type=None): + """ this method sets the disk type to the specified one and adapts the interface + in the main window to it. Also leaves everything ready to start creating a + new disc """ + + if (disc_type is not None): + self.disc_type = disc_type + self.wmain_window.show_all() + self.set_interface_status(None) + + # Set the default disc size + if (self.disc_type == "dvd") or (self.disc_type == "mkv"): + self.wdisc_size.set_active(1) # 4.7 GB DVD + else: + self.wdisc_size.set_active(3) # 700 MB CD + + if (self.disc_type == "dvd"): + self.winmenu.set_visible(True) + self.wframe_menu.show_all() + self.wcreate_menu.set_active(True) + else: + self.winmenu.set_visible(False) + self.wframe_menu.hide() + self.wcreate_menu.set_active(False) + + def get_current_file(self): + """ returns the currently selected file """ + + selection = self.wfiles.get_selection() + model, treeiter = selection.get_selected() + + if treeiter is not None: + element = model[treeiter][0] + position = 0 + for row in self.wfiles.get_model(): + item = row.model[row.iter][0] + if element == item: + break + position += 1 + return ((element, position, model, treeiter)) + else: + return ((None, -1, None, None)) + + def get_all_files(self): + + retval = [] + + for row in self.wfiles.get_model(): + retval.append(row.model[row.iter][0]) + return retval + + def set_interface_status(self, b): + + self.wadd_file.set_sensitive(True) + self.wdelete_file.set_sensitive(True) + self.wup_file.set_sensitive(True) + self.wdown_file.set_sensitive(True) + self.wproperties_file.set_sensitive(True) + self.wpreview_file.set_sensitive(True) + + status = self.wcreate_menu.get_active() + self.wmenu_options.set_sensitive(status) + + self.pal = self.wuse_pal.get_active() + + (element, position, model, treeiter) = self.get_current_file() + if (element is None): + self.wdelete_file.set_sensitive(False) + self.wup_file.set_sensitive(False) + self.wdown_file.set_sensitive(False) + self.wproperties_file.set_sensitive(False) + self.wpreview_file.set_sensitive(False) + else: + nfiles = len(self.wfiles.get_model()) + if (nfiles < 1): + self.wdelete_file.set_sensitive(False) + if (position == 0): + self.wup_file.set_sensitive(False) + if (position == (nfiles - 1)): + self.wdown_file.set_sensitive(False) + + def on_cellrenderertext3_edited(self, widget, path, text): + self.wliststore_files[path][0].set_title(text) + + def on_cellrenderertext4_toggled(self, widget, path): + self.wliststore_files[path][0].set_show_in_menu( + False if widget.get_active() else True) + + def on_use_pal_toggled(self, b): + + self.config.PAL = self.wuse_pal.get_active() + self.set_interface_status(None) + + def on_wmain_window_delete_event(self, b, e=None): + + ask = devedeng.ask.ask_window() + if (ask.run(_("Abort the current DVD and exit?"), _("Exit DeVeDe"))): + Gtk.main_quit() + return True + + def title_changed(self, obj, new_title): + + for item in self.wliststore_files: + element = item.model[item.iter][0] + if element == obj: + item.model.set_value(item.iter, 1, new_title) + self.refresh_disc_usage() + + def in_menu_changed(self, obj, new_inmenu): + for item in self.wliststore_files: + element = item.model[item.iter][0] + if element == obj: + item.model.set_value(item.iter, 4, new_inmenu) + self.refresh_disc_usage() + + def on_help_clicked(self, b): + + help_file = devedeng.help.help("main.html") + + def on_help_index_activate(self, b): + + help_file = devedeng.help.help("index.html") + + def on_add_file_clicked(self, b): + + ask_files = devedeng.add_files.add_files() + if (ask_files.run()): + self.add_several_files(ask_files.files) + + def duration_to_string(self, duration): + + seconds = math.floor(duration % 60) + minutes = math.floor((duration / 60) % 60) + hours = math.floor(duration / 3600) + + output = str(seconds) + "s" + if ((hours != 0) or (minutes != 0)): + output = str(minutes) + "m " + output + if (hours != 0): + output = str(hours) + "h " + output + return output + + def add_several_files(self, file_list): + error_list = [] + for efile in file_list: + if efile.startswith("file://"): + efile = urllib.parse.unquote(efile[7:]) + new_file = devedeng.file_movie.file_movie(efile) + if (new_file.error): + error_list.append(os.path.basename(efile)) + else: + new_file.connect('title_changed', self.title_changed) + new_file.connect('in_menu_changed', self.in_menu_changed) + self.wliststore_files.append([new_file, new_file.title_name, True, self.duration_to_string( + new_file.get_duration()), new_file.show_in_menu]) + if (len(error_list) != 0): + devedeng.message.message_window(_("The following files could not be added:"), _( + "Error while adding files"), error_list) + self.set_interface_status(None) + self.refresh_disc_usage() + + def on_delete_file_clicked(self, b): + + (element, position, model, treeiter) = self.get_current_file() + if (element is None): + return + + ask_w = devedeng.ask.ask_window() + if (ask_w.run(_("The file %(X)s (%(Y)s) will be removed.") % {"X": element.title_name, "Y": element.file_name}, _("Delete file"))): + element.delete_file() + model.remove(treeiter) + self.set_interface_status(None) + self.refresh_disc_usage() + + def on_up_file_clicked(self, b): + + (element, position, model, treeiter) = self.get_current_file() + if (element is None) or (position == 0): + return + + last_element = self.wfiles.get_model()[position - 1] + self.wfiles.get_model().swap(last_element.iter, treeiter) + self.set_interface_status(None) + + def on_down_file_clicked(self, b): + + (element, position, model, treeiter) = self.get_current_file() + if (element is None) or (position == (len(self.wfiles.get_model()) - 1)): + return + + last_element = self.wfiles.get_model()[position + 1] + self.wfiles.get_model().swap(last_element.iter, treeiter) + self.set_interface_status(None) + + def on_properties_file_clicked(self, b): + (element, position, model, treeiter) = self.get_current_file() + if (element is None): + return + element.properties() + + def on_create_menu_toggled(self, b): + self.set_interface_status(None) + self.refresh_disc_usage() + + def on_adjust_disc_usage_clicked(self, b): + + total_resolution = 0 + fixed_size = 0 + to_adjust = [] + for f in self.get_all_files(): + estimated_size, videorate_fixed_size, audio_rate, sub_rate, width, height, time_length = f.get_size_data() + if videorate_fixed_size: + fixed_size += estimated_size + else: + fixed_size += ((audio_rate + sub_rate) * time_length) + # 76800 = 320x240, which is the smallest resolution + surface = ((float(width) * float(height)) / + 76800.0) * float(time_length) + to_adjust.append((f, surface, time_length, audio_rate, height)) + total_resolution += surface + + if (self.disc_type == "dvd") and (self.wcreate_menu.get_active()): + fixed_size += self.menu.get_estimated_size() * 8.0 + + if (self.disc_type == "dvd"): + max_bps_base = devede_project.dvd_max_bps_base.copy() + min_bps = devede_project.dvd_min_bps + max_total = devede_project.dvd_max_total + elif (self.disc_type == "svcd") or (self.disc_type == "cvd"): + max_bps_base = devede_project.svcd_max_bps_base.copy() + min_bps = devede_project.svcd_min_bps + max_total = devede_project.svcd_max_total + elif (self.disc_type == "divx"): + max_bps_base = devede_project.divx_max_bps_base.copy() + min_bps = devede_project.divx_min_bps + max_total = devede_project.divx_max_total + elif (self.disc_type == "mkv"): + max_bps_base = devede_project.mkv_max_bps_base.copy() + min_bps = devede_project.mkv_min_bps + max_total = devede_project.mkv_max_total + else: + max_bps_base = devede_project.def_max_bps_base.copy() + min_bps = devede_project.def_min_bps + max_total = devede_project.def_max_total + + if (total_resolution != 0): + remaining_disc_size = ( + (8000.0 * self.get_dvd_size()[0]) - fixed_size) # in kbits + for l in to_adjust: + f = l[0] + surface = l[1] + length = l[2] + audio_rate = l[3] + height = l[4] + + max_bps = max_bps_base[0] + resy = 0 + for bitrates in max_bps_base: + if (height >= bitrates) and (resy < bitrates): + resy = bitrates + max_bps = max_bps_base[bitrates] + + video_rate = (remaining_disc_size * surface) / \ + (length * total_resolution) + if max_total != -1: + max2 = max_total - audio_rate + if (max2 > max_bps): + max2 = max_bps + else: + max2 = max_bps + if (video_rate > max2): + video_rate = max2 + if (video_rate < min_bps): + video_rate = min_bps + f.set_auto_video_audio_rate(video_rate, audio_rate) + + self.refresh_disc_usage() + + def refresh_disc_usage(self): + + used = 0.0 + + for f in self.get_all_files(): + estimated_size = f.get_estimated_size() + used += float(estimated_size) + + if self.wcreate_menu.get_active(): + used += float(self.menu.get_estimated_size()) + + used /= 1000.0 + + disc_size, minvrate, maxvrate = self.get_dvd_size() + + if used > disc_size: + self.wdisc_fill_level.set_fraction(1.0) + addv = 1 + else: + self.wdisc_fill_level.set_fraction(used / disc_size) + addv = 0 + + self.wdisc_fill_level.set_text( + str(addv + int((used / disc_size) * 100)) + "%") + self.wdisc_fill_level.set_show_text(True) + + def on_menu_options_clicked(self, b): + + self.menu.show_configuration(self.get_all_files()) + + def get_dvd_size(self): + """ Returns the size for the currently selected disk type, and the minimum and maximum + videorate for the current video disk """ + + active = self.wdisc_size.get_active() + + # here we choose the size in Mbytes for the media + if 5 == active: + size = 170.0 + elif 4 == active: + size = 700.0 + elif 3 == active: + size = 750.0 + elif 2 == active: + size = 1100.0 + elif 1 == active: + size = 4200.0 + else: + size = 8000.0 + + if self.disc_type == "vcd": + minvrate = 1152 + maxvrate = 1152 + elif (self.disc_type == "svcd") or (self.disc_type == "cvd"): + minvrate = 400 + maxvrate = 2300 + elif (self.disc_type == "dvd"): + minvrate = 400 + maxvrate = 8500 + elif (self.disc_type == "divx") or (self.disc_type == "mkv"): + minvrate = 300 + maxvrate = 6000 + else: + minvrate = 0 + maxvrate = 8000 + + size *= 0.90 # a safe margin of 10% to ensure that it never will be bigger + # (it's important to have in mind the space needed by disk structures like + # directories, file entries, and so on) + + return size, minvrate, maxvrate + + def on_disc_size_changed(self, c): + + self.refresh_disc_usage() + + def on_create_disc_clicked(self, b): + + if self.disc_type == "dvd": + max_files = 62 + else: + max_files = -1 + + file_movies = self.get_all_files() + t = len(file_movies) + if (max_files != -1) and (t > max_files): + devedeng.message.message_window(_("The limit for this format is %(l)d files, but your project has %(h)d.") % { + "l": max_files, "h": t}, _("Too many files in the project")) + return + + data = devedeng.create_disk_window.create_disk_window() + if (not data.run()): + return + + if os.path.exists(data.path): + ask_w = devedeng.ask.ask_window() + retval = ask_w.run(_("The selected folder already exists. To create the project, Devede must delete it.\nIf you continue, the folder\n\n %s\n\n and all its contents will be deleted. Continue?") % data.path, _("Delete folder")) + if retval: + # delete only the bare minimun needed + shutil.rmtree(os.path.join(data.path, "dvd_tree"), True) + shutil.rmtree(os.path.join(data.path, "menu"), True) + shutil.rmtree(os.path.join(data.path, "movies"), True) + shutil.rmtree(os.path.join(data.path, "xml_data"), True) + if self.config.disc_type == "dvd": + try: + os.unlink(os.path.join(data.path, data.name + ".iso")) + except: + pass + if (self.config.disc_type == "vcd") or (self.config.disc_type == "svcd") or (self.config.disc_type == "cvd"): + try: + os.unlink(os.path.join(data.path, data.name + ".bin")) + except: + pass + try: + os.unlink(os.path.join(data.path, data.name + ".cue")) + except: + pass + else: + return + + self.shutdown = data.shutdown + + run_window = devedeng.runner.runner() + + final_dependencies = [] + + if (self.disc_type == "dvd") and (self.wcreate_menu.get_active()): + processes, menu_entries = self.menu.create_dvd_menus( + file_movies, data.path) + for p in processes: + run_window.add_process(p) + final_dependencies.append(p) + else: + menu_entries = None + + movie_folder = os.path.join(data.path, "movies") + try: + os.makedirs(movie_folder) + except: + pass + counter = 0 + if self.disc_type == "divx": + extension = "avi" + elif self.disc_type == "mkv": + extension = "mkv" + else: + extension = "mpg" + for movie in file_movies: + p = movie.do_conversion(os.path.join( + movie_folder, "movie_{:d}.{:s}".format(counter, extension))) + run_window.add_process(p) + final_dependencies.append(p) + counter += 1 + + if (self.disc_type == "dvd"): + if (self.menu.at_startup == "menu_show_at_startup"): + start_with_menu = True + else: + start_with_menu = False + dvdauthor = devedeng.dvdauthor_converter.dvdauthor_converter() + dvdauthor.create_dvd_project( + data.path, data.name, file_movies, menu_entries, start_with_menu, self.menu.play_all_c) + # dvdauthor must wait until all the files have been converted + for element in final_dependencies: + dvdauthor.add_dependency(element) + run_window.add_process(dvdauthor) + + cv = devedeng.converter.converter.get_converter() + isocreator = cv.get_mkiso()() + isocreator.create_iso(data.path, data.name) + isocreator.add_dependency(dvdauthor) + run_window.add_process(isocreator) + self.disc_image_name = os.path.join(data.path, data.name + ".iso") + elif (self.disc_type == "vcd") or (self.disc_type == "svcd") or (self.disc_type == "cvd"): + vcdcreator = devedeng.vcdimager_converter.vcdimager_converter() + vcdcreator.create_cd_project(data.path, data.name, file_movies) + for element in final_dependencies: + vcdcreator.add_dependency(element) + run_window.add_process(vcdcreator) + self.disc_image_name = os.path.join(data.path, data.name + ".cue") + else: + self.disc_image_name = None + + run_window.connect("done", self.disc_done) + self.wmain_window.hide() + self.time_start = time.time() + run_window.run() + + def disc_done(self, object, value): + + if self.shutdown: + Gtk.main_quit() + devedeng.shutdown.shutdown() + + if value == 0: + ended = devedeng.end_job.end_window() + if self.disc_image_name is None: + do_burn = False + else: + do_burn = True + if (ended.run(time.time() - self.time_start, do_burn)): + cv = devedeng.converter.converter.get_converter() + burner = cv.get_burner()() + burner.burn(self.disc_image_name) + run_window = devedeng.runner.runner(False) + run_window.add_process(burner) + run_window.connect("done", self.disc_done2) + run_window.run() + return + + self.wmain_window.show() + + def disc_done2(self, object, value): + + self.wmain_window.show() + + def on_preview_file_clicked(self, b): + + (element, position, model, treeiter) = self.get_current_file() + if (element is None): + return + element.do_preview() + + def on_settings_activate(self, b): + + w = devedeng.settings.settings_window() + + def on_about_activate(self, b): + + w = devedeng.about.about_window() + + def on_new_activate(self, b): + + w = devedeng.ask.ask_window() + if w.run(_("Close current project and start a fresh one?"), _("New project")): + self.wliststore_files.clear() + self.project_file = None + self.wmain_window.hide() + devedeng.choose_disc_type.choose_disc_type() + + def on_wmain_window_drag_motion(self, wid, context, x, y, time): + Gdk.drag_status(context, Gdk.DragAction.COPY, time) + return True + + def on_wmain_window_drag_drop(self, wid, context, x, y, time): + # Used with windows drag and drop + return True + + def on_wmain_window_drag_data_received(self, widget, drag_context, x, y, data, info, time): + uris = data.get_uris() + self.add_several_files(uris) + Gtk.drag_finish(drag_context, True, Gdk.DragAction.COPY, time) + + def on_save_activate(self, b): + if self.project_file is not None: + self.save_current_project() + else: + self.on_save_as_activate(None) + + def on_save_as_activate(self, b): + + while True: + w = devedeng.opensave.opensave_window(True) + retval = w.run(self.project_file) + if retval is None: + return + if not retval.endswith(".devedeng"): + retval += ".devedeng" + if os.path.isfile(retval): + w = devedeng.ask.ask_window() + if not w.run(_("The file already exists. Overwrite it?"), _("The file already exists")): + continue + self.project_file = retval + self.save_current_project() + return + + def on_load_activate(self, b): + w = devedeng.opensave.opensave_window(False) + retval = w.run() + if retval is not None: + self.load_project(retval) + + def save_current_project(self): + + project = {} + + project["PAL"] = self.wuse_pal.get_active() + project["create_menu"] = self.wcreate_menu.get_active() + project["disc_type"] = self.config.disc_type + project["disc_size"] = self.wdisc_size.get_active() + project["files"] = [] + f = self.get_all_files() + for i in f: + project["files"].append(i.store_file()) + if self.disc_type == "dvd": + project["menu"] = self.menu.store_menu() + + with open(self.project_file, 'wb') as f: + pickle.dump(project, f, 3) + + def load_project(self, project_file): + + self.wliststore_files.clear() + self.project_file = project_file + with open(project_file, 'rb') as f: + project = pickle.load(f) + if "disc_type" in project: + self.config.set_disc_type(project["disc_type"]) + if "PAL" in project: + self.wuse_pal.set_active(project["PAL"]) + if "create_menu" in project: + self.wcreate_menu.set_active(project["create_menu"]) + if "disc_size" in project: + self.wdisc_size.set_active(project["disc_size"]) + if "menu" in project: + self.menu.restore_menu(project["menu"]) + if "files" in project: + error_list = [] + for efile in project["files"]: + new_file = devedeng.file_movie.file_movie(efile["file_name"]) + if (new_file.error): + error_list.append(os.path.basename(efile["file_name"])) + else: + new_file.restore_file(efile) + new_file.connect('title_changed', self.title_changed) + self.wliststore_files.append([new_file, new_file.title_name, True, self.duration_to_string( + new_file.get_duration()), new_file.show_in_menu]) + if (len(error_list) != 0): + devedeng.message.message_window(_("The following files in the project could not be added again:"), _( + "Error while adding files"), error_list) + self.set_interface_status(None) + self.refresh_disc_usage() + + def on_multiproperties_activate(self, b): + + e = devedeng.file_movie.file_movie(None, self.get_all_files()) + e.properties() diff --git a/src/devedeng/runner.py b/src/devedeng/runner.py index 3f82e3e..deee58c 100644 --- a/src/devedeng/runner.py +++ b/src/devedeng/runner.py @@ -15,17 +15,18 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see -from gi.repository import Gtk,GObject +from gi.repository import Gtk, GObject import os import devedeng.configuration_data import devedeng.error import devedeng.ask + class runner(GObject.GObject): - __gsignals__ = {'done': (GObject.SIGNAL_RUN_FIRST, None,(int,))} + __gsignals__ = {'done': (GObject.SIGNAL_RUN_FIRST, None, (int,))} - def __init__(self, show_window = True): + def __init__(self, show_window=True): GObject.GObject.__init__(self) @@ -47,7 +48,8 @@ class runner(GObject.GObject): self.builder = Gtk.Builder() self.builder.set_translation_domain(self.config.gettext_domain) - self.builder.add_from_file(os.path.join(self.config.glade,"wprogress.ui")) + self.builder.add_from_file(os.path.join( + self.config.glade, "wprogress.ui")) self.builder.connect_signals(self) self.wprogress = self.builder.get_object("progress") if show_window: @@ -60,7 +62,7 @@ class runner(GObject.GObject): box.show() self.progress_bars = [] self.used_progress_bars = [] - for c in range(0,self.cores): + for c in range(0, self.cores): f = Gtk.Frame() p = Gtk.ProgressBar() p.set_orientation(Gtk.Orientation.HORIZONTAL) @@ -68,13 +70,12 @@ class runner(GObject.GObject): f.add(p) # A frame, a progress bar, and the process running in that bar self.progress_bars.append([f, p, None]) - box.pack_start(f,True,True,0) + box.pack_start(f, True, True, 0) box.set_orientation(Gtk.Orientation.VERTICAL) self.total_processes = 0 self.error = False - - def add_process(self,process): + def add_process(self, process): if (self.proc_list.count(process) == 0): self.proc_list.append(process) @@ -84,20 +85,20 @@ class runner(GObject.GObject): self.total_processes = len(self.proc_list) - - def on_cancel_clicked(self,b): + def on_cancel_clicked(self, b): ask_w = devedeng.ask.ask_window() - retval = ask_w.run(_("Cancel the current job?"),_("Cancel the current job?")) + retval = ask_w.run(_("Cancel the current job?"), + _("Cancel the current job?")) if retval: self.error = True for element in self.proc_list: element.cancel() self.wprogress.destroy() - self.emit("done",1) # there was an error + self.emit("done", 1) # there was an error return - def run(self, clear_log = True): + def run(self, clear_log=True): if clear_log: self.config.clear_log() @@ -108,7 +109,7 @@ class runner(GObject.GObject): # * the list of dependencies, or None if there are no more dependencies # * the progress bar being used by this process if (element.dependencies is None) and (element.progress_bar is None): - element.connect("ended",self.process_ended) + element.connect("ended", self.process_ended) element.run(self.progress_bars[0]) element.progress_bar = self.progress_bars[0] self.used_progress_bars.append(self.progress_bars[0]) @@ -117,11 +118,12 @@ class runner(GObject.GObject): else: self.progress_bars = [] break - self.wtotal.set_text(str(self.total_processes - len(self.proc_list))+"/"+str(self.total_processes)) - self.wtotal.set_fraction((float(self.total_processes - len(self.proc_list)))/(float(self.total_processes))) + self.wtotal.set_text( + str(self.total_processes - len(self.proc_list)) + "/" + str(self.total_processes)) + self.wtotal.set_fraction( + (float(self.total_processes - len(self.proc_list))) / (float(self.total_processes))) - - def process_ended(self,process, retval): + def process_ended(self, process, retval): if self.error: return @@ -132,10 +134,11 @@ class runner(GObject.GObject): element.cancel() self.wprogress.destroy() devedeng.error.error_window() - self.emit("done",1) # there was an error + self.emit("done", 1) # there was an error return - # move the progress bar used by this process to the list of available progress bars + # move the progress bar used by this process to the list of available + # progress bars tmp = [] for e in self.used_progress_bars: if (process.progress_bar == e): @@ -145,7 +148,8 @@ class runner(GObject.GObject): tmp.append(e) self.used_progress_bars = tmp - # remove this process from the list of processes, and remove it from the dependencies in other processes + # remove this process from the list of processes, and remove it from + # the dependencies in other processes tmp = [] for e in self.proc_list: if (e != process): @@ -158,4 +162,4 @@ class runner(GObject.GObject): self.run(False) else: self.wprogress.destroy() - self.emit("done",0) # no error + self.emit("done", 0) # no error diff --git a/src/devedeng/settings.py b/src/devedeng/settings.py index 31d3bb1..524132a 100644 --- a/src/devedeng/settings.py +++ b/src/devedeng/settings.py @@ -22,6 +22,7 @@ import devedeng.interface_manager import gettext import devedeng.converter + class settings_window(devedeng.interface_manager.interface_manager): def __init__(self): @@ -36,7 +37,7 @@ class settings_window(devedeng.interface_manager.interface_manager): cores = self.config.multicore else: if self.config.cores <= -self.config.multicore: - cores = -self.config.cores+1 + cores = -self.config.cores + 1 else: cores = self.config.multicore @@ -44,15 +45,17 @@ class settings_window(devedeng.interface_manager.interface_manager): list_core_elements = [] default_value = _("Use all cores") counter = 1 - for c in range(self.config.cores-1,-self.config.cores, -1): + for c in range(self.config.cores - 1, -self.config.cores, -1): if c > 0: - translated_string = gettext.ngettext("Use %(X)d core","Use %(X)d cores",c) % {"X":c} + translated_string = gettext.ngettext( + "Use %(X)d core", "Use %(X)d cores", c) % {"X": c} value = c if c == cores: default_value = translated_string counter += 1 elif c < 0: - translated_string = gettext.ngettext("Use all except %(X)d core","Use all except %(X)d cores", -c) % {"X": -c} + translated_string = gettext.ngettext( + "Use all except %(X)d core", "Use all except %(X)d cores", -c) % {"X": -c} value = c if c == cores: default_value = translated_string @@ -64,23 +67,26 @@ class settings_window(devedeng.interface_manager.interface_manager): self.core_elements[translated_string] = value list_core_elements.append(translated_string) - self.add_combobox("multicore",list_core_elements,default_value) + self.add_combobox("multicore", list_core_elements, default_value) self.add_filebutton("tempo_path", self.config.tmp_folder) c = devedeng.converter.converter.get_converter() - (analizers, players, menuers, converters, burners, mkiso) = c.get_available_programs() + (analizers, players, menuers, converters, + burners, mkiso) = c.get_available_programs() - self.add_combobox("analizer", analizers,self.config.film_analizer) - self.add_combobox("player", players,self.config.film_player) - self.add_combobox("converter", converters,self.config.film_converter,self.set_data_converter) - self.add_combobox("menuer", menuers,self.config.menu_converter) + self.add_combobox("analizer", analizers, self.config.film_analizer) + self.add_combobox("player", players, self.config.film_player) + self.add_combobox("converter", converters, + self.config.film_converter, self.set_data_converter) + self.add_combobox("menuer", menuers, self.config.menu_converter) self.add_combobox("mkiso", mkiso, self.config.mkiso) self.add_combobox("burner", burners, self.config.burner) self.builder = Gtk.Builder() self.builder.set_translation_domain(self.config.gettext_domain) - self.builder.add_from_file(os.path.join(self.config.glade,"wsettings.ui")) + self.builder.add_from_file(os.path.join( + self.config.glade, "wsettings.ui")) self.builder.connect_signals(self) wsettings_window = self.builder.get_object("settings") self.wconverter = self.builder.get_object("converter") @@ -105,7 +111,7 @@ class settings_window(devedeng.interface_manager.interface_manager): self.config.mkiso = self.mkiso self.config.save_config() - def set_data_converter(self,b): + def set_data_converter(self, b): self.store_ui(self.builder) cv = devedeng.converter.converter.get_converter() @@ -118,4 +124,4 @@ class settings_window(devedeng.interface_manager.interface_manager): if data != "": self.wtypes.set_text(data) else: - self.wtypes.set_text(_("No discs supported")) \ No newline at end of file + self.wtypes.set_text(_("No discs supported")) diff --git a/src/devedeng/shutdown.py b/src/devedeng/shutdown.py index a69d6b3..88bba00 100644 --- a/src/devedeng/shutdown.py +++ b/src/devedeng/shutdown.py @@ -17,6 +17,7 @@ from gi.repository import Gio, GLib + class shutdown: def __init__(self): @@ -25,12 +26,12 @@ class shutdown: try: bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) bus.call_sync("org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", - "PowerOff", GLib.Variant_boolean('(bb)', ( False , False) ), None, Gio.DBusCallFlags.NONE, -1, None) + "PowerOff", GLib.Variant_boolean('(bb)', (False, False)), None, Gio.DBusCallFlags.NONE, -1, None) except: - failure=True + failure = True if (failure): - failure=False + failure = False # If it fails, try with ConsoleKit try: @@ -38,15 +39,15 @@ class shutdown: bus.call_sync("org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", "Stop", None, None, Gio.DBusCallFlags.NONE, -1, None) except: - failure=True + failure = True if (failure): - failure=False + failure = False # If it fails, try with HAL try: bus = Gio.bus_get_sync(Gio.BusType.SYSTEM, None) - bus.call_sync("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer","org.freedesktop.Hal.Device.SystemPowerManagement", + bus.call_sync("org.freedesktop.Hal", "/org/freedesktop/Hal/devices/computer", "org.freedesktop.Hal.Device.SystemPowerManagement", "Shutdown", None, None, Gio.DBusCallFlags.NONE, -1, None) except: - failure=True + failure = True diff --git a/src/devedeng/subtitles_mux.py b/src/devedeng/subtitles_mux.py index fc0d033..c4478f6 100644 --- a/src/devedeng/subtitles_mux.py +++ b/src/devedeng/subtitles_mux.py @@ -23,6 +23,7 @@ import subprocess import devedeng.configuration_data import devedeng.executor + class subtitles_mux(devedeng.executor.executor): def __init__(self): @@ -40,9 +41,10 @@ class subtitles_mux(devedeng.executor.executor): self.subt_path = file_path self.duration = duration - self.text = _("Adding %(L)s subtitles to %(X)s") % {"X": os.path.basename(file_path), "L": subt_lang} + self.text = _("Adding %(L)s subtitles to %(X)s") % { + "X": os.path.basename(file_path), "L": subt_lang} - out_xml = open(file_path+"_s"+str(stream_id)+".xml","w") + out_xml = open(file_path + "_s" + str(stream_id) + ".xml", "w") out_xml.write(' -from gi.repository import Gtk,GObject +from gi.repository import Gtk, GObject import os + class title(GObject.GObject): counter = 0 - def __init__(self,config,file_treeview,original_liststore,title_name = None): + def __init__(self, config, file_treeview, original_liststore, title_name=None): GObject.GObject.__init__(self) self.config = config self.file_treeview = file_treeview if (title_name is None): title.counter += 1 - self.title_name = _("Title %(X)d") % {"X":title.counter} + self.title_name = _("Title %(X)d") % {"X": title.counter} else: self.title_name = title_name self.post_action = "stop" @@ -39,7 +40,7 @@ class title(GObject.GObject): self.files = Gtk.ListStore() self.files.set_column_types(columns) - def set_type(self,disc_type): + def set_type(self, disc_type): self.disc_type = disc_type @@ -48,7 +49,8 @@ class title(GObject.GObject): builder = Gtk.Builder() builder.set_translation_domain(self.config.gettext_domain) - builder.add_from_file(os.path.join(self.config.glade,"wtitle_properties.ui")) + builder.add_from_file(os.path.join( + self.config.glade, "wtitle_properties.ui")) builder.connect_signals(self) # Interface widgets @@ -82,15 +84,14 @@ class title(GObject.GObject): wtitle_properties.destroy() - def delete_title(self): - print("Deleted title "+self.title_name) + print("Deleted title " + self.title_name) def refresh(self): self.file_treeview.set_model(self.files) - def add_file(self,new_file): + def add_file(self, new_file): self.files.append([new_file.file_name, new_file]) diff --git a/src/devedeng/vcdimager_converter.py b/src/devedeng/vcdimager_converter.py index 111d682..3e42e44 100644 --- a/src/devedeng/vcdimager_converter.py +++ b/src/devedeng/vcdimager_converter.py @@ -21,6 +21,7 @@ import os import devedeng.configuration_data import devedeng.executor + class vcdimager_converter(devedeng.executor.executor): def __init__(self): @@ -28,14 +29,14 @@ class vcdimager_converter(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def create_cd_project (self, path, name, file_movies): + def create_cd_project(self, path, name, file_movies): - self.command_var=[] + self.command_var = [] self.command_var.append("vcdimager") self.command_var.append("-c") - self.command_var.append(os.path.join(path,name+".cue")) + self.command_var.append(os.path.join(path, name + ".cue")) self.command_var.append("-b") - self.command_var.append(os.path.join(path,name+".bin")) + self.command_var.append(os.path.join(path, name + ".bin")) self.command_var.append("-t") if self.config.disc_type == "vcd": self.command_var.append("vcd2") @@ -45,11 +46,10 @@ class vcdimager_converter(devedeng.executor.executor): self.command_var.append(element.converted_filename) self.text = _("Creating CD image") - - def process_stdout(self,data): - print("Stdout: "+str(data)) + def process_stdout(self, data): + print("Stdout: " + str(data)) return - def process_stderr(self,data): - print("Stderr: "+str(data)) + def process_stderr(self, data): + print("Stderr: " + str(data)) return diff --git a/src/devedeng/vlc.py b/src/devedeng/vlc.py index 0c76d93..4a66a0f 100644 --- a/src/devedeng/vlc.py +++ b/src/devedeng/vlc.py @@ -19,6 +19,7 @@ import subprocess import devedeng.configuration_data import devedeng.executor + class vlc(devedeng.executor.executor): supports_analize = False @@ -32,9 +33,10 @@ class vlc(devedeng.executor.executor): @staticmethod def check_is_installed(): try: - handle = subprocess.Popen(["vlc","-h"], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + handle = subprocess.Popen( + ["vlc", "-h"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) (stdout, stderr) = handle.communicate() - if 0==handle.wait(): + if 0 == handle.wait(): return True else: return False @@ -46,13 +48,13 @@ class vlc(devedeng.executor.executor): devedeng.executor.executor.__init__(self) self.config = devedeng.configuration_data.configuration.get_config() - def play_film(self,file_name): + def play_film(self, file_name): - command_line = ["vlc", "--play-and-exit",file_name] + command_line = ["vlc", "--play-and-exit", file_name] self.launch_process(command_line) - def process_stdout(self,data): + def process_stdout(self, data): return - def process_stderr(self,data): + def process_stderr(self, data): return diff --git a/src/unitests/test_avconv.py b/src/unitests/test_avconv.py index 8cd3222..c327a08 100755 --- a/src/unitests/test_avconv.py +++ b/src/unitests/test_avconv.py @@ -2,6 +2,7 @@ import unittest import devedeng.avbase import devedeng.avprobe + class TestAVConv(unittest.TestCase): def test_ubuntu_14_04(self): @@ -19,9 +20,10 @@ libswscale 2. 1. 1 / 2. 1. 1""".split("\n") text.append(9) c.check_version_txt(text) - self.assertEqual(c.major_version, 9, "Detecting major version for Ubuntu 14.04's AVConv version") - self.assertEqual(c.minor_version, 18, "Detecting minor version for Ubuntu 14.04's AVConv version") - + self.assertEqual( + c.major_version, 9, "Detecting major version for Ubuntu 14.04's AVConv version") + self.assertEqual( + c.minor_version, 18, "Detecting minor version for Ubuntu 14.04's AVConv version") def test_ubuntu_14_10(self): c = devedeng.avbase.avbase() @@ -38,9 +40,10 @@ libswscale 3. 0. 0 / 3. 0. 0""".split("\n") text.append(9) c.check_version_txt(text) - self.assertEqual(c.major_version, 11, "Detecting major version for Ubuntu 14.10's AVConv version") - self.assertEqual(c.minor_version, 0, "Detecting minor version for Ubuntu 14.10's AVConv version") - + self.assertEqual( + c.major_version, 11, "Detecting major version for Ubuntu 14.10's AVConv version") + self.assertEqual( + c.minor_version, 0, "Detecting minor version for Ubuntu 14.10's AVConv version") def test_ubuntu_15_04(self): c = devedeng.avbase.avbase() @@ -57,13 +60,13 @@ libswscale 3. 0. 0 / 3. 0. 0""".split("\n") text.append(9) c.check_version_txt(text) - self.assertEqual(c.major_version, 11, "Detecting major version for Ubuntu 15.04's AVConv version") - self.assertEqual(c.minor_version, 2, "Detecting minor version for Ubuntu 15.04's AVConv version") - + self.assertEqual( + c.major_version, 11, "Detecting major version for Ubuntu 15.04's AVConv version") + self.assertEqual( + c.minor_version, 2, "Detecting minor version for Ubuntu 15.04's AVConv version") def test_mkv1(self): - c = devedeng.avprobe.avprobe() json_test = """{ "streams": [ @@ -163,12 +166,14 @@ libswscale 3. 0. 0 / 3. 0. 0""".split("\n") } ] }""" - retval = c.process_json(json_test,"filename.mkv") + retval = c.process_json(json_test, "filename.mkv") self.assertFalse(retval) - self.assertEqual(c.audio_streams, 1, "Checking number of audio streams") + self.assertEqual(c.audio_streams, 1, + "Checking number of audio streams") self.assertEqual(c.audio_list[0], 0, "Checking audio stream 1") - self.assertEqual(c.video_streams, 1, "Checking number of video streams") + self.assertEqual(c.video_streams, 1, + "Checking number of video streams") self.assertEqual(c.video_list[0], 1, "Checking video stream 1") if __name__ == '__main__': - unittest.main() \ No newline at end of file + unittest.main()