2021-07-14 14:47:20 +00:00
|
|
|
import logging
|
2021-06-14 15:27:33 +00:00
|
|
|
from modules import util
|
|
|
|
from modules.util import Failed
|
|
|
|
|
|
|
|
logger = logging.getLogger("Plex Meta Manager")
|
|
|
|
|
2021-07-03 19:17:05 +00:00
|
|
|
builders = ["icheckmovies_list", "icheckmovies_list_details"]
|
2021-07-14 14:47:20 +00:00
|
|
|
base_url = "https://www.icheckmovies.com/lists/"
|
2021-06-14 15:27:33 +00:00
|
|
|
|
|
|
|
class ICheckMovies:
|
|
|
|
def __init__(self, config):
|
|
|
|
self.config = config
|
|
|
|
|
2021-07-14 14:47:20 +00:00
|
|
|
def _request(self, url, language, xpath):
|
|
|
|
return self.config.get_html(url, headers=util.header(language)).xpath(xpath)
|
2021-06-14 15:27:33 +00:00
|
|
|
|
|
|
|
def _parse_list(self, list_url, language):
|
2021-07-14 14:47:20 +00:00
|
|
|
imdb_urls = self._request(list_url, language, "//a[@class='optionIcon optionIMDB external']/@href")
|
2021-06-14 15:27:33 +00:00
|
|
|
return [t[t.find("/tt") + 1:-1] for t in imdb_urls]
|
|
|
|
|
2021-07-03 19:17:05 +00:00
|
|
|
def get_list_description(self, list_url, language):
|
2021-07-14 14:47:20 +00:00
|
|
|
descriptions = self._request(list_url, language, "//div[@class='span-19 last']/p/em/text()")
|
2021-07-03 19:17:05 +00:00
|
|
|
return descriptions[0] if len(descriptions) > 0 and len(descriptions[0]) > 0 else None
|
|
|
|
|
2021-06-14 15:27:33 +00:00
|
|
|
def validate_icheckmovies_list(self, list_url, language):
|
|
|
|
list_url = list_url.strip()
|
2021-07-14 14:47:20 +00:00
|
|
|
if not list_url.startswith(base_url):
|
|
|
|
raise Failed(f"ICheckMovies Error: {list_url} must begin with: {base_url}")
|
2021-06-14 15:27:33 +00:00
|
|
|
if len(self._parse_list(list_url, language)) > 0:
|
|
|
|
return list_url
|
|
|
|
raise Failed(f"ICheckMovies Error: {list_url} failed to parse")
|
|
|
|
|
|
|
|
def get_items(self, method, data, language):
|
|
|
|
pretty = util.pretty_names[method] if method in util.pretty_names else method
|
|
|
|
movie_ids = []
|
|
|
|
if method == "icheckmovies_list":
|
|
|
|
logger.info(f"Processing {pretty}: {data}")
|
|
|
|
imdb_ids = self._parse_list(data, language)
|
|
|
|
total_ids = len(imdb_ids)
|
|
|
|
for i, imdb_id in enumerate(imdb_ids, 1):
|
|
|
|
try:
|
|
|
|
util.print_return(f"Converting IMDb ID {i}/{total_ids}")
|
|
|
|
movie_ids.append(self.config.Convert.imdb_to_tmdb(imdb_id))
|
|
|
|
except Failed as e:
|
|
|
|
logger.error(e)
|
|
|
|
logger.info(util.adjust_space(f"Processed {total_ids} IMDb IDs"))
|
|
|
|
else:
|
|
|
|
raise Failed(f"ICheckMovies Error: Method {method} not supported")
|
|
|
|
logger.debug("")
|
2021-07-03 01:47:09 +00:00
|
|
|
logger.debug(f"{len(movie_ids)} TMDb IDs Found: {movie_ids}")
|
2021-06-14 15:27:33 +00:00
|
|
|
return movie_ids, []
|