mirror of
https://github.com/morpheus65535/bazarr.git
synced 2024-11-11 01:23:38 +08:00
Added debug mode for subtitles synchronization.
This commit is contained in:
parent
6ad4843cdf
commit
88452468cf
3 changed files with 42 additions and 19 deletions
|
@ -162,7 +162,8 @@ defaults = {
|
|||
'use_subsync_threshold': 'False',
|
||||
'subsync_threshold': '90',
|
||||
'use_subsync_movie_threshold': 'False',
|
||||
'subsync_movie_threshold': '70'
|
||||
'subsync_movie_threshold': '70',
|
||||
'debug': 'False'
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,8 @@ from utils import get_binary
|
|||
from utils import history_log, history_log_movie
|
||||
from get_languages import alpha2_from_alpha3, language_from_alpha3
|
||||
from helper import path_mappings
|
||||
from config import settings
|
||||
from get_args import args
|
||||
|
||||
|
||||
class SubSyncer:
|
||||
|
@ -15,12 +17,13 @@ class SubSyncer:
|
|||
self.ffmpeg_path = None
|
||||
self.args = None
|
||||
self.vad = 'subs_then_auditok'
|
||||
self.log_dir_path = os.path.join(args.config_dir, 'log')
|
||||
|
||||
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.srtout = '{}.synced.srt'.format(os.path.splitext(self.srtin)[0])
|
||||
self.args = None
|
||||
|
||||
ffprobe_exe = get_binary('ffprobe')
|
||||
|
@ -39,8 +42,10 @@ class SubSyncer:
|
|||
|
||||
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]
|
||||
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)
|
||||
|
@ -49,20 +54,24 @@ class SubSyncer:
|
|||
'{0}'.format(self.srtin))
|
||||
else:
|
||||
if result['sync_was_successful']:
|
||||
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_alpha3(srt_lang), offset_seconds,
|
||||
"{:.2f}".format(framerate_scale_factor))
|
||||
if not settings.subsync.getboolean('debug'):
|
||||
os.remove(self.srtin)
|
||||
os.rename(self.srtout, self.srtin)
|
||||
|
||||
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)
|
||||
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_alpha3(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=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))
|
||||
|
||||
|
|
|
@ -412,14 +412,26 @@
|
|||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="col-sm-3 text-right">
|
||||
<b>Subtitles synchronization</b>
|
||||
<b>Automatic subtitles synchronization</b>
|
||||
</div>
|
||||
<div class="form-group col-sm-8">
|
||||
<label class="custom-control custom-checkbox">
|
||||
<input type="checkbox" class="custom-control-input" id="settings-subsync-use_subsync" name="settings-subsync-use_subsync">
|
||||
<span class="custom-control-label" for="settings-subsync-use_subsync"></span>
|
||||
</label>
|
||||
<label>Enable the subtitles synchronization after downloading a subtitles.</label>
|
||||
<label>Enable the automatic subtitles synchronization after downloading a subtitles.</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-sm-4 text-right">
|
||||
<b>Subtitles synchronization debugging</b>
|
||||
</div>
|
||||
<div class="form-group col-sm-8">
|
||||
<label class="custom-control custom-checkbox">
|
||||
<input type="checkbox" class="custom-control-input" id="settings-subsync-debug" name="settings-subsync-debug">
|
||||
<span class="custom-control-label" for="settings-subsync-debug"></span>
|
||||
</label>
|
||||
<label>Do not actually sync the subtitles but generate a .tar.gz file to be able to open an issue for ffsubsync. This file will reside alongside the media file.</label>
|
||||
</div>
|
||||
</div>
|
||||
<div id="subsync_div">
|
||||
|
@ -680,6 +692,7 @@
|
|||
$('#settings-general-chmod_enabled').prop('checked', {{'true' if settings.general.getboolean('chmod_enabled') else 'false'}}).trigger('change');
|
||||
$('#settings-subsync-use_subsync').prop('checked', {{'true' if settings.subsync.getboolean('use_subsync') else 'false'}}).trigger('change');
|
||||
$('#settings-subsync-use_subsync_threshold').prop('checked', {{'true' if settings.subsync.getboolean('use_subsync_threshold') else 'false'}}).trigger('change');
|
||||
$('#settings-subsync-debug').prop('checked', {{'true' if settings.subsync.getboolean('debug') else 'false'}}).trigger('change');
|
||||
$('#settings-subsync-use_subsync_movie_threshold').prop('checked', {{'true' if settings.subsync.getboolean('use_subsync_movie_threshold') else 'false'}}).trigger('change');
|
||||
$('#settings-general-use_postprocessing').prop('checked', {{'true' if settings.general.getboolean('use_postprocessing') else 'false'}}).trigger('change');
|
||||
$('#settings-general-use_postprocessing_threshold').prop('checked', {{'true' if settings.general.getboolean('use_postprocessing_threshold') else 'false'}}).trigger('change');
|
||||
|
|
Loading…
Reference in a new issue