From e44fc93b4e8aceea890075011d335156fb707383 Mon Sep 17 00:00:00 2001 From: Maveno Date: Sat, 16 Nov 2024 21:57:28 +0100 Subject: [PATCH] #379 Shifted Seasons --- bin/ffx.py | 20 ++++++-- bin/ffx/shifted_season_controller.py | 61 ++++-------------------- bin/ffx/shifted_season_details_screen.py | 3 -- 3 files changed, 26 insertions(+), 58 deletions(-) diff --git a/bin/ffx.py b/bin/ffx.py index cec7a07..ea2f5c5 100755 --- a/bin/ffx.py +++ b/bin/ffx.py @@ -33,6 +33,8 @@ from ffx.filter.nlmeans_filter import NlmeansFilter from ffx.constants import VERSION +from ffx.shifted_season_controller import ShiftedSeasonController + # 0.1.1 # Bugfixes, TMBD identify shows @@ -559,16 +561,26 @@ def convert(ctx, mediaFileProperties = FileProperties(context, sourceFilename) + ssc = ShiftedSeasonController(context) + + showId = mediaFileProperties.getShowId() + #HINT: -1 if not set if 'tmdb' in cliOverrides.keys() and 'season' in cliOverrides['tmdb']: - showSeason = cliOverrides['tmdb']['season'] + sSeason = cliOverrides['tmdb']['season'] else: - showSeason = mediaFileProperties.getSeason() + sSeason = mediaFileProperties.getSeason() if 'tmdb' in cliOverrides.keys() and 'episode' in cliOverrides['tmdb']: - showEpisode = cliOverrides['tmdb']['episode'] + sEpisode = 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: - showEpisode = mediaFileProperties.getEpisode() + showSeason = sSeason + showEpisode = sEpisode ctx.obj['logger'].debug(f"Season={showSeason} Episode={showEpisode}") diff --git a/bin/ffx/shifted_season_controller.py b/bin/ffx/shifted_season_controller.py index 7102d1d..682d9e0 100644 --- a/bin/ffx/shifted_season_controller.py +++ b/bin/ffx/shifted_season_controller.py @@ -203,56 +203,15 @@ class ShiftedSeasonController(): s.close() -# def matchFilename(self, filename : str) -> dict: -# """Returns dict {'match': , 'pattern': } or empty dict of no pattern was found""" -# -# try: -# s = self.Session() -# q = s.query(Pattern) -# -# matchResult = {} -# -# for pattern in q.all(): -# patternMatch = re.search(str(pattern.pattern), str(filename)) -# if patternMatch is not None: -# matchResult['match'] = patternMatch -# matchResult['pattern'] = pattern -# -# return matchResult -# -# except Exception as ex: -# raise click.ClickException(f"PatternController.matchFilename(): {repr(ex)}") -# finally: -# s.close() -# -# # def getMediaDescriptor(self, context, patternId): -# # -# # try: -# # s = self.Session() -# # q = s.query(Pattern).filter(Pattern.id == int(patternId)) -# # -# # if q.count(): -# # return q.first().getMediaDescriptor(context) -# # else: -# # return None -# # -# # except Exception as ex: -# # raise click.ClickException(f"PatternController.getMediaDescriptor(): {repr(ex)}") -# # finally: -# # s.close() - - def shift(self, season, episode): - - if season == self.original_season and episode >= self.first_episode and episode <= self.last_episode: - return season + self.season_offset, episode + self.episode_offset - - else: - return season, episode + def shiftSeason(self, showId, season, episode): - def unshift(self, season, episode): + shiftedSeason: ShiftedSeason + for shiftedSeason in self.getShiftedSeasonSiblings(showId): - if season == self.original_season and episode >= self.first_episode and episode <= self.last_episode: - return season + self.season_offset, episode + self.episode_offset - - else: - return season, episode + if (season == shiftedSeason.getOriginalSeason() + and (shiftedSeason.getFirstEpisode() == -1 or episode >= shiftedSeason.getFirstEpisode()) + and (shiftedSeason.getLastEpisode() == -1 or episode <= shiftedSeason.getLastEpisode())): + + return season + shiftedSeason.getSeasonOffset(), episode + shiftedSeason.getEpisodeOffset() + + return season, episode diff --git a/bin/ffx/shifted_season_details_screen.py b/bin/ffx/shifted_season_details_screen.py index 3a6ef95..7cf0194 100644 --- a/bin/ffx/shifted_season_details_screen.py +++ b/bin/ffx/shifted_season_details_screen.py @@ -186,12 +186,9 @@ class ShiftedSeasonDetailsScreen(Screen): except ValueError: shiftedSeasonObj['episode_offset'] = 0 - - return shiftedSeasonObj - # Event handler for button press def on_button_pressed(self, event: Button.Pressed) -> None: