Esempio n. 1
0
 def _load_subtitle_run_script(self, subtitle_file, encoding):
     """Try to run the Submod-script in a new thread.
     """
     try:
         subtitle_loader = lambda f: self._load_subtitle(f, encoding)
         subtitle_list = self._submod.run(subtitle_file, subtitle_loader,
                                          self._cuts)
     except Exception as e:
         # Maybe the subtitle-checksum was wrong. Then an Exception
         # is raised before the subtitle was loaded. In that case
         # _load_subtitle was not called and thus the
         # STEP_RUNNING_SUBMOD-icons are not shown yet.
         # NOTE: _load_subtitle may raise an Exception, too.
         self._show_step_icons(self.STEP_RUNNING_SUBMOD)
         self._error(self.STEP_RUNNING_SUBMOD, unicode(e))
         return
     # Script has run, now save the new subtitle list.
     self._show_step_icons(self.STEP_SAVING_SUBTITLE)
     dir_, __ = path.split(self._script_file)
     # Generate name for new subtitle file based on the name of the
     # old subtitle file. '_submod' will be added before the file
     # extension. If the file already exists a new filename is
     # generated (by adding '.1', '.2' .. before the extension)
     # until a non existing filename is found.
     subtitle_filename = self._submod.script['subtitle']['filename']
     name_parts = subtitle_filename.rsplit('.', 1)
     name_base = name_parts[0] + '_submod'
     ext = '.'+name_parts[1] if len(name_parts)==2 else ''
     new_subtitle_file = path.join(dir_, name_base + ext)
     c = 0
     while path.isfile(new_subtitle_file):
         c += 1
         new_subtitle_file = path.join(dir_, name_base + '.' + str(c) + ext)
     try:
         SubtitleFile.save_srt(new_subtitle_file, subtitle_list)
     except Exception as e:
         self._error(self.STEP_SAVING_SUBTITLE, unicode(e))
         return
     self._show_step_icons(self.STEP_DONE)
     GLib.idle_add(self._allow_close)
Esempio n. 2
0
 def _load_subtitle(self, subtitle_file, encoding):
     subtitle_list = SubtitleFile.load_srt(subtitle_file, encoding)
     self._show_step_icons(self.STEP_RUNNING_SUBMOD)
     return subtitle_list