Exemple #1
0
def gen_synctest_configs():
    def test_path(fname):
        return os.path.join('test-data', fname)
    if INTEGRATION not in os.environ or os.environ[INTEGRATION] == 0:
        return
    with open('test-data/integration-testing-config.yaml', 'r') as f:
        config = yaml.load(f, yaml.SafeLoader)
    parser = ffsubsync.make_parser()
    for test in config[SYNC_TESTS]:
        if SKIP in test and test[SKIP]:
            continue
        unparsed_args = [test_path(test[REF]), '-i', test_path(test[UNSYNCED])]
        if EXTRA_ARGS in test:
            for extra_key, extra_value in test[EXTRA_ARGS].items():
                unparsed_args.extend(['--{}'.format(extra_key), str(extra_value)])
        if EXTRA_NO_VALUE_ARGS in test:
            for extra_key in test[EXTRA_NO_VALUE_ARGS]:
                unparsed_args.append('--{}'.format(extra_key))
        args = parser.parse_args(unparsed_args)
        truth = test_path(test[SYNCED])
        should_filecmp = True
        if FILECMP in test:
            should_filecmp = test[FILECMP]
        should_detect_encoding = None
        if SHOULD_DETECT_ENCODING in test:
            should_detect_encoding = test[SHOULD_DETECT_ENCODING]
        yield args, truth, should_filecmp, should_detect_encoding
Exemple #2
0
    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
Exemple #3
0
 def __init__(self, skip_subsync, ost_username, ost_password, tmdb_key):
     self.skip_subsync = skip_subsync
     self.ost = OpenSubtitles()
     try:
         self.ost.login(ost_username, ost_password)
     except Exception as e:
         logging.error("Failed to log into opensubtitles.org.")
         raise e
     self.ost_language = 'eng'
     if tmdb_key:
         self.media_searcher = MediaSearcher(tmdb_key)
     if not self.skip_subsync:
         self.subsync_parser = ffsubsync.make_parser()
Exemple #4
0
    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