pull/83/head
meisnate12 4 years ago
parent fd0301e68a
commit 4a8f825f7b

@ -43,6 +43,8 @@ sonarr: # Can be individually specified
root_folder_path: "S:/TV Shows"
add: false
search: false
omdb:
apikey: ########
trakt:
client_id: ################################################################
client_secret: ################################################################

@ -7,10 +7,8 @@ from retrying import retry
logger = logging.getLogger("Plex Meta Manager")
class AniDBAPI:
def __init__(self, Cache=None, TMDb=None, Trakt=None):
self.Cache = Cache
self.TMDb = TMDb
self.Trakt = Trakt
def __init__(self, config):
self.config = config
self.urls = {
"anime": "https://anidb.net/anime",
"popular": "https://anidb.net/latest/anime/popular/?h=1",
@ -62,7 +60,7 @@ class AniDBAPI:
return anidb_values
raise Failed(f"AniDB Error: No valid AniDB IDs in {anidb_list}")
def get_items(self, config, method, data, language, status_message=True):
def get_items(self, method, data, language, status_message=True):
pretty = util.pretty_names[method] if method in util.pretty_names else method
if status_message:
logger.debug(f"Data: {data}")
@ -81,7 +79,7 @@ class AniDBAPI:
for anidb_id in anime_ids:
try:
for imdb_id in self.convert_anidb_to_imdb(anidb_id):
tmdb_id, _ = config.convert_from_imdb(imdb_id, language)
tmdb_id, _ = self.config.convert_from_imdb(imdb_id, language)
if tmdb_id: movie_ids.append(tmdb_id)
else: raise Failed
except Failed:

@ -648,10 +648,10 @@ class CollectionBuilder:
elif "tautulli" in method:
items = self.library.Tautulli.get_items(self.library, time_range=value["list_days"], stats_count=value["list_size"], list_type=value["list_type"], stats_count_buffer=value["list_buffer"])
items_found += len(items)
elif "anidb" in method: items_found += check_map(self.config.AniDB.get_items(self.config, method, value, self.library.Plex.language))
elif "anidb" in method: items_found += check_map(self.config.AniDB.get_items(method, value, self.library.Plex.language))
elif "mal" in method: items_found += check_map(self.config.MyAnimeList.get_items(method, value))
elif "tvdb" in method: items_found += check_map(self.config.TVDb.get_items(method, value, self.library.Plex.language))
elif "imdb" in method: items_found += check_map(self.config.IMDb.get_items(self.config, method, value, self.library.Plex.language))
elif "imdb" in method: items_found += check_map(self.config.IMDb.get_items(method, value, self.library.Plex.language))
elif "letterboxd" in method: items_found += check_map(self.config.Letterboxd.get_items(method, value, self.library.Plex.language))
elif "tmdb" in method: items_found += check_map(self.config.TMDb.get_items(method, value, self.library.is_movie))
elif "trakt" in method: items_found += check_map(self.config.Trakt.get_items(method, value, self.library.is_movie))

@ -52,7 +52,6 @@ class Cache:
)
self.expiration = expiration
self.cache_path = cache
self.omdb_expiration = expiration
def get_ids_from_imdb(self, imdb_id):
tmdb_id, tmdb_expired = self.get_tmdb_id("movie", imdb_id=imdb_id)
@ -197,11 +196,11 @@ class Cache:
omdb_dict["Type"] = row["type"] if row["type"] else None
datetime_object = datetime.strptime(row["expiration_date"], "%Y-%m-%d")
time_between_insertion = datetime.now() - datetime_object
expired = time_between_insertion.days > self.omdb_expiration
expired = time_between_insertion.days > self.expiration
return omdb_dict, expired
def update_omdb(self, expired, omdb):
expiration_date = datetime.now() if expired is True else (datetime.now() - timedelta(days=random.randint(1, self.omdb_expiration)))
expiration_date = datetime.now() if expired is True else (datetime.now() - timedelta(days=random.randint(1, self.expiration)))
with sqlite3.connect(self.cache_path) as connection:
connection.row_factory = sqlite3.Row
with closing(connection.cursor()) as cursor:

@ -180,8 +180,6 @@ class Config:
self.omdb = {}
try:
self.omdb["apikey"] = check_for_attribute(self.data, "apikey", parent="omdb", throw=True)
self.omdb["omdb_cache"] = check_for_attribute(self.data, "omdb_cache", parent="omdb", options=" true (Use a cache to store data)\n false (Do not use a cache to store data)", var_type="bool", default=self.general["cache"])
self.omdb["omdb_cache_expiration"] = check_for_attribute(self.data, "omdb_cache_expiration", parent="omdb", var_type="int", default=self.general["cache_expiration"])
self.OMDb = OMDbAPI(self.omdb, Cache=self.Cache)
except Failed as e:
logger.error(e)
@ -226,9 +224,9 @@ class Config:
else:
logger.warning("mal attribute not found")
self.TVDb = TVDbAPI(self, Cache=self.Cache, TMDb=self.TMDb, Trakt=self.Trakt)
self.IMDb = IMDbAPI(Cache=self.Cache, TMDb=self.TMDb, Trakt=self.Trakt, TVDb=self.TVDb) if self.TMDb or self.Trakt else None
self.AniDB = AniDBAPI(Cache=self.Cache, TMDb=self.TMDb, Trakt=self.Trakt)
self.TVDb = TVDbAPI(self)
self.IMDb = IMDbAPI(self)
self.AniDB = AniDBAPI(self)
self.Letterboxd = LetterboxdAPI()
util.separator()

@ -7,23 +7,22 @@ from retrying import retry
logger = logging.getLogger("Plex Meta Manager")
class IMDbAPI:
def __init__(self, Cache=None, TMDb=None, Trakt=None, TVDb=None):
if TMDb is None and Trakt is None:
raise Failed("IMDb Error: IMDb requires either TMDb or Trakt")
self.Cache = Cache
self.TMDb = TMDb
self.Trakt = Trakt
self.TVDb = TVDb
def __init__(self, config):
self.config = config
self.urls = {
"list": "https://www.imdb.com/list/ls",
"search": "https://www.imdb.com/search/title/?"
}
def get_imdb_ids_from_url(self, imdb_url, language, limit):
imdb_url = imdb_url.strip()
if not imdb_url.startswith("https://www.imdb.com/list/ls") and not imdb_url.startswith("https://www.imdb.com/search/title/?"):
raise Failed(f"IMDb Error: {imdb_url} must begin with either:\n| https://www.imdb.com/list/ls (For Lists)\n| https://www.imdb.com/search/title/? (For Searches)")
if not imdb_url.startswith(self.urls["list"]) and not imdb_url.startswith(self.urls["search"]):
raise Failed(f"IMDb Error: {imdb_url} must begin with either:\n| {self.urls['list']} (For Lists)\n| {self.urls['search']} (For Searches)")
if imdb_url.startswith("https://www.imdb.com/list/ls"):
if imdb_url.startswith(self.urls["list"]):
try: list_id = re.search("(\\d+)", str(imdb_url)).group(1)
except AttributeError: raise Failed(f"IMDb Error: Failed to parse List ID from {imdb_url}")
current_url = f"https://www.imdb.com/search/title/?lists=ls{list_id}"
current_url = f"{self.urls['search']}lists=ls{list_id}"
else:
current_url = imdb_url
header = {"Accept-Language": language}
@ -52,7 +51,7 @@ class IMDbAPI:
def send_request(self, url, header):
return html.fromstring(requests.get(url, headers=header).content)
def get_items(self, config, method, data, language, status_message=True):
def get_items(self, method, data, language, status_message=True):
pretty = util.pretty_names[method] if method in util.pretty_names else method
if status_message:
logger.debug(f"Data: {data}")
@ -61,7 +60,7 @@ class IMDbAPI:
if method == "imdb_id":
if status_message:
logger.info(f"Processing {pretty}: {data}")
tmdb_id, tvdb_id = config.convert_from_imdb(data, language)
tmdb_id, tvdb_id = self.config.convert_from_imdb(data, language)
if tmdb_id: movie_ids.append(tmdb_id)
if tvdb_id: show_ids.append(tvdb_id)
elif method == "imdb_list":
@ -74,7 +73,7 @@ class IMDbAPI:
for i, imdb_id in enumerate(imdb_ids, 1):
length = util.print_return(length, f"Converting IMDb ID {i}/{total_ids}")
try:
tmdb_id, tvdb_id = config.convert_from_imdb(imdb_id, language)
tmdb_id, tvdb_id = self.config.convert_from_imdb(imdb_id, language)
if tmdb_id: movie_ids.append(tmdb_id)
if tvdb_id: show_ids.append(tvdb_id)
except Failed as e: logger.warning(e)

@ -36,24 +36,21 @@ class OMDbAPI:
def __init__(self, params, Cache=None):
self.url = "http://www.omdbapi.com/"
self.apikey = params["apikey"]
self.cache = params["omdb_cache"]
self.cache_expiration = params["omdb_cache_expiration"]
self.limit = False
Cache.omdb_expiration = self.cache_expiration
self.Cache = Cache
self.get_omdb("tt0080684")
#@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 get_omdb(self, imdb_id):
expired = None
if self.cache and self.Cache:
if self.Cache:
omdb_dict, expired = self.Cache.query_omdb(imdb_id)
if omdb_dict and expired is False:
return OMDbObj(omdb_dict)
response = requests.get(self.url, params={"i": imdb_id, "apikey": self.apikey})
if response.status_code < 400:
omdb = OMDbObj(response.json())
if self.cache and self.Cache:
if self.Cache:
self.Cache.update_omdb(expired, omdb)
return omdb
else:

@ -54,11 +54,8 @@ class TVDbObj:
self.TVDb = TVDb
class TVDbAPI:
def __init__(self, config, Cache=None, TMDb=None, Trakt=None):
def __init__(self, config):
self.config = config
self.Cache = Cache
self.TMDb = TMDb
self.Trakt = Trakt
self.site_url = "https://www.thetvdb.com"
self.alt_site_url = "https://thetvdb.com"
self.list_url = f"{self.site_url}/lists/"

Loading…
Cancel
Save