@ -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 ( ' -sd ' , ' --subtitle-directory ' , type = str , default = ' ' , help = ' Load subtitles from here ' )
@click.option ( ' -s l' , ' --subtitle-label ' , type = str , default = ' ' , help = ' Subtitle filename prefix ' )
@click.option ( ' -s p' , ' --subtitle-prefix ' , type = str , default = ' ' , help = ' Subtitle filename prefix ' )
@click.option ( ' -ss ' , ' --subtitle-language ' , type = str , default= ' ' , help = ' Subtitle stream language(s) ' )
@click.option ( ' -st ' , ' --subtitle-title ' , type = str , default= ' ' , help = ' Subtitle stream title(s) ' )
@click.option ( ' -ss ' , ' --subtitle-language ' , type = str , multiple= True , help = ' Subtitle stream language(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 ( ' -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 ( ' -at ' , ' --audio-title ' , type = str , default= ' ' , help = ' Audio stream title(s) ' )
@click.option ( ' -as ' , ' --audio-language ' , type = str , multiple= True , help = ' Audio stream language(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 ' )
@ -449,7 +449,7 @@ def convert(ctx,
ac3_bitrate ,
dts_bitrate ,
subtitle_directory ,
subtitle_ label ,
subtitle_ prefix ,
subtitle_language ,
subtitle_title ,
default_subtitle ,
@ -493,17 +493,17 @@ def convert(ctx,
click . echo ( f " DTS bitrate: { context [ ' bitrates ' ] [ ' dts ' ] } " )
# 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 )
e_match = re . compile ( EPISODE_INDICATOR_MATCH )
sesl_match = re . compile ( SEASON_EPISODE_STREAM_LANGUAGE_MATCH )
available Subtitles = [ ]
available File Subtitles = [ ]
if context [ ' import_subtitles ' ] :
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 )
if sesl_result is not None :
subtitleFilePath = os . path . join ( subtitle_directory , subtitleFilename )
@ -514,16 +514,16 @@ def convert(ctx,
subtitleFileDescriptor [ ' episode ' ] = int ( sesl_result . group ( 2 ) )
subtitleFileDescriptor [ ' stream ' ] = int ( sesl_result . group ( 3 ) )
subtitleFileDescriptor [ ' language ' ] = sesl_result . group ( 4 )
available Subtitles. append ( subtitleFileDescriptor )
available File Subtitles. append ( subtitleFileDescriptor )
click . echo ( f " Found { len ( available Subtitles) } subtitles in files " )
click . echo ( f " Found { len ( available File Subtitles) } subtitles in files " )
subtitleLanguages = subtitle_language . split ( ' , ' ) if subtitle_language else [ ]
subtitleTitles = subtitle_title . split ( ' , ' ) if subtitle_title else [ ]
subtitleLanguages = subtitle_language
subtitleTitles = subtitle_title
audioLanguages = audio_language . split ( ' , ' ) if audio_language else [ ]
audioTitles = audio_title . split ( ' , ' ) if audio_title else [ ]
audioLanguages = audio_language
audioTitles = audio_title
# Process crop parameters
@ -625,8 +625,8 @@ def convert(ctx,
subtitleFileTokens = [ ]
matchingSubtitles = [ ]
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 ' ] )
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 ] [ ' 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 :
matchingSubtitles = mSubtitles
else :
@ -732,6 +735,8 @@ def convert(ctx,
msg = matchingSubtitles [ fileIndex ]
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 :