minor changes

pull/309/head
meisnate12 4 years ago
parent 8f491e70c2
commit 7fa141ac99

@ -8,7 +8,7 @@ logger = logging.getLogger("Plex Meta Manager")
builders = ["anidb_id", "anidb_relation", "anidb_popular"] builders = ["anidb_id", "anidb_relation", "anidb_popular"]
class AniDBAPI: class AniDB:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
self.urls = { self.urls = {

@ -22,7 +22,7 @@ pretty_names = {
tag_query = "query{MediaTagCollection {name}}" tag_query = "query{MediaTagCollection {name}}"
genre_query = "query{GenreCollection}" genre_query = "query{GenreCollection}"
class AniListAPI: class AniList:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
self.url = "https://graphql.anilist.co" self.url = "https://graphql.anilist.co"

@ -1,21 +1,21 @@
import logging, os import logging, os
from datetime import datetime from datetime import datetime
from modules import util from modules import util
from modules.anidb import AniDBAPI from modules.anidb import AniDB
from modules.anilist import AniListAPI from modules.anilist import AniList
from modules.cache import Cache from modules.cache import Cache
from modules.convert import Convert from modules.convert import Convert
from modules.imdb import IMDbAPI from modules.imdb import IMDb
from modules.letterboxd import LetterboxdAPI from modules.letterboxd import Letterboxd
from modules.mal import MyAnimeListAPI from modules.mal import MyAnimeList
from modules.omdb import OMDbAPI from modules.omdb import OMDb
from modules.plex import PlexAPI from modules.plex import Plex
from modules.radarr import Radarr from modules.radarr import Radarr
from modules.sonarr import Sonarr from modules.sonarr import Sonarr
from modules.tautulli import TautulliAPI from modules.tautulli import Tautulli
from modules.tmdb import TMDbAPI from modules.tmdb import TMDb
from modules.trakttv import TraktAPI from modules.trakttv import Trakt
from modules.tvdb import TVDbAPI from modules.tvdb import TVDb
from modules.util import Failed from modules.util import Failed
from ruamel import yaml from ruamel import yaml
@ -214,7 +214,7 @@ class Config:
try: self.tmdb["apikey"] = check_for_attribute(self.data, "apikey", parent="tmdb", throw=True) try: self.tmdb["apikey"] = check_for_attribute(self.data, "apikey", parent="tmdb", throw=True)
except Failed as e: raise Failed(e) except Failed as e: raise Failed(e)
self.tmdb["language"] = check_for_attribute(self.data, "language", parent="tmdb", default="en") 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'}") logger.info(f"TMDb Connection {'Failed' if self.TMDb is None else 'Successful'}")
else: else:
raise Failed("Config Error: tmdb attribute not found") raise Failed("Config Error: tmdb attribute not found")
@ -227,7 +227,7 @@ class Config:
self.omdb = {} self.omdb = {}
try: try:
self.omdb["apikey"] = check_for_attribute(self.data, "apikey", parent="omdb", throw=True) 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: except Failed as e:
logger.error(e) logger.error(e)
logger.info(f"OMDb Connection {'Failed' if self.OMDb is None else 'Successful'}") 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["client_secret"] = check_for_attribute(self.data, "client_secret", parent="trakt", throw=True)
self.trakt["config_path"] = self.config_path 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 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: except Failed as e:
logger.error(e) logger.error(e)
logger.info(f"Trakt Connection {'Failed' if self.Trakt is None else 'Successful'}") 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["client_secret"] = check_for_attribute(self.data, "client_secret", parent="mal", throw=True)
self.mal["config_path"] = self.config_path 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 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: except Failed as e:
logger.error(e) logger.error(e)
logger.info(f"My Anime List Connection {'Failed' if self.MyAnimeList is None else 'Successful'}") logger.info(f"My Anime List Connection {'Failed' if self.MyAnimeList is None else 'Successful'}")
else: else:
logger.warning("mal attribute not found") logger.warning("mal attribute not found")
self.TVDb = TVDbAPI(self) self.TVDb = TVDb(self)
self.IMDb = IMDbAPI(self) self.IMDb = IMDb(self)
self.AniDB = AniDBAPI(self) self.AniDB = AniDB(self)
self.Convert = Convert(self) self.Convert = Convert(self)
self.AniList = AniListAPI(self) self.AniList = AniList(self)
self.Letterboxd = LetterboxdAPI(self) self.Letterboxd = Letterboxd(self)
util.separator() 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"]["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"]["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) 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("")
logger.info(f"{display_name} Library Connection Successful") logger.info(f"{display_name} Library Connection Successful")
except Failed as e: except Failed as e:
@ -517,7 +517,7 @@ class Config:
try: 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["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) 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: except Failed as e:
util.print_multiline(e, error=True) util.print_multiline(e, error=True)
logger.info("") logger.info("")

@ -8,7 +8,7 @@ logger = logging.getLogger("Plex Meta Manager")
builders = ["imdb_list", "imdb_id"] builders = ["imdb_list", "imdb_id"]
class IMDbAPI: class IMDb:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
self.urls = { self.urls = {

@ -8,7 +8,7 @@ logger = logging.getLogger("Plex Meta Manager")
builders = ["letterboxd_list", "letterboxd_list_details"] builders = ["letterboxd_list", "letterboxd_list_details"]
class LetterboxdAPI: class Letterboxd:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
self.url = "https://letterboxd.com" self.url = "https://letterboxd.com"

@ -72,7 +72,7 @@ userlist_status = [
"plan_to_watch" "plan_to_watch"
] ]
class MyAnimeListAPI: class MyAnimeList:
def __init__(self, params, config, authorization=None): def __init__(self, params, config, authorization=None):
self.config = config self.config = config
self.urls = { self.urls = {

@ -103,7 +103,7 @@ class Metadata:
logger.error(f"Metadata Error: {name} attribute is blank") logger.error(f"Metadata Error: {name} attribute is blank")
def add_advanced_edit(attr, obj, group, alias, show_library=False, new_agent=False): 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 attr in alias:
if new_agent and self.library.agent not in plex.new_plex_agents: 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") logger.error(f"Metadata Error: {attr} attribute only works for with the New Plex Movie Agent and New Plex TV Agent")

@ -31,7 +31,7 @@ class OMDbObj:
self.imdb_id = data["imdbID"] self.imdb_id = data["imdbID"]
self.type = data["Type"] self.type = data["Type"]
class OMDbAPI: class OMDb:
def __init__(self, params, Cache=None): def __init__(self, params, Cache=None):
self.url = "http://www.omdbapi.com/" self.url = "http://www.omdbapi.com/"
self.apikey = params["apikey"] self.apikey = params["apikey"]

@ -58,15 +58,6 @@ metadata_language_options["default"] = None
use_original_title_options = {"default": -1, "no": 0, "yes": 1} use_original_title_options = {"default": -1, "no": 0, "yes": 1}
collection_mode_keys = {-1: "default", 0: "hide", 1: "hideItems", 2: "showItems"} collection_mode_keys = {-1: "default", 0: "hide", 1: "hideItems", 2: "showItems"}
collection_order_keys = {0: "release", 1: "alpha", 2: "custom"} 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_advance_keys = {
"item_episode_sorting": ("episodeSort", episode_sorting_options), "item_episode_sorting": ("episodeSort", episode_sorting_options),
"item_keep_episodes": ("autoDeletionItemPolicyUnwatchedLibrary", keep_episodes_options), "item_keep_episodes": ("autoDeletionItemPolicyUnwatchedLibrary", keep_episodes_options),
@ -260,7 +251,7 @@ sort_types = {
"episodes": (4, episode_sorts), "episodes": (4, episode_sorts),
} }
class PlexAPI: class Plex:
def __init__(self, config, params): def __init__(self, config, params):
self.config = config self.config = config
try: try:

@ -8,7 +8,7 @@ logger = logging.getLogger("Plex Meta Manager")
builders = ["tautulli_popular", "tautulli_watched"] builders = ["tautulli_popular", "tautulli_watched"]
class TautulliAPI: class Tautulli:
def __init__(self, params): def __init__(self, params):
self.url = params["url"] self.url = params["url"]
self.apikey = params["apikey"] self.apikey = params["apikey"]

@ -108,7 +108,7 @@ discover_tv_sort = [
"popularity.desc", "popularity.asc" "popularity.desc", "popularity.asc"
] ]
class TMDbAPI: class TMDb:
def __init__(self, config, params): def __init__(self, config, params):
self.config = config self.config = config
self.TMDb = tmdbv3api.TMDb() self.TMDb = tmdbv3api.TMDb()

@ -3,7 +3,7 @@ from modules import util
from modules.util import Failed, TimeoutExpired from modules.util import Failed, TimeoutExpired
from retrying import retry from retrying import retry
from ruamel import yaml from ruamel import yaml
from trakt import Trakt from trakt import Trakt as TraktAPI
from trakt.objects.episode import Episode from trakt.objects.episode import Episode
from trakt.objects.movie import Movie from trakt.objects.movie import Movie
from trakt.objects.season import Season from trakt.objects.season import Season
@ -23,7 +23,7 @@ builders = [
"trakt_watchlist" "trakt_watchlist"
] ]
class TraktAPI: class Trakt:
def __init__(self, params, authorization=None): def __init__(self, params, authorization=None):
self.base_url = "https://api.trakt.tv" self.base_url = "https://api.trakt.tv"
self.redirect_uri = "urn:ietf:wg:oauth:2.0:oob" self.redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
@ -36,20 +36,20 @@ class TraktAPI:
self.client_secret = params["client_secret"] self.client_secret = params["client_secret"]
self.config_path = params["config_path"] self.config_path = params["config_path"]
self.authorization = authorization 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._save(self.authorization):
if not self._refresh(): if not self._refresh():
self._authorization() self._authorization()
def _authorization(self): 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(f"Navigate to: {url}")
logger.info("If you get an OAuth error your client_id or client_secret is invalid") logger.info("If you get an OAuth error your client_id or client_secret is invalid")
webbrowser.open(url, new=2) webbrowser.open(url, new=2)
try: pin = util.logger_input("Trakt pin (case insensitive)", timeout=300).strip() try: pin = util.logger_input("Trakt pin (case insensitive)", timeout=300).strip()
except TimeoutExpired: raise Failed("Input Timeout: Trakt pin required.") except TimeoutExpired: raise Failed("Input Timeout: Trakt pin required.")
if not pin: raise Failed("Trakt Error: No input 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: 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") 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): if not self._save(new_authorization):
@ -57,8 +57,8 @@ class TraktAPI:
def _check(self, authorization): def _check(self, authorization):
try: try:
with Trakt.configuration.oauth.from_response(authorization, refresh=True): with TraktAPI.configuration.oauth.from_response(authorization, refresh=True):
if Trakt["users/settings"].get(): if TraktAPI["users/settings"].get():
return True return True
except ValueError: pass except ValueError: pass
return False return False
@ -66,7 +66,7 @@ class TraktAPI:
def _refresh(self): def _refresh(self):
if self.authorization and "refresh_token" in self.authorization and self.authorization["refresh_token"]: if self.authorization and "refresh_token" in self.authorization and self.authorization["refresh_token"]:
logger.info("Refreshing Access 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 self._save(refreshed_authorization)
return False return False
@ -86,13 +86,13 @@ class TraktAPI:
logger.info(f"Saving authorization information to {self.config_path}") 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) yaml.round_trip_dump(config, open(self.config_path, "w"), indent=ind, block_seq_indent=bsi)
self.authorization = authorization self.authorization = authorization
Trakt.configuration.defaults.oauth.from_response(self.authorization) TraktAPI.configuration.defaults.oauth.from_response(self.authorization)
return True return True
return False return False
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) @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): 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: if lookup:
lookup = lookup[0] if isinstance(lookup, list) else lookup lookup = lookup[0] if isinstance(lookup, list) else lookup
if lookup.get_key(to_source): 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) @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): 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") if items is None: raise Failed("Trakt Error: No List found")
else: return [i for i in items] else: return [i for i in items]
@retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed) @retry(stop_max_attempt_number=6, wait_fixed=10000, retry_on_exception=util.retry_if_not_failed)
def standard_list(self, data): 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 except AttributeError: trakt_list = None
if trakt_list is None: raise Failed("Trakt Error: No List found") if trakt_list is None: raise Failed("Trakt Error: No List found")
else: return trakt_list else: return trakt_list

@ -74,7 +74,7 @@ class TVDbObj:
self.is_movie = is_movie self.is_movie = is_movie
self.TVDb = TVDb self.TVDb = TVDb
class TVDbAPI: class TVDb:
def __init__(self, config): def __init__(self, config):
self.config = config self.config = config
self.site_url = "https://www.thetvdb.com" self.site_url = "https://www.thetvdb.com"

Loading…
Cancel
Save