Multiple fixes to ffsubsync.

This commit is contained in:
Louis Vézina 2020-08-19 15:23:43 -04:00
parent 5dbde75893
commit 6ad4843cdf
1 changed files with 17 additions and 7 deletions

View File

@ -41,12 +41,15 @@ def make_test_case(args, npy_savename, sync_was_successful):
raise ValueError('need non-null npy_savename')
tar_dir = '{}.{}'.format(
args.reference,
datetime.now().strftime('%Y-%m-%d-%H:%M:%S')
datetime.now().strftime('%Y-%m-%d-%H-%M-%S')
)
logger.info('creating test archive {}.tar.gz...'.format(tar_dir))
os.mkdir(tar_dir)
try:
shutil.move('ffsubsync.log', tar_dir)
log_path = 'ffsubsync.log'
if args.log_dir_path and os.path.isdir(args.log_dir_path):
log_path = os.path.join(args.log_dir_path, log_path)
shutil.move(log_path, tar_dir)
shutil.copy(args.srtin, tar_dir)
if sync_was_successful:
shutil.move(args.srtout, tar_dir)
@ -62,10 +65,10 @@ def make_test_case(args, npy_savename, sync_was_successful):
if archive_format in supported_formats:
shutil.make_archive(tar_dir, 'gztar', os.curdir, tar_dir)
break
else:
logger.error('failed to create test archive; no formats supported '
'(this should not happen)')
return 1
else:
logger.error('failed to create test archive; no formats supported '
'(this should not happen)')
return 1
logger.info('...done')
finally:
shutil.rmtree(tar_dir)
@ -265,7 +268,10 @@ def run(args):
result['retval'] = 1
return result
if args.make_test_case:
handler = logging.FileHandler('ffsubsync.log')
log_path = 'ffsubsync.log'
if args.log_dir_path and os.path.isdir(args.log_dir_path):
log_path = os.path.join(args.log_dir_path, log_path)
handler = logging.FileHandler(log_path)
logger.addHandler(handler)
if args.extract_subs_from_stream is not None:
result['retval'] = extract_subtitles_from_reference(args)
@ -286,6 +292,8 @@ def run(args):
srt_pipes = make_srt_pipes(args)
sync_was_successful = try_sync(args, reference_pipe, srt_pipes, result)
if args.make_test_case:
handler.close()
logger.removeHandler(handler)
result['retval'] += make_test_case(args, npy_savename, sync_was_successful)
return result
@ -354,6 +362,8 @@ def add_cli_only_args(parser):
'--ffmpeg-path', '--ffmpegpath', default=None,
help='Where to look for ffmpeg and ffprobe. Uses the system PATH by default.'
)
parser.add_argument('--log-dir-path', default=None, help='Where to save ffsubsync.log file (must be an existing '
'directory).')
parser.add_argument('--vlc-mode', action='store_true', help=argparse.SUPPRESS)
parser.add_argument('--gui-mode', action='store_true', help=argparse.SUPPRESS)