diff --git a/.gitignore b/.gitignore index ed8ebf5..3a57b21 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -__pycache__ \ No newline at end of file +__pycache__ +junk/ \ No newline at end of file diff --git a/bin/ffx/tmdb_controller.py b/bin/ffx/tmdb_controller.py new file mode 100644 index 0000000..7c6de2d --- /dev/null +++ b/bin/ffx/tmdb_controller.py @@ -0,0 +1,98 @@ +import os, click, requests + + +class TmdbController(): + + DEFAULT_LANGUAGE = 'de-DE' + + def __init__(self): + + try: + self.__tmdbApiKey = os.environ['TMDB_API_KEY'] + except KeyError: + click.ClickException('TMDB api key is not available, please set environment variable TMDB_API_KEY') + + self.tmdbLanguage = TmdbController.DEFAULT_LANGUAGE + + + def queryTmdb(self, showId, season, episode): + """ + First level keys in the response object: + air_date str 'YYY-MM-DD' + crew [] + episode_number int + guest_stars [] + name str + overview str + id int + production_code + runtime int + season_number int + still_path str '/filename.jpg' + vote_average float + vote_count int + """ + + urlParams = f"?language={self.tmdbLanguage}&api_key={self.__tmdbApiKey}" + + tmdbUrl = f"https://api.themoviedb.org/3/tv/{showId}/season/{season}/episode/{episode}{urlParams}" + + return requests.get(tmdbUrl).json() + + + def getEpisodeFilename(self, + showName, + episodeName, + season, + episode, + extension, + indexSeasonDigits = 2, + indexEpisodeDigits = 2, + indicatorSeasonDigits = 2, + indicatorEpisodeDigits = 2): + """ + One Piece: + indexSeasonDigits = 0, + indexEpisodeDigits = 4, + indicatorSeasonDigits = 2, + indicatorEpisodeDigits = 4 + + Three-Body: + indexSeasonDigits = 0, + indexEpisodeDigits = 2, + indicatorSeasonDigits = 2, + indicatorEpisodeDigits = 2 + + Dragonball: + indexSeasonDigits = 0, + indexEpisodeDigits = 3, + indicatorSeasonDigits = 2, + indicatorEpisodeDigits = 3 + + Boruto: + indexSeasonDigits = 0, + indexEpisodeDigits = 4, + indicatorSeasonDigits = 2, + indicatorEpisodeDigits = 4 + """ + filenameTokens = [str(showName), ' - '] + + if indexSeasonDigits: + filenameTokens += ['{num:{fill}{width}}'.format(num=season, fill='0', width=indexSeasonDigits)] + if indexEpisodeDigits: + filenameTokens += ['{num:{fill}{width}}'.format(num=episode, fill='0', width=indexEpisodeDigits)] + if indexSeasonDigits or indexEpisodeDigits: + filenameTokens += [' '] + + filenameTokens += [episodeName] + + if indicatorSeasonDigits or indicatorEpisodeDigits: + filenameTokens += [' - '] + if indicatorSeasonDigits: + filenameTokens += ['S{num:{fill}{width}}'.format(num=season, fill='0', width=indicatorSeasonDigits)] + if indicatorEpisodeDigits: + filenameTokens += ['E{num:{fill}{width}}'.format(num=episode, fill='0', width=indicatorEpisodeDigits)] + + filenameTokens += ['.', extension] + + return ''.join(filenameTokens)