Plex-Meta-Manager/modules/icheckmovies.py

43 lines
1.8 KiB
Python
Raw Normal View History

2021-06-14 15:27:33 +00:00
from modules import util
from modules.util import Failed
logger = util.logger
2021-06-14 15:27:33 +00:00
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):
2022-09-07 19:32:52 +00:00
logger.trace(f"URL: {url}")
2021-07-14 14:47:20 +00:00
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-08-07 06:01:21 +00:00
return [(t[t.find("/tt") + 1:-1], "imdb") for t in imdb_urls]
2021-06-14 15:27:33 +00:00
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-07-21 17:40:05 +00:00
def validate_icheckmovies_lists(self, icheckmovies_lists, language):
valid_lists = []
for icheckmovies_list in util.get_list(icheckmovies_lists, split=False):
list_url = icheckmovies_list.strip()
if not list_url.startswith(base_url):
raise Failed(f"ICheckMovies Error: {list_url} must begin with: {base_url}")
2021-07-26 14:55:28 +00:00
elif len(self._parse_list(list_url, language)) > 0:
2021-07-21 17:40:05 +00:00
valid_lists.append(list_url)
2021-07-26 14:55:28 +00:00
else:
raise Failed(f"ICheckMovies Error: {list_url} failed to parse")
2021-07-21 17:40:05 +00:00
return valid_lists
2021-06-14 15:27:33 +00:00
2022-03-19 05:16:25 +00:00
def get_imdb_ids(self, method, data, language):
2021-06-14 15:27:33 +00:00
if method == "icheckmovies_list":
2021-08-01 04:35:42 +00:00
logger.info(f"Processing ICheckMovies List: {data}")
2021-08-07 06:01:21 +00:00
return self._parse_list(data, language)
2021-06-14 15:27:33 +00:00
else:
raise Failed(f"ICheckMovies Error: Method {method} not supported")