|
|
|
@ -11,55 +11,6 @@ from ffx.database import databaseContext
|
|
|
|
|
|
|
|
|
|
VERSION='0.1.0'
|
|
|
|
|
|
|
|
|
|
STREAM_TYPE_VIDEO = 'video'
|
|
|
|
|
STREAM_TYPE_AUDIO = 'audio'
|
|
|
|
|
STREAM_TYPE_SUBTITLE = 'subtitle'
|
|
|
|
|
|
|
|
|
|
SEASON_EPISODE_INDICATOR_MATCH = '[sS]([0-9]+)[eE]([0-9]+)'
|
|
|
|
|
EPISODE_INDICATOR_MATCH = '[eE]([0-9]+)'
|
|
|
|
|
SEASON_EPISODE_STREAM_LANGUAGE_MATCH = '[sS]([0-9]+)[eE]([0-9]+)_([0-9]+)_([a-z]{3})'
|
|
|
|
|
|
|
|
|
|
SUBTITLE_FILE_EXTENSION = 'vtt'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def getModifiedStreamOrder(length, last):
|
|
|
|
|
"""This is jellyfin specific as the last stream in the order is set as default"""
|
|
|
|
|
seq = list(range(length))
|
|
|
|
|
if last < 0 or last > length -1:
|
|
|
|
|
return seq
|
|
|
|
|
seq.pop(last)
|
|
|
|
|
seq.append(last)
|
|
|
|
|
return seq
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# def countStreamDispositions(subStreamDescriptor):
|
|
|
|
|
# return len([l for (k,v) in subStreamDescriptor['disposition'].items()])
|
|
|
|
|
|
|
|
|
|
def searchSubtitleFiles(dir, prefix):
|
|
|
|
|
|
|
|
|
|
sesl_match = re.compile(SEASON_EPISODE_STREAM_LANGUAGE_MATCH)
|
|
|
|
|
|
|
|
|
|
availableFileSubtitleDescriptors = []
|
|
|
|
|
for subtitleFilename in os.listdir(dir):
|
|
|
|
|
if subtitleFilename.startswith(prefix) and subtitleFilename.endswith('.' + SUBTITLE_FILE_EXTENSION):
|
|
|
|
|
sesl_result = sesl_match.search(subtitleFilename)
|
|
|
|
|
if sesl_result is not None:
|
|
|
|
|
subtitleFilePath = os.path.join(dir, subtitleFilename)
|
|
|
|
|
if os.path.isfile(subtitleFilePath):
|
|
|
|
|
|
|
|
|
|
subtitleFileDescriptor = {}
|
|
|
|
|
subtitleFileDescriptor['path'] = subtitleFilePath
|
|
|
|
|
subtitleFileDescriptor['season'] = int(sesl_result.group(1))
|
|
|
|
|
subtitleFileDescriptor['episode'] = int(sesl_result.group(2))
|
|
|
|
|
subtitleFileDescriptor['stream'] = int(sesl_result.group(3))
|
|
|
|
|
subtitleFileDescriptor['language'] = sesl_result.group(4)
|
|
|
|
|
|
|
|
|
|
availableFileSubtitleDescriptors.append(subtitleFileDescriptor)
|
|
|
|
|
|
|
|
|
|
click.echo(f"Found {len(availableFileSubtitleDescriptors)} subtitles in files\n")
|
|
|
|
|
|
|
|
|
|
return availableFileSubtitleDescriptors
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.group()
|
|
|
|
|
@click.pass_context
|
|
|
|
@ -252,19 +203,16 @@ def convert(ctx,
|
|
|
|
|
|
|
|
|
|
# click.echo(f"Qualities: {q_list}")
|
|
|
|
|
#
|
|
|
|
|
# context['bitrates'] = {}
|
|
|
|
|
# context['bitrates']['stereo'] = str(stereo_bitrate) if str(stereo_bitrate).endswith('k') else f"{stereo_bitrate}k"
|
|
|
|
|
# context['bitrates']['ac3'] = str(ac3_bitrate) if str(ac3_bitrate).endswith('k') else f"{ac3_bitrate}k"
|
|
|
|
|
# context['bitrates']['dts'] = str(dts_bitrate) if str(dts_bitrate).endswith('k') else f"{dts_bitrate}k"
|
|
|
|
|
context['bitrates'] = {}
|
|
|
|
|
context['bitrates']['stereo'] = str(stereo_bitrate) if str(stereo_bitrate).endswith('k') else f"{stereo_bitrate}k"
|
|
|
|
|
context['bitrates']['ac3'] = str(ac3_bitrate) if str(ac3_bitrate).endswith('k') else f"{ac3_bitrate}k"
|
|
|
|
|
context['bitrates']['dts'] = str(dts_bitrate) if str(dts_bitrate).endswith('k') else f"{dts_bitrate}k"
|
|
|
|
|
#
|
|
|
|
|
# click.echo(f"Stereo bitrate: {context['bitrates']['stereo']}")
|
|
|
|
|
# click.echo(f"AC3 bitrate: {context['bitrates']['ac3']}")
|
|
|
|
|
# click.echo(f"DTS bitrate: {context['bitrates']['dts']}")
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# se_match = re.compile(SEASON_EPISODE_INDICATOR_MATCH)
|
|
|
|
|
# e_match = re.compile(EPISODE_INDICATOR_MATCH)
|
|
|
|
|
#
|
|
|
|
|
#
|
|
|
|
|
# ## Conversion parameters
|
|
|
|
|
#
|
|
|
|
@ -347,6 +295,10 @@ def convert(ctx,
|
|
|
|
|
dispositionTokens = fc.generateDispositionTokens()
|
|
|
|
|
click.echo(f"Disposition Tokens: {dispositionTokens}")
|
|
|
|
|
|
|
|
|
|
audioTokens = fc.generateAudioEncodingTokens()
|
|
|
|
|
click.echo(f"Audio Tokens: {audioTokens}")
|
|
|
|
|
|
|
|
|
|
click.echo(f"Season={mediaFileProperties.getSeason()} Episode={mediaFileProperties.getEpisode()}")
|
|
|
|
|
|
|
|
|
|
# # Determine season and episode if present in current filename
|
|
|
|
|
# season_digits = 2
|
|
|
|
|