Adds subtitle default dir
This commit is contained in:
@@ -39,6 +39,14 @@ CPU_OPTION_HELP = (
|
||||
+ "(about 2 cores), or use a percentage such as 25% for a share of present cores. "
|
||||
+ "Omit to disable; 0 also disables."
|
||||
)
|
||||
SUBTITLE_DIRECTORY_OPTION_HELP = (
|
||||
"Load subtitles from here. When omitted and --subtitle-prefix is set, "
|
||||
+ "FFX uses the configured subtitlesDirectory base path plus the prefix as a subdirectory."
|
||||
)
|
||||
SUBTITLE_PREFIX_OPTION_HELP = (
|
||||
"Subtitle filename prefix. Requires --subtitle-directory, or a configured "
|
||||
+ "subtitlesDirectory base path that contains a matching <prefix>/ subdirectory."
|
||||
)
|
||||
CROPDETECT_SEEK_OPTION_HELP = (
|
||||
"Start crop detection this many seconds into the input. "
|
||||
+ "Useful for skipping logos, intros, or black frames."
|
||||
@@ -117,6 +125,41 @@ def normalizeCutOption(ctx, param, value):
|
||||
raise click.BadParameter(str(ex)) from ex
|
||||
|
||||
|
||||
def resolveSubtitleImportOptions(context, subtitleDirectory, subtitlePrefix):
|
||||
resolvedSubtitlePrefix = str(subtitlePrefix).strip()
|
||||
resolvedSubtitleDirectory = (
|
||||
os.path.expanduser(str(subtitleDirectory).strip())
|
||||
if subtitleDirectory
|
||||
else ''
|
||||
)
|
||||
|
||||
if not resolvedSubtitlePrefix:
|
||||
return False, resolvedSubtitleDirectory, resolvedSubtitlePrefix
|
||||
|
||||
if resolvedSubtitleDirectory:
|
||||
return True, resolvedSubtitleDirectory, resolvedSubtitlePrefix
|
||||
|
||||
configuredSubtitlesBaseDirectory = context['config'].getSubtitlesDirectoryPath()
|
||||
if not configuredSubtitlesBaseDirectory:
|
||||
raise click.ClickException(
|
||||
"Subtitle prefix was set but no --subtitle-directory was provided and "
|
||||
+ "no subtitlesDirectory default is configured in ffx.json."
|
||||
)
|
||||
|
||||
resolvedSubtitleDirectory = os.path.join(
|
||||
configuredSubtitlesBaseDirectory,
|
||||
resolvedSubtitlePrefix,
|
||||
)
|
||||
|
||||
if not os.path.isdir(resolvedSubtitleDirectory):
|
||||
raise click.ClickException(
|
||||
"Subtitle prefix was set but the resolved subtitle directory does not exist: "
|
||||
+ resolvedSubtitleDirectory
|
||||
)
|
||||
|
||||
return True, resolvedSubtitleDirectory, resolvedSubtitlePrefix
|
||||
|
||||
|
||||
|
||||
@click.group()
|
||||
@click.pass_context
|
||||
@@ -604,8 +647,8 @@ def checkUniqueDispositions(context, mediaDescriptor: MediaDescriptor):
|
||||
@click.option('--ac3', type=int, default=DEFAULT_AC3_BANDWIDTH, help=f"Bitrate in kbit/s to be used to encode 5.1 audio streams", show_default=True)
|
||||
@click.option('--dts', type=int, default=DEFAULT_DTS_BANDWIDTH, help=f"Bitrate in kbit/s to be used to encode 6.1 audio streams", show_default=True)
|
||||
|
||||
@click.option('--subtitle-directory', type=str, default='', help='Load subtitles from here')
|
||||
@click.option('--subtitle-prefix', type=str, default='', help='Subtitle filename prefix')
|
||||
@click.option('--subtitle-directory', type=str, default='', help=SUBTITLE_DIRECTORY_OPTION_HELP)
|
||||
@click.option('--subtitle-prefix', type=str, default='', help=SUBTITLE_PREFIX_OPTION_HELP)
|
||||
|
||||
@click.option('--language', type=str, multiple=True, help='Set stream language. Use format <stream index>:<3 letter iso code>')
|
||||
@click.option('--title', type=str, multiple=True, help='Set stream title. Use format <stream index>:<title>')
|
||||
@@ -797,10 +840,18 @@ def convert(ctx,
|
||||
}
|
||||
|
||||
|
||||
context['import_subtitles'] = (subtitle_directory and subtitle_prefix)
|
||||
(
|
||||
context['import_subtitles'],
|
||||
resolvedSubtitleDirectory,
|
||||
resolvedSubtitlePrefix,
|
||||
) = resolveSubtitleImportOptions(
|
||||
context,
|
||||
subtitle_directory,
|
||||
subtitle_prefix,
|
||||
)
|
||||
if context['import_subtitles']:
|
||||
context['subtitle_directory'] = subtitle_directory
|
||||
context['subtitle_prefix'] = subtitle_prefix
|
||||
context['subtitle_directory'] = resolvedSubtitleDirectory
|
||||
context['subtitle_prefix'] = resolvedSubtitlePrefix
|
||||
|
||||
|
||||
existingSourcePaths = [p for p in paths if os.path.isfile(p) and p.split('.')[-1] in SUPPORTED_INPUT_FILE_EXTENSIONS]
|
||||
|
||||
@@ -8,6 +8,7 @@ class ConfigurationController():
|
||||
|
||||
DATABASE_PATH_CONFIG_KEY = 'databasePath'
|
||||
LOG_DIRECTORY_CONFIG_KEY = 'logDirectory'
|
||||
SUBTITLES_DIRECTORY_CONFIG_KEY = 'subtitlesDirectory'
|
||||
OUTPUT_FILENAME_TEMPLATE_KEY = 'outputFilenameTemplate'
|
||||
|
||||
|
||||
@@ -49,6 +50,12 @@ class ConfigurationController():
|
||||
def getDatabaseFilePath(self):
|
||||
return self.__databaseFilePath
|
||||
|
||||
def getSubtitlesDirectoryPath(self):
|
||||
subtitlesDirectory = self.__configurationData.get(
|
||||
ConfigurationController.SUBTITLES_DIRECTORY_CONFIG_KEY,
|
||||
'',
|
||||
)
|
||||
return os.path.expanduser(str(subtitlesDirectory)) if subtitlesDirectory else ''
|
||||
|
||||
def getData(self):
|
||||
return self.__configurationData
|
||||
@@ -139,4 +146,4 @@ class ConfigurationController():
|
||||
# raise click.ClickException(f"PatternController.getPattern(): {repr(ex)}")
|
||||
# finally:
|
||||
# s.close()
|
||||
#
|
||||
#
|
||||
|
||||
Reference in New Issue
Block a user