Plex-Meta-Manager/modules/reciperr.py

40 lines
1.4 KiB
Python
Raw Normal View History

2022-03-19 05:16:25 +00:00
from modules import util
from modules.util import Failed
logger = util.logger
builders = ["reciperr_list", "stevenlu_popular"]
stevenlu_url = "https://s3.amazonaws.com/popular-movies/movies.json"
class Reciperr:
def __init__(self, config):
self.config = config
def _request(self, url, name="Reciperr"):
response = self.config.get(url)
if response.status_code >= 400:
raise Failed(f"{name} Error: JSON not found at {url}")
return response.json()
def validate_list(self, data):
valid_lists = []
for reciperr_list in util.get_list(data, split=False):
if "imdb_id" not in self._request(reciperr_list)[0]:
raise Failed(f"Reciperr Error: imdb_id not found in the JSON at {reciperr_list}")
valid_lists.append(reciperr_list)
return valid_lists
def get_imdb_ids(self, method, data):
2022-08-03 14:07:21 +00:00
name = "StevenLu" if method == "stevenlu_popular" else "Reciperr"
logger.info(f"Processing {name} Movies")
2022-03-19 05:16:25 +00:00
if method == "reciperr_list":
2024-04-30 21:03:37 +00:00
ids = [(i["imdb_id"], "imdb") for i in self._request(data) if "imdb_id" in i]
2022-03-19 05:16:25 +00:00
elif method == "stevenlu_popular":
2022-08-03 14:07:21 +00:00
ids = [(i["imdb_id"], "imdb") for i in self._request(stevenlu_url, name="StevenLu")]
2022-03-19 05:16:25 +00:00
else:
2022-08-03 14:07:21 +00:00
raise Failed(f"Config Error: Method {method} not supported")
if not ids:
raise Failed(f"{name} Error: No IDs found.")
return ids