From e2b6a4bf7c4b5c1c7a7a51a49d681c63d8b1481a Mon Sep 17 00:00:00 2001 From: Maveno Date: Sun, 17 Nov 2024 12:51:28 +0100 Subject: [PATCH] imp #400 import subtitle output #397 unmuxing output --- src/ffx/ffx.py | 62 +++++++++++++++++----------- src/ffx/media_descriptor.py | 5 +++ src/ffx/shifted_season_controller.py | 18 +++++--- 3 files changed, 55 insertions(+), 30 deletions(-) diff --git a/src/ffx/ffx.py b/src/ffx/ffx.py index 9816dcc..c8c1832 100755 --- a/src/ffx/ffx.py +++ b/src/ffx/ffx.py @@ -121,19 +121,26 @@ def getUnmuxSequence(trackDescriptor: TrackDescriptor, sourcePath, targetPrefix, if not trackCodec in CODEC_LOOKUP_TABLE.keys(): return [] + # executable and input file commandTokens = FfxController.COMMAND_TOKENS + ['-i', sourcePath] + trackType = trackDescriptor.getType() targetPathBase = os.path.join(targetDirectory, targetPrefix) if targetDirectory else targetPrefix + # mapping commandTokens += ['-map', f"0:{trackType.indicator()}:{trackDescriptor.getSubIndex()}", '-c', 'copy'] - + + # TODO #425: Codec Enum + # output format if 'format' in CODEC_LOOKUP_TABLE[trackCodec].keys(): commandTokens += ['-f', CODEC_LOOKUP_TABLE[trackCodec]['format']] - + + # TODO #425: Codec enum + # output filename commandTokens += [f"{targetPathBase}.{CODEC_LOOKUP_TABLE[trackCodec]['extension']}"] return commandTokens @@ -182,7 +189,7 @@ def unmux(ctx, ctx.obj['logger'].warning(f"Skipping file {fp.getFilename()}: Label set but no indicator recognized") continue else: - ctx.obj['logger'].debug(f"\nUnmuxing file {fp.getFilename()}\n") + ctx.obj['logger'].info(f"\nUnmuxing file {fp.getFilename()}\n") for trackDescriptor in sourceMediaDescriptor.getAllTrackDescriptors(): @@ -195,7 +202,12 @@ def unmux(ctx, if unmuxSequence: if not ctx.obj['dry_run']: + + #TODO #425: Codec Enum + ctx.obj['logger'].info(f"Unmuxing stream {trackDescriptor.getIndex()} into file {targetPrefix}.{CODEC_LOOKUP_TABLE[trackDescriptor.getCodec()]['extension']}") + ctx.obj['logger'].debug(f"Executing unmuxing sequence") + out, err, rc = executeProcess(unmuxSequence, context = ctx.obj) if rc: ctx.obj['logger'].error(f"Unmuxing of stream {trackDescriptor.getIndex()} failed with error ({rc}) {err}") @@ -552,21 +564,14 @@ def convert(ctx, #HINT: -1 if not set if 'tmdb' in cliOverrides.keys() and 'season' in cliOverrides['tmdb']: - sSeason = cliOverrides['tmdb']['season'] + showSeason = cliOverrides['tmdb']['season'] else: - sSeason = mediaFileProperties.getSeason() + showSeason = mediaFileProperties.getSeason() if 'tmdb' in cliOverrides.keys() and 'episode' in cliOverrides['tmdb']: - sEpisode = cliOverrides['tmdb']['episode'] + showEpisode = cliOverrides['tmdb']['episode'] else: - sEpisode = mediaFileProperties.getEpisode() - - if 'tmdb' not in cliOverrides.keys() and showId != -1: - showSeason, showEpisode = ssc.shiftSeason(showId, season=sSeason, episode=sEpisode) - else: - showSeason = sSeason - showEpisode = sEpisode - + showEpisode = mediaFileProperties.getEpisode() ctx.obj['logger'].debug(f"Season={showSeason} Episode={showEpisode}") @@ -624,13 +629,23 @@ def convert(ctx, indicatorEpisodeDigits = currentShowDescriptor.getIndicatorEpisodeDigits() if not currentPattern is None else ShowDescriptor.DEFAULT_INDICATOR_EPISODE_DIGITS + # Shift season and episode if defined for this show + if ('tmdb' not in cliOverrides.keys() and showId != -1 + and showSeason != -1 and showEpisode != -1): + shiftedShowSeason, shiftedShowEpisode = ssc.shiftSeason(showId, + season=showSeason, + episode=showEpisode) + else: + shiftedShowSeason = showSeason + shiftedShowEpisode = showEpisode + # 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: + if context['use_tmdb'] and showId != -1 and shiftedShowSeason != -1 and shiftedShowEpisode != -1: - ctx.obj['logger'].debug(f"Querying TMDB for show_id={showId} season={showSeason} episode{showEpisode}") + ctx.obj['logger'].debug(f"Querying TMDB for show_id={showId} season={shiftedShowSeason} episode{shiftedShowEpisode}") if currentPattern is None: sName, showYear = tc.getShowNameAndYear(showId) @@ -639,7 +654,7 @@ def convert(ctx, else: showFilenamePrefix = currentShowDescriptor.getFilenamePrefix() - tmdbEpisodeResult = tc.queryEpisode(showId, showSeason, showEpisode) + tmdbEpisodeResult = tc.queryEpisode(showId, shiftedShowSeason, shiftedShowEpisode) ctx.obj['logger'].debug(f"tmdbEpisodeResult={tmdbEpisodeResult}") @@ -647,19 +662,18 @@ def convert(ctx, filteredEpisodeName = filterFilename(tmdbEpisodeResult['name']) sourceFileBasename = TmdbController.getEpisodeFileBasename(showFilenamePrefix, filteredEpisodeName, - showSeason, - showEpisode, + shiftedShowSeason, + shiftedShowEpisode, indexSeasonDigits, indexEpisodeDigits, indicatorSeasonDigits, indicatorEpisodeDigits) - if label: - if showSeason > -1 and showEpisode > -1: - targetSuffices['se'] = f"S{showSeason:0{indicatorSeasonDigits}d}E{showEpisode:0{indicatorEpisodeDigits}d}" - elif showEpisode > -1: - targetSuffices['se'] = f"E{showEpisode:0{indicatorEpisodeDigits}d}" + if shiftedShowSeason > -1 and shiftedShowEpisode > -1: + targetSuffices['se'] = f"S{shiftedShowSeason:0{indicatorSeasonDigits}d}E{shiftedShowEpisode:0{indicatorEpisodeDigits}d}" + elif shiftedShowEpisode > -1: + targetSuffices['se'] = f"E{shiftedShowEpisode:0{indicatorEpisodeDigits}d}" else: if 'se' in targetSuffices.keys(): del targetSuffices['se'] diff --git a/src/ffx/media_descriptor.py b/src/ffx/media_descriptor.py index 37510f1..c8b4ca2 100644 --- a/src/ffx/media_descriptor.py +++ b/src/ffx/media_descriptor.py @@ -394,11 +394,16 @@ class MediaDescriptor: importFileTokens = [] + td: TrackDescriptor for td in self.__trackDescriptors: importedFilePath = td.getExternalSourceFilePath() if importedFilePath: + + self.__logger.info(f"Substituting subtitle stream {td.getSubIndex()} " + + f"with import from file {td.getExternalSourceFilePath()}") + importFileTokens += [ "-i", importedFilePath, diff --git a/src/ffx/shifted_season_controller.py b/src/ffx/shifted_season_controller.py index c37b091..a9c0fe1 100644 --- a/src/ffx/shifted_season_controller.py +++ b/src/ffx/shifted_season_controller.py @@ -205,13 +205,19 @@ class ShiftedSeasonController(): def shiftSeason(self, showId, season, episode): - shiftedSeason: ShiftedSeason - for shiftedSeason in self.getShiftedSeasonSiblings(showId): + shiftedSeasonEntry: ShiftedSeason + for shiftedSeasonEntry in self.getShiftedSeasonSiblings(showId): - if (season == shiftedSeason.getOriginalSeason() - and (shiftedSeason.getFirstEpisode() == -1 or episode >= shiftedSeason.getFirstEpisode()) - and (shiftedSeason.getLastEpisode() == -1 or episode <= shiftedSeason.getLastEpisode())): + if (season == shiftedSeasonEntry.getOriginalSeason() + and (shiftedSeasonEntry.getFirstEpisode() == -1 or episode >= shiftedSeasonEntry.getFirstEpisode()) + and (shiftedSeasonEntry.getLastEpisode() == -1 or episode <= shiftedSeasonEntry.getLastEpisode())): - return season + shiftedSeason.getSeasonOffset(), episode + shiftedSeason.getEpisodeOffset() + shiftedSeason = season + shiftedSeasonEntry.getSeasonOffset() + shiftedEpisode = episode + shiftedSeasonEntry.getEpisodeOffset() + + self.context['logger'].info(f"Shifting season: {season} episode: {episode} " + +f"-> season: {shiftedSeason} episode: {shiftedEpisode}") + + return shiftedSeason, shiftedEpisode return season, episode