#379 Shifted Seasons
This commit is contained in:
20
bin/ffx.py
20
bin/ffx.py
@@ -33,6 +33,8 @@ from ffx.filter.nlmeans_filter import NlmeansFilter
|
|||||||
|
|
||||||
from ffx.constants import VERSION
|
from ffx.constants import VERSION
|
||||||
|
|
||||||
|
from ffx.shifted_season_controller import ShiftedSeasonController
|
||||||
|
|
||||||
|
|
||||||
# 0.1.1
|
# 0.1.1
|
||||||
# Bugfixes, TMBD identify shows
|
# Bugfixes, TMBD identify shows
|
||||||
@@ -559,16 +561,26 @@ def convert(ctx,
|
|||||||
mediaFileProperties = FileProperties(context, sourceFilename)
|
mediaFileProperties = FileProperties(context, sourceFilename)
|
||||||
|
|
||||||
|
|
||||||
|
ssc = ShiftedSeasonController(context)
|
||||||
|
|
||||||
|
showId = mediaFileProperties.getShowId()
|
||||||
|
|
||||||
#HINT: -1 if not set
|
#HINT: -1 if not set
|
||||||
if 'tmdb' in cliOverrides.keys() and 'season' in cliOverrides['tmdb']:
|
if 'tmdb' in cliOverrides.keys() and 'season' in cliOverrides['tmdb']:
|
||||||
showSeason = cliOverrides['tmdb']['season']
|
sSeason = cliOverrides['tmdb']['season']
|
||||||
else:
|
else:
|
||||||
showSeason = mediaFileProperties.getSeason()
|
sSeason = mediaFileProperties.getSeason()
|
||||||
|
|
||||||
if 'tmdb' in cliOverrides.keys() and 'episode' in cliOverrides['tmdb']:
|
if 'tmdb' in cliOverrides.keys() and 'episode' in cliOverrides['tmdb']:
|
||||||
showEpisode = cliOverrides['tmdb']['episode']
|
sEpisode = cliOverrides['tmdb']['episode']
|
||||||
else:
|
else:
|
||||||
showEpisode = mediaFileProperties.getEpisode()
|
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
|
||||||
|
|
||||||
|
|
||||||
ctx.obj['logger'].debug(f"Season={showSeason} Episode={showEpisode}")
|
ctx.obj['logger'].debug(f"Season={showSeason} Episode={showEpisode}")
|
||||||
|
|||||||
@@ -203,56 +203,15 @@ class ShiftedSeasonController():
|
|||||||
s.close()
|
s.close()
|
||||||
|
|
||||||
|
|
||||||
# def matchFilename(self, filename : str) -> dict:
|
def shiftSeason(self, showId, season, episode):
|
||||||
# """Returns dict {'match': <a regex match obj>, 'pattern': <ffx pattern obj>} 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):
|
shiftedSeason: ShiftedSeason
|
||||||
|
for shiftedSeason in self.getShiftedSeasonSiblings(showId):
|
||||||
|
|
||||||
if season == self.original_season and episode >= self.first_episode and episode <= self.last_episode:
|
if (season == shiftedSeason.getOriginalSeason()
|
||||||
return season + self.season_offset, episode + self.episode_offset
|
and (shiftedSeason.getFirstEpisode() == -1 or episode >= shiftedSeason.getFirstEpisode())
|
||||||
|
and (shiftedSeason.getLastEpisode() == -1 or episode <= shiftedSeason.getLastEpisode())):
|
||||||
|
|
||||||
|
return season + shiftedSeason.getSeasonOffset(), episode + shiftedSeason.getEpisodeOffset()
|
||||||
|
|
||||||
else:
|
|
||||||
return season, episode
|
|
||||||
|
|
||||||
def unshift(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
|
return season, episode
|
||||||
|
|||||||
@@ -186,12 +186,9 @@ class ShiftedSeasonDetailsScreen(Screen):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
shiftedSeasonObj['episode_offset'] = 0
|
shiftedSeasonObj['episode_offset'] = 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return shiftedSeasonObj
|
return shiftedSeasonObj
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Event handler for button press
|
# Event handler for button press
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user