ff
This commit is contained in:
37
bin/ffx.py
37
bin/ffx.py
@@ -412,16 +412,16 @@ def streams(filename):
|
|||||||
@click.option('-dts', '--dts-bitrate', type=int, default=DEFAULT_DTS_BANDWIDTH, help=f"Bitrate in kbit/s to be used to encode 6.1 audio streams (default: {DEFAULT_DTS_BANDWIDTH})")
|
@click.option('-dts', '--dts-bitrate', type=int, default=DEFAULT_DTS_BANDWIDTH, help=f"Bitrate in kbit/s to be used to encode 6.1 audio streams (default: {DEFAULT_DTS_BANDWIDTH})")
|
||||||
|
|
||||||
@click.option('-sd', '--subtitle-directory', type=str, default='', help='Load subtitles from here')
|
@click.option('-sd', '--subtitle-directory', type=str, default='', help='Load subtitles from here')
|
||||||
@click.option('-sl', '--subtitle-label', type=str, default='', help='Subtitle filename prefix')
|
@click.option('-sp', '--subtitle-prefix', type=str, default='', help='Subtitle filename prefix')
|
||||||
|
|
||||||
@click.option('-ss', '--subtitle-language', type=str, default='', help='Subtitle stream language(s)')
|
@click.option('-ss', '--subtitle-language', type=str, multiple=True, help='Subtitle stream language(s)')
|
||||||
@click.option('-st', '--subtitle-title', type=str, default='', help='Subtitle stream title(s)')
|
@click.option('-st', '--subtitle-title', type=str, multiple=True, help='Subtitle stream title(s)')
|
||||||
|
|
||||||
@click.option('-ds', '--default-subtitle', type=int, default=-1, help='Index of default subtitle stream')
|
@click.option('-ds', '--default-subtitle', type=int, default=-1, help='Index of default subtitle stream')
|
||||||
@click.option('-fs', '--forced-subtitle', type=int, default=-1, help='Index of forced subtitle stream') # (including default audio stream tag)
|
@click.option('-fs', '--forced-subtitle', type=int, default=-1, help='Index of forced subtitle stream') # (including default audio stream tag)
|
||||||
|
|
||||||
@click.option('-as', '--audio-language', type=str, default='', help='Audio stream language(s)')
|
@click.option('-as', '--audio-language', type=str, multiple=True, help='Audio stream language(s)')
|
||||||
@click.option('-at', '--audio-title', type=str, default='', help='Audio stream title(s)')
|
@click.option('-at', '--audio-title', type=str, multiple=True, help='Audio stream title(s)')
|
||||||
|
|
||||||
@click.option('-da', '--default-audio', type=int, default=-1, help='Index of default audio stream')
|
@click.option('-da', '--default-audio', type=int, default=-1, help='Index of default audio stream')
|
||||||
|
|
||||||
@@ -449,7 +449,7 @@ def convert(ctx,
|
|||||||
ac3_bitrate,
|
ac3_bitrate,
|
||||||
dts_bitrate,
|
dts_bitrate,
|
||||||
subtitle_directory,
|
subtitle_directory,
|
||||||
subtitle_label,
|
subtitle_prefix,
|
||||||
subtitle_language,
|
subtitle_language,
|
||||||
subtitle_title,
|
subtitle_title,
|
||||||
default_subtitle,
|
default_subtitle,
|
||||||
@@ -493,17 +493,17 @@ def convert(ctx,
|
|||||||
click.echo(f"DTS bitrate: {context['bitrates']['dts']}")
|
click.echo(f"DTS bitrate: {context['bitrates']['dts']}")
|
||||||
|
|
||||||
# Parse subtitle files
|
# Parse subtitle files
|
||||||
context['import_subtitles'] = (subtitle_directory and subtitle_label)
|
context['import_subtitles'] = (subtitle_directory and subtitle_prefix)
|
||||||
|
|
||||||
se_match = re.compile(SEASON_EPISODE_INDICATOR_MATCH)
|
se_match = re.compile(SEASON_EPISODE_INDICATOR_MATCH)
|
||||||
e_match = re.compile(EPISODE_INDICATOR_MATCH)
|
e_match = re.compile(EPISODE_INDICATOR_MATCH)
|
||||||
sesl_match = re.compile(SEASON_EPISODE_STREAM_LANGUAGE_MATCH)
|
sesl_match = re.compile(SEASON_EPISODE_STREAM_LANGUAGE_MATCH)
|
||||||
|
|
||||||
|
|
||||||
availableSubtitles = []
|
availableFileSubtitles = []
|
||||||
if context['import_subtitles']:
|
if context['import_subtitles']:
|
||||||
for subtitleFilename in os.listdir(subtitle_directory):
|
for subtitleFilename in os.listdir(subtitle_directory):
|
||||||
if subtitleFilename.startswith(subtitle_label) and subtitleFilename.endswith('.' + SUBTITLE_FILE_EXTENSION):
|
if subtitleFilename.startswith(subtitle_prefix) and subtitleFilename.endswith('.' + SUBTITLE_FILE_EXTENSION):
|
||||||
sesl_result = sesl_match.search(subtitleFilename)
|
sesl_result = sesl_match.search(subtitleFilename)
|
||||||
if sesl_result is not None:
|
if sesl_result is not None:
|
||||||
subtitleFilePath = os.path.join(subtitle_directory, subtitleFilename)
|
subtitleFilePath = os.path.join(subtitle_directory, subtitleFilename)
|
||||||
@@ -514,16 +514,16 @@ def convert(ctx,
|
|||||||
subtitleFileDescriptor['episode'] = int(sesl_result.group(2))
|
subtitleFileDescriptor['episode'] = int(sesl_result.group(2))
|
||||||
subtitleFileDescriptor['stream'] = int(sesl_result.group(3))
|
subtitleFileDescriptor['stream'] = int(sesl_result.group(3))
|
||||||
subtitleFileDescriptor['language'] = sesl_result.group(4)
|
subtitleFileDescriptor['language'] = sesl_result.group(4)
|
||||||
availableSubtitles.append(subtitleFileDescriptor)
|
availableFileSubtitles.append(subtitleFileDescriptor)
|
||||||
|
|
||||||
click.echo(f"Found {len(availableSubtitles)} subtitles in files")
|
click.echo(f"Found {len(availableFileSubtitles)} subtitles in files")
|
||||||
|
|
||||||
|
|
||||||
subtitleLanguages = subtitle_language.split(',') if subtitle_language else []
|
subtitleLanguages = subtitle_language
|
||||||
subtitleTitles = subtitle_title.split(',') if subtitle_title else []
|
subtitleTitles = subtitle_title
|
||||||
|
|
||||||
audioLanguages = audio_language.split(',') if audio_language else []
|
audioLanguages = audio_language
|
||||||
audioTitles = audio_title.split(',') if audio_title else []
|
audioTitles = audio_title
|
||||||
|
|
||||||
|
|
||||||
# Process crop parameters
|
# Process crop parameters
|
||||||
@@ -625,8 +625,8 @@ def convert(ctx,
|
|||||||
subtitleFileTokens = []
|
subtitleFileTokens = []
|
||||||
matchingSubtitles = []
|
matchingSubtitles = []
|
||||||
if context['import_subtitles']:
|
if context['import_subtitles']:
|
||||||
subtitles = [a for a in availableSubtitles if a['season'] == season and a['episode'] == episode]
|
|
||||||
|
|
||||||
|
subtitles = [a for a in availableFileSubtitles if a['season'] == season and a['episode'] == episode]
|
||||||
mSubtitles = sorted(subtitles, key=lambda d: d['stream'])
|
mSubtitles = sorted(subtitles, key=lambda d: d['stream'])
|
||||||
|
|
||||||
for sfd in mSubtitles:
|
for sfd in mSubtitles:
|
||||||
@@ -636,6 +636,9 @@ def convert(ctx,
|
|||||||
mSubtitles[streamIndex]['forced'] = 1 if forced_subtitle != -1 and streamIndex == forced_subtitle else 0
|
mSubtitles[streamIndex]['forced'] = 1 if forced_subtitle != -1 and streamIndex == forced_subtitle else 0
|
||||||
mSubtitles[streamIndex]['default'] = 1 if default_subtitle != -1 and streamIndex == default_subtitle else 0
|
mSubtitles[streamIndex]['default'] = 1 if default_subtitle != -1 and streamIndex == default_subtitle else 0
|
||||||
|
|
||||||
|
if streamIndex <= len(subtitleTitles) -1:
|
||||||
|
mSubtitles[streamIndex]['title'] = subtitleTitles[streamIndex]
|
||||||
|
|
||||||
if default_subtitle == -1:
|
if default_subtitle == -1:
|
||||||
matchingSubtitles = mSubtitles
|
matchingSubtitles = mSubtitles
|
||||||
else:
|
else:
|
||||||
@@ -732,6 +735,8 @@ def convert(ctx,
|
|||||||
|
|
||||||
msg = matchingSubtitles[fileIndex]
|
msg = matchingSubtitles[fileIndex]
|
||||||
subtitleMetadataTokens += [f"-metadata:s:s:{fileIndex}", f"language={msg['language']}"]
|
subtitleMetadataTokens += [f"-metadata:s:s:{fileIndex}", f"language={msg['language']}"]
|
||||||
|
if 'title' in matchingSubtitles[fileIndex].keys():
|
||||||
|
subtitleMetadataTokens += [f"-metadata:s:s:{fileIndex}", f"title={matchingSubtitles[fileIndex]['title']}"]
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user