@ -14,6 +14,8 @@ from ffx.database import databaseContext
from ffx . media_descriptor import MediaDescriptor
from ffx . track_descriptor import TrackDescriptor
from ffx . show_descriptor import ShowDescriptor
from ffx . track_type import TrackType
from ffx . video_encoder import VideoEncoder
from ffx . track_disposition import TrackDisposition
@ -299,9 +301,11 @@ def checkUniqueDispositions(context, mediaDescriptor: MediaDescriptor):
@click.option ( ' --denoise-research-window ' , type = str , default = ' ' , help = ' Range to search for comparable patches on luminosity plane. Better filtering but costly. ' )
@click.option ( ' --denoise-chroma-research-window ' , type = str , default = ' ' , help = ' Range to search for comparable patches on chroma planes. ' )
@click.option ( ' --show ' , type = int , default = - 1 , help = ' Set TMDB show identifier ' )
@click.option ( ' --season ' , type = int , default = - 1 , help = ' Set season of show ' )
@click.option ( ' --episode ' , type = int , default = - 1 , help = ' Set episode of show ' )
@click.option ( " --no-tmdb " , is_flag = True , default = False )
# @click.option("--no-jellyfin", is_flag=True, default=False)
@click.option ( " --no-pattern " , is_flag = True , default = False )
@click.option ( " --dont-pass-dispositions " , is_flag = True , default = False )
@ -346,6 +350,10 @@ def convert(ctx,
denoise_research_window ,
denoise_chroma_research_window ,
show ,
season ,
episode ,
no_tmdb ,
# no_jellyfin,
no_pattern ,
@ -389,6 +397,11 @@ def convert(ctx,
context [ ' subtitle_prefix ' ] = subtitle_prefix
existingSourcePaths = [ p for p in paths if os . path . isfile ( p ) and p . split ( ' . ' ) [ - 1 ] in FfxController . INPUT_FILE_EXTENSIONS ]
# CLI Overrides
cliOverrides = { }
if language :
@ -426,6 +439,18 @@ def convert(ctx,
if forced_subtitle != - 1 :
cliOverrides [ ' forced_subtitle ' ] = forced_subtitle
if show != - 1 or season != - 1 or episode != - 1 :
if len ( existingSourcePaths ) > 1 :
context [ ' logger ' ] . warning ( f " Ignoring TMDB show, season, episode overrides, not supported for multiple source files " )
else :
cliOverrides [ ' tmdb ' ] = { }
if show != - 1 :
cliOverrides [ ' tmdb ' ] [ ' show ' ] = show
if season != - 1 :
cliOverrides [ ' tmdb ' ] [ ' season ' ] = season
if episode != - 1 :
cliOverrides [ ' tmdb ' ] [ ' episode ' ] = episode
if cliOverrides :
context [ ' overrides ' ] = cliOverrides
@ -468,7 +493,7 @@ def convert(ctx,
tc = TmdbController ( ) if context [ ' use_tmdb ' ] else None
existingSourcePaths = [ p for p in paths if os . path . isfile ( p ) and p . split ( ' . ' ) [ - 1 ] in FfxController . INPUT_FILE_EXTENSIONS ]
ctx . obj [ ' logger ' ] . info ( f " \n Running { len ( existingSourcePaths ) * len ( q_list ) } jobs " )
jobIndex = 0
@ -487,6 +512,15 @@ def convert(ctx,
mediaFileProperties = FileProperties ( context , sourceFilename )
#HINT: -1 if not set
showSeason = ( cliOverrides [ ' tmdb ' ] [ ' season ' ] if ' tmdb ' in cliOverrides . keys ( )
and ' season ' in cliOverrides [ ' tmdb ' ] else mediaFileProperties . getSeason ( ) )
showEpisode = ( cliOverrides [ ' tmdb ' ] [ ' episode ' ] if ' tmdb ' in cliOverrides . keys ( )
and ' episode ' in cliOverrides [ ' tmdb ' ] else mediaFileProperties . getEpisode ( ) )
ctx . obj [ ' logger ' ] . debug ( f " Season= { showSeason } Episode= { showEpisode } " )
sourceMediaDescriptor = mediaFileProperties . getMediaDescriptor ( )
#HINT: This is None if the filename did not match anything in database
@ -494,80 +528,84 @@ def convert(ctx,
ctx . obj [ ' logger ' ] . debug ( f " Pattern matching: { ' No ' if currentPattern is None else ' Yes ' } " )
# fileBasename = ''
# Setup FfxController accordingly depending on pattern matching is enabled and a pattern was matched
if currentPattern is None :
# Case no pattern matching
# fileBasename = currentShowDescriptor.getFilenamePrefix()
checkUniqueDispositions ( context , sourceMediaDescriptor )
currentShowDescriptor = None
if context [ ' import_subtitles ' ] :
sourceMediaDescriptor . importSubtitles ( context [ ' subtitle_directory ' ] ,
context [ ' subtitle_prefix ' ] ,
mediaFileProperties. getSeason ( ) ,
mediaFileProperties. getEpisode ( ) )
showSeason ,
showEpisode )
if cliOverrides :
sourceMediaDescriptor . applyOverrides ( cliOverrides )
#YOLO
fc = FfxController ( context , sourceMediaDescriptor )
else :
# Case pattern matching
targetMediaDescriptor = currentPattern . getMediaDescriptor ( ctx . obj )
checkUniqueDispositions ( context , targetMediaDescriptor )
currentShowDescriptor = currentPattern . getShowDescriptor ( ctx . obj )
if context [ ' use_tmdb ' ] :
ctx . obj [ ' logger ' ] . debug ( f " Querying TMDB for show_id= { currentShowDescriptor . getId ( ) } season= { mediaFileProperties . getSeason ( ) } episode { mediaFileProperties . getEpisode ( ) } " )
tmdbEpisodeResult = tc . queryEpisode ( currentShowDescriptor . getId ( ) , mediaFileProperties . getSeason ( ) , mediaFileProperties . getEpisode ( ) )
ctx . obj [ ' logger ' ] . debug ( f " tmdbEpisodeResult= { tmdbEpisodeResult } " )
if tmdbEpisodeResult :
filteredEpisodeName = filterFilename ( tmdbEpisodeResult [ ' name ' ] )
sourceFileBasename = TmdbController . getEpisodeFileBasename ( currentShowDescriptor . getFilenamePrefix ( ) ,
filteredEpisodeName ,
mediaFileProperties . getSeason ( ) ,
mediaFileProperties . getEpisode ( ) ,
currentShowDescriptor . getIndexSeasonDigits ( ) ,
currentShowDescriptor . getIndexEpisodeDigits ( ) ,
currentShowDescriptor . getIndicatorSeasonDigits ( ) ,
currentShowDescriptor . getIndicatorEpisodeDigits ( ) )
else :
sourceFileBasename = currentShowDescriptor . getFilenamePrefix ( )
if context [ ' import_subtitles ' ] :
targetMediaDescriptor . importSubtitles ( context [ ' subtitle_directory ' ] ,
context [ ' subtitle_prefix ' ] ,
mediaFileProperties. getSeason ( ) ,
mediaFileProperties. getEpisode ( ) )
showSeason ,
showEpisode )
ctx . obj [ ' logger ' ] . debug ( f " tmd subindices: { [ t . getIndex ( ) for t in targetMediaDescriptor . getAllTrackDescriptors ( ) ] } { [ t . getSubIndex ( ) for t in targetMediaDescriptor . getAllTrackDescriptors ( ) ] } { [ t . getDispositionFlag ( TrackDisposition . DEFAULT ) for t in targetMediaDescriptor . getAllTrackDescriptors ( ) ] } " )
if cliOverrides :
targetMediaDescriptor . applyOverrides ( cliOverrides )
ctx . obj [ ' logger ' ] . debug ( f " tmd subindices: { [ t . getIndex ( ) for t in targetMediaDescriptor . getAllTrackDescriptors ( ) ] } { [ t . getSubIndex ( ) for t in targetMediaDescriptor . getAllTrackDescriptors ( ) ] } { [ t . getDispositionFlag ( TrackDisposition . DEFAULT ) for t in targetMediaDescriptor . getAllTrackDescriptors ( ) ] } " )
ctx . obj [ ' logger ' ] . debug ( f " Input mapping tokens (2nd pass): { targetMediaDescriptor . getInputMappingTokens ( ) } " )
fc = FfxController ( context , targetMediaDescriptor , sourceMediaDescriptor )
ctx . obj [ ' logger ' ] . debug ( f " Season= { mediaFileProperties . getSeason ( ) } Episode= { mediaFileProperties . getEpisode ( ) } " )
# Assemble target filename accordingly depending on TMDB lookup is enabled
#HINT: -1 if not set
showId = cliOverrides [ ' tmdb ' ] [ ' show ' ] if ' tmdb ' in cliOverrides . keys ( ) and ' show ' in cliOverrides [ ' tmdb ' ] else ( - 1 if currentShowDescriptor is None else currentShowDescriptor . getId ( ) )
if context [ ' use_tmdb ' ] and showId != - 1 and showSeason != - 1 and showEpisode != - 1 :
ctx . obj [ ' logger ' ] . debug ( f " Querying TMDB for show_id= { showId } season= { showSeason } episode { showEpisode } " )
if currentPattern is None :
sName , showYear = tc . getShowNameAndYear ( showId )
showName = filterFilename ( sName )
showFilenamePrefix = f " { showName } ( { str ( showYear ) } ) "
indexSeasonDigits = ShowDescriptor . DEFAULT_INDEX_SEASON_DIGITS
indexEpisodeDigits = ShowDescriptor . DEFAULT_INDEX_EPISODE_DIGITS
indicatorSeasonDigits = ShowDescriptor . DEFAULT_INDICATOR_SEASON_DIGITS
indicatorEpisodeDigits = ShowDescriptor . DEFAULT_INDICATOR_EPISODE_DIGITS
else :
showFilenamePrefix = currentShowDescriptor . getFilenamePrefix ( )
indexSeasonDigits = currentShowDescriptor . getIndexSeasonDigits ( )
indexEpisodeDigits = currentShowDescriptor . getIndexEpisodeDigits ( )
indicatorSeasonDigits = currentShowDescriptor . getIndicatorSeasonDigits ( )
indicatorEpisodeDigits = currentShowDescriptor . getIndicatorEpisodeDigits ( )
tmdbEpisodeResult = tc . queryEpisode ( showId , showSeason , showEpisode )
ctx . obj [ ' logger ' ] . debug ( f " tmdbEpisodeResult= { tmdbEpisodeResult } " )
if tmdbEpisodeResult :
filteredEpisodeName = filterFilename ( tmdbEpisodeResult [ ' name ' ] )
sourceFileBasename = TmdbController . getEpisodeFileBasename ( showFilenamePrefix ,
filteredEpisodeName ,
showSeason ,
showEpisode ,
indexSeasonDigits ,
indexEpisodeDigits ,
indicatorSeasonDigits ,
indicatorEpisodeDigits )
ctx . obj [ ' logger ' ] . debug ( f " fileBasename= { sourceFileBasename } " )