def main(): parser = make_parser() _ = parser.parse_args() # Fool Gooey into presenting the simpler menu add_cli_only_args(parser) args = parser.parse_args() args.gui_mode = True return run(args)
def sync(self, video_path, srt_path, srt_lang, media_type, sonarr_series_id=None, sonarr_episode_id=None, radarr_id=None): self.reference = video_path self.srtin = srt_path self.srtout = '{}.synced.srt'.format(os.path.splitext(self.srtin)[0]) self.args = None ffprobe_exe = get_binary('ffprobe') if not ffprobe_exe: logging.debug('BAZARR FFprobe not found!') return else: logging.debug('BAZARR FFprobe used is %s', ffprobe_exe) ffmpeg_exe = get_binary('ffmpeg') if not ffmpeg_exe: logging.debug('BAZARR FFmpeg not found!') return else: logging.debug('BAZARR FFmpeg used is %s', ffmpeg_exe) self.ffmpeg_path = os.path.dirname(ffmpeg_exe) try: unparsed_args = [self.reference, '-i', self.srtin, '-o', self.srtout, '--ffmpegpath', self.ffmpeg_path, '--vad', self.vad, '--log-dir-path', self.log_dir_path] if settings.subsync.getboolean('debug'): unparsed_args.append('--make-test-case') parser = make_parser() self.args = parser.parse_args(args=unparsed_args) result = run(self.args) except Exception as e: logging.exception('BAZARR an exception occurs during the synchronization process for this subtitles: ' '{0}'.format(self.srtin)) else: if settings.subsync.getboolean('debug'): return result if os.path.isfile(self.srtout): if not settings.subsync.getboolean('debug'): os.remove(self.srtin) os.rename(self.srtout, self.srtin) offset_seconds = result['offset_seconds'] or 0 framerate_scale_factor = result['framerate_scale_factor'] or 0 message = "{0} subtitles synchronization ended with an offset of {1} seconds and a framerate " \ "scale factor of {2}.".format(language_from_alpha2(srt_lang), offset_seconds, "{:.2f}".format(framerate_scale_factor)) if media_type == 'series': history_log(action=5, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id, description=message, video_path=path_mappings.path_replace_reverse(self.reference), language=srt_lang, subtitles_path=srt_path) else: history_log_movie(action=5, radarr_id=radarr_id, description=message, video_path=path_mappings.path_replace_reverse_movie(self.reference), language=srt_lang, subtitles_path=srt_path) else: logging.error('BAZARR unable to sync subtitles: {0}'.format(self.srtin)) return result
def test_sync_matches_ground_truth(args, truth, should_filecmp, should_detect_encoding): # context manager TemporaryDirectory not available on py2 dirpath = tempfile.mkdtemp() try: args.srtout = os.path.join(dirpath, 'test' + os.path.splitext(args.srtin)[-1]) assert ffsubsync.run(args)['retval'] == 0 if should_filecmp: assert filecmp.cmp(args.srtout, truth, shallow=False) else: assert timestamps_roughly_match(args.srtout, truth) if should_detect_encoding is not None: assert detected_encoding(args.srtin) == should_detect_encoding finally: shutil.rmtree(dirpath)
def sync(self, video_path, srt_path, srt_lang, media_type, sonarr_series_id=None, sonarr_episode_id=None, radarr_id=None): self.reference = video_path self.srtin = srt_path self.srtout = None ffprobe_exe = get_binary('ffprobe') if not ffprobe_exe: logging.debug('BAZARR FFprobe not found!') return else: logging.debug('BAZARR FFprobe used is %s', ffprobe_exe) api.initialize({'provider': 'ffmpeg', 'ffmpeg': ffprobe_exe}) data = api.know(self.reference) using_what = None if 'subtitle' in data: for i, embedded_subs in enumerate(data['subtitle']): if 'language' in embedded_subs: language = embedded_subs['language'].alpha3 if language == "eng": using_what = "English embedded subtitle track" self.reference_stream = "s:{}".format(i) break if not self.reference_stream: using_what = "{0} embedded subtitle track".format( language_from_alpha3(embedded_subs['language'].alpha3) or 'unknown language embedded subtitles ' 'track') self.reference_stream = "s:0" elif 'audio' in data: audio_tracks = data['audio'] for i, audio_track in enumerate(audio_tracks): if 'language' in audio_track: language = audio_track['language'].alpha3 if language == srt_lang: using_what = "{0} audio track".format(language_from_alpha3(audio_track['language'].alpha3) or 'unknown language audio track') self.reference_stream = "a:{}".format(i) break if not self.reference_stream: audio_tracks = data['audio'] for i, audio_track in enumerate(audio_tracks): if 'language' in audio_track: language = audio_track['language'].alpha3 if language == "eng": using_what = "English audio track" self.reference_stream = "a:{}".format(i) break if not self.reference_stream: using_what = "first audio track" self.reference_stream = "a:0" else: raise NoAudioTrack ffmpeg_exe = get_binary('ffmpeg') if not ffmpeg_exe: logging.debug('BAZARR FFmpeg not found!') return else: logging.debug('BAZARR FFmpeg used is %s', ffmpeg_exe) self.ffmpeg_path = os.path.dirname(ffmpeg_exe) try: result = run(self) except Exception as e: logging.error('BAZARR an exception occurs during the synchronization process for this subtitles: ' + self.srtin) else: if result['sync_was_successful']: message = "{0} subtitles synchronization ended with an offset of {1} seconds and a framerate scale " \ "factor of {2} using {3} (0:{4}).".format(language_from_alpha3(srt_lang), result['offset_seconds'], result['framerate_scale_factor'], using_what, self.reference_stream) if media_type == 'series': history_log(action=5, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id, description=message, video_path=path_mappings.path_replace_reverse(self.reference), language=alpha2_from_alpha3(srt_lang), subtitles_path=srt_path) else: history_log_movie(action=5, radarr_id=radarr_id, description=message, video_path=path_mappings.path_replace_reverse_movie(self.reference), language=alpha2_from_alpha3(srt_lang), subtitles_path=srt_path) else: logging.error('BAZARR unable to sync subtitles using {0}({1}): {2}'.format(using_what, self.reference_stream, self.srtin)) return result
def run_subsync(self, reference, srtin, srtout): ffsubsync.run(self.subsync_parser.parse_args([ reference, '-i', srtin, '-o', srtout ]))
def sync(self, video_path, srt_path, srt_lang, media_type, sonarr_series_id=None, sonarr_episode_id=None, radarr_id=None): self.reference = video_path self.srtin = srt_path self.srtout = None self.args = None ffprobe_exe = get_binary('ffprobe') if not ffprobe_exe: logging.debug('BAZARR FFprobe not found!') return else: logging.debug('BAZARR FFprobe used is %s', ffprobe_exe) ffmpeg_exe = get_binary('ffmpeg') if not ffmpeg_exe: logging.debug('BAZARR FFmpeg not found!') return else: logging.debug('BAZARR FFmpeg used is %s', ffmpeg_exe) self.ffmpeg_path = os.path.dirname(ffmpeg_exe) try: unparsed_args = [ self.reference, '-i', self.srtin, '--overwrite-input', '--ffmpegpath', self.ffmpeg_path, '--vad', self.vad ] parser = make_parser() self.args = parser.parse_args(args=unparsed_args) result = run(self.args) except Exception as e: logging.exception( 'BAZARR an exception occurs during the synchronization process for this subtitles: ' '{0}'.format(self.srtin)) else: if result['sync_was_successful']: message = "{0} subtitles synchronization ended with an offset of {1} seconds and a framerate scale " \ "factor of {2}.".format(language_from_alpha3(srt_lang), result['offset_seconds'], "{:.2f}".format(result['framerate_scale_factor'])) if media_type == 'series': history_log(action=5, sonarr_series_id=sonarr_series_id, sonarr_episode_id=sonarr_episode_id, description=message, video_path=path_mappings.path_replace_reverse( self.reference), language=alpha2_from_alpha3(srt_lang), subtitles_path=srt_path) else: history_log_movie( action=5, radarr_id=radarr_id, description=message, video_path=path_mappings.path_replace_reverse_movie( self.reference), language=alpha2_from_alpha3(srt_lang), subtitles_path=srt_path) else: logging.error('BAZARR unable to sync subtitles: {0}'.format( self.srtin)) return result