diff --git a/modules/anidb.py b/modules/anidb.py index b1beb49d..0c196c77 100644 --- a/modules/anidb.py +++ b/modules/anidb.py @@ -8,7 +8,7 @@ logger = logging.getLogger("Plex Meta Manager") builders = ["anidb_id", "anidb_relation", "anidb_popular"] -class AniDBAPI: +class AniDB: def __init__(self, config): self.config = config self.urls = { diff --git a/modules/anilist.py b/modules/anilist.py index 7301327f..970277dc 100644 --- a/modules/anilist.py +++ b/modules/anilist.py @@ -22,7 +22,7 @@ pretty_names = { tag_query = "query{MediaTagCollection {name}}" genre_query = "query{GenreCollection}" -class AniListAPI: +class AniList: def __init__(self, config): self.config = config self.url = "https://graphql.anilist.co" diff --git a/modules/config.py b/modules/config.py index 86fa05a2..16c76734 100644 --- a/modules/config.py +++ b/modules/config.py @@ -1,21 +1,21 @@ import logging, os from datetime import datetime from modules import util -from modules.anidb import AniDBAPI -from modules.anilist import AniListAPI +from modules.anidb import AniDB +from modules.anilist import AniList from modules.cache import Cache from modules.convert import Convert -from modules.imdb import IMDbAPI -from modules.letterboxd import LetterboxdAPI -from modules.mal import MyAnimeListAPI -from modules.omdb import OMDbAPI -from modules.plex import PlexAPI +from modules.imdb import IMDb +from modules.letterboxd import Letterboxd +from modules.mal import MyAnimeList +from modules.omdb import OMDb +from modules.plex import Plex from modules.radarr import Radarr from modules.sonarr import Sonarr -from modules.tautulli import TautulliAPI -from modules.tmdb import TMDbAPI -from modules.trakttv import TraktAPI -from modules.tvdb import TVDbAPI +from modules.tautulli import Tautulli +from modules.tmdb import TMDb +from modules.trakttv import Trakt +from modules.tvdb import TVDb from modules.util import Failed from ruamel import yaml @@ -214,7 +214,7 @@ class Config: try: self.tmdb["apikey"] = check_for_attribute(self.data, "apikey", parent="tmdb", throw=True) except Failed as e: raise Failed(e) self.tmdb["language"] = check_for_attribute(self.data, "language", parent="tmdb", default="en") - self.TMDb = TMDbAPI(self, self.tmdb) + self.TMDb = TMDb(self, self.tmdb) logger.info(f"TMDb Connection {'Failed' if self.TMDb is None else 'Successful'}") else: raise Failed("Config Error: tmdb attribute not found") @@ -227,7 +227,7 @@ class Config: self.omdb = {} try: self.omdb["apikey"] = check_for_attribute(self.data, "apikey", parent="omdb", throw=True) - self.OMDb = OMDbAPI(self.omdb, Cache=self.Cache) + self.OMDb = OMDb(self.omdb, Cache=self.Cache) except Failed as e: logger.error(e) logger.info(f"OMDb Connection {'Failed' if self.OMDb is None else 'Successful'}") @@ -245,7 +245,7 @@ class Config: self.trakt["client_secret"] = check_for_attribute(self.data, "client_secret", parent="trakt", throw=True) self.trakt["config_path"] = self.config_path authorization = self.data["trakt"]["authorization"] if "authorization" in self.data["trakt"] and self.data["trakt"]["authorization"] else None - self.Trakt = TraktAPI(self.trakt, authorization) + self.Trakt = Trakt(self.trakt, authorization) except Failed as e: logger.error(e) logger.info(f"Trakt Connection {'Failed' if self.Trakt is None else 'Successful'}") @@ -263,19 +263,19 @@ class Config: self.mal["client_secret"] = check_for_attribute(self.data, "client_secret", parent="mal", throw=True) self.mal["config_path"] = self.config_path authorization = self.data["mal"]["authorization"] if "authorization" in self.data["mal"] and self.data["mal"]["authorization"] else None - self.MyAnimeList = MyAnimeListAPI(self.mal, self, authorization) + self.MyAnimeList = MyAnimeList(self.mal, self, authorization) except Failed as e: logger.error(e) logger.info(f"My Anime List Connection {'Failed' if self.MyAnimeList is None else 'Successful'}") else: logger.warning("mal attribute not found") - self.TVDb = TVDbAPI(self) - self.IMDb = IMDbAPI(self) - self.AniDB = AniDBAPI(self) + self.TVDb = TVDb(self) + self.IMDb = IMDb(self) + self.AniDB = AniDB(self) self.Convert = Convert(self) - self.AniList = AniListAPI(self) - self.Letterboxd = LetterboxdAPI(self) + self.AniList = AniList(self) + self.Letterboxd = Letterboxd(self) util.separator() @@ -447,7 +447,7 @@ class Config: params["plex"]["clean_bundles"] = check_for_attribute(lib, "clean_bundles", parent="plex", var_type="bool", default=self.general["plex"]["clean_bundles"], save=False) params["plex"]["empty_trash"] = check_for_attribute(lib, "empty_trash", parent="plex", var_type="bool", default=self.general["plex"]["empty_trash"], save=False) params["plex"]["optimize"] = check_for_attribute(lib, "optimize", parent="plex", var_type="bool", default=self.general["plex"]["optimize"], save=False) - library = PlexAPI(self, params) + library = Plex(self, params) logger.info("") logger.info(f"{display_name} Library Connection Successful") except Failed as e: @@ -517,7 +517,7 @@ class Config: try: tautulli_params["url"] = check_for_attribute(lib, "url", parent="tautulli", var_type="url", default=self.general["tautulli"]["url"], req_default=True, save=False) tautulli_params["apikey"] = check_for_attribute(lib, "apikey", parent="tautulli", default=self.general["tautulli"]["apikey"], req_default=True, save=False) - library.Tautulli = TautulliAPI(tautulli_params) + library.Tautulli = Tautulli(tautulli_params) except Failed as e: util.print_multiline(e, error=True) logger.info("") diff --git a/modules/imdb.py b/modules/imdb.py index dfe465e8..c70947b9 100644 --- a/modules/imdb.py +++ b/modules/imdb.py @@ -8,7 +8,7 @@ logger = logging.getLogger("Plex Meta Manager") builders = ["imdb_list", "imdb_id"] -class IMDbAPI: +class IMDb: def __init__(self, config): self.config = config self.urls = { diff --git a/modules/letterboxd.py b/modules/letterboxd.py index cc61d424..44fd433e 100644 --- a/modules/letterboxd.py +++ b/modules/letterboxd.py @@ -8,7 +8,7 @@ logger = logging.getLogger("Plex Meta Manager") builders = ["letterboxd_list", "letterboxd_list_details"] -class LetterboxdAPI: +class Letterboxd: def __init__(self, config): self.config = config self.url = "https://letterboxd.com" diff --git a/modules/mal.py b/modules/mal.py index eda320b4..79faff7d 100644 --- a/modules/mal.py +++ b/modules/mal.py @@ -72,7 +72,7 @@ userlist_status = [ "plan_to_watch" ] -class MyAnimeListAPI: +class MyAnimeList: def __init__(self, params, config, authorization=None): self.config = config self.urls = { diff --git a/modules/meta.py b/modules/meta.py index 5bd04df5..211bba9b 100644 --- a/modules/meta.py +++ b/modules/meta.py @@ -103,7 +103,7 @@ class Metadata: logger.error(f"Metadata Error: {name} attribute is blank") def add_advanced_edit(attr, obj, group, alias, show_library=False, new_agent=False): - key, options = plex.advance_keys[attr] + key, options = plex.item_advance_keys[f"item_{attr}"] if attr in alias: if new_agent and self.library.agent not in plex.new_plex_agents: logger.error(f"Metadata Error: {attr} attribute only works for with the New Plex Movie Agent and New Plex TV Agent") diff --git a/modules/omdb.py b/modules/omdb.py index 2cf96b4b..52363f92 100644 --- a/modules/omdb.py +++ b/modules/omdb.py @@ -31,7 +31,7 @@ class OMDbObj: self.imdb_id = data["imdbID"] self.type = data["Type"] -class OMDbAPI: +class OMDb: def __init__(self, params, Cache=None): self.url = "http://www.omdbapi.com/" self.apikey = params["apikey"] diff --git a/modules/plex.py b/modules/plex.py index cc6b885d..79a347a5 100644 --- a/modules/plex.py +++ b/modules/plex.py @@ -58,15 +58,6 @@ metadata_language_options["default"] = None use_original_title_options = {"default": -1, "no": 0, "yes": 1} collection_mode_keys = {-1: "default", 0: "hide", 1: "hideItems", 2: "showItems"} collection_order_keys = {0: "release", 1: "alpha", 2: "custom"} -advance_keys = { - "episode_sorting": ("episodeSort", episode_sorting_options), - "keep_episodes": ("autoDeletionItemPolicyUnwatchedLibrary", keep_episodes_options), - "delete_episodes": ("autoDeletionItemPolicyWatchedLibrary", delete_episodes_options), - "season_display": ("flattenSeasons", season_display_options), - "episode_ordering": ("showOrdering", episode_ordering_options), - "metadata_language": ("languageOverride", metadata_language_options), - "use_original_title": ("useOriginalTitle", use_original_title_options) -} item_advance_keys = { "item_episode_sorting": ("episodeSort", episode_sorting_options), "item_keep_episodes": ("autoDeletionItemPolicyUnwatchedLibrary", keep_episodes_options), @@ -260,7 +251,7 @@ sort_types = { "episodes": (4, episode_sorts), } -class PlexAPI: +class Plex: def __init__(self, config, params): self.config = config try: diff --git a/modules/tautulli.py b/modules/tautulli.py index 0ee75e48..bc0f9dfd 100644 --- a/modules/tautulli.py +++ b/modules/tautulli.py @@ -8,7 +8,7 @@ logger = logging.getLogger("Plex Meta Manager") builders = ["tautulli_popular", "tautulli_watched"] -class TautulliAPI: +class Tautulli: def __init__(self, params): self.url = params["url"] self.apikey = params["apikey"] diff --git a/modules/tmdb.py b/modules/tmdb.py index e493915e..e9a45396 100644 --- a/modules/tmdb.py +++ b/modules/tmdb.py @@ -108,7 +108,7 @@ discover_tv_sort = [ "popularity.desc", "popularity.asc" ] -class TMDbAPI: +class TMDb: def __init__(self, config, params): self.config = config self.TMDb = tmdbv3api.TMDb() diff --git a/modules/trakttv.py b/modules/trakttv.py index 8ed2a9d3..20b1cdff 100644 --- a/modules/trakttv.py +++ b/modules/trakttv.py @@ -3,7 +3,7 @@ from modules import util from modules.util import Failed, TimeoutExpired from retrying import retry from ruamel import yaml -from trakt import Trakt +from trakt import Trakt as TraktAPI from trakt.objects.episode import Episode from trakt.objects.movie import Movie from trakt.objects.season import Season @@ -23,7 +23,7 @@ builders = [ "trakt_watchlist" ] -class TraktAPI: +class Trakt: def __init__(self, params, authorization=None): self.base_url = "https://api.trakt.tv" self.redirect_uri = "urn:ietf:wg:oauth:2.0:oob" @@ -36,20 +36,20 @@ class TraktAPI: self.client_secret = params["client_secret"] self.config_path = params["config_path"] self.authorization = authorization - Trakt.configuration.defaults.client(self.client_id, self.client_secret) + TraktAPI.configuration.defaults.client(self.client_id, self.client_secret) if not self._save(self.authorization): if not self._refresh(): self._authorization() def _authorization(self): - url = Trakt["oauth"].authorize_url(self.redirect_uri) + url = TraktAPI["oauth"].authorize_url(self.redirect_uri) logger.info(f"Navigate to: {url}") logger.info("If you get an OAuth error your client_id or client_secret is invalid") webbrowser.open(url, new=2) try: pin = util.logger_input("Trakt pin (case insensitive)", timeout=300).strip() except TimeoutExpired: raise Failed("Input Timeout: Trakt pin required.") if not pin: raise Failed("Trakt Error: No input Trakt pin required.") - new_authorization = Trakt["oauth"].token(pin, self.redirect_uri) + new_authorization = TraktAPI["oauth"].token(pin, self.redirect_uri) if not new_authorization: raise Failed("Trakt Error: Invalid trakt pin. If you're sure you typed it in correctly your client_id or client_secret may be invalid") if not self._save(new_authorization): @@ -57,8 +57,8 @@ class TraktAPI: def _check(self, authorization): try: - with Trakt.configuration.oauth.from_response(authorization, refresh=True): - if Trakt["users/settings"].get(): + with TraktAPI.configuration.oauth.from_response(authorization, refresh=True): + if TraktAPI["users/settings"].get(): return True except ValueError: pass return False @@ -66,7 +66,7 @@ class TraktAPI: def _refresh(self): if self.authorization and "refresh_token" in self.authorization and self.authorization["refresh_token"]: logger.info("Refreshing Access Token...") - refreshed_authorization = Trakt["oauth"].token_refresh(self.authorization["refresh_token"], self.redirect_uri) + refreshed_authorization = TraktAPI["oauth"].token_refresh(self.authorization["refresh_token"], self.redirect_uri) return self._save(refreshed_authorization) return False @@ -86,13 +86,13 @@ class TraktAPI: logger.info(f"Saving authorization information to {self.config_path}") yaml.round_trip_dump(config, open(self.config_path, "w"), indent=ind, block_seq_indent=bsi) self.authorization = authorization - Trakt.configuration.defaults.oauth.from_response(self.authorization) + TraktAPI.configuration.defaults.oauth.from_response(self.authorization) return True return False @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) def convert(self, external_id, from_source, to_source, media_type): - lookup = Trakt["search"].lookup(external_id, from_source, media_type) + lookup = TraktAPI["search"].lookup(external_id, from_source, media_type) if lookup: lookup = lookup[0] if isinstance(lookup, list) else lookup if lookup.get_key(to_source): @@ -107,13 +107,13 @@ class TraktAPI: @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) def _user_list(self, list_type, data, is_movie): - items = Trakt[f"users/{data}/{list_type}"].movies() if is_movie else Trakt[f"users/{data}/{list_type}"].shows() + items = TraktAPI[f"users/{data}/{list_type}"].movies() if is_movie else TraktAPI[f"users/{data}/{list_type}"].shows() if items is None: raise Failed("Trakt Error: No List found") else: return [i for i in items] @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) def standard_list(self, data): - try: trakt_list = Trakt[requests.utils.urlparse(data).path].get() + try: trakt_list = TraktAPI[requests.utils.urlparse(data).path].get() except AttributeError: trakt_list = None if trakt_list is None: raise Failed("Trakt Error: No List found") else: return trakt_list diff --git a/modules/tvdb.py b/modules/tvdb.py index 93970232..624cec0b 100644 --- a/modules/tvdb.py +++ b/modules/tvdb.py @@ -74,7 +74,7 @@ class TVDbObj: self.is_movie = is_movie self.TVDb = TVDb -class TVDbAPI: +class TVDb: def __init__(self, config): self.config = config self.site_url = "https://www.thetvdb.com"