Skip to content

Commit

Permalink
added letterboxd list descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Mar 8, 2021
1 parent 716d5d4 commit 1ebaf44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
7 changes: 7 additions & 0 deletions modules/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,8 @@ def replace_txt(txt):
self.summaries[method_name] = config.TVDb.get_list_description(data[m], self.library.Plex.language)
elif method_name == "trakt_description":
self.summaries[method_name] = config.Trakt.standard_list(config.Trakt.validate_trakt_list(util.get_list(data[m]))[0]).description
elif method_name == "letterboxd_description":
self.summaries[method_name] = config.Letterboxd.get_list_description(data[m], self.library.Plex.language)
elif method_name == "collection_mode":
if data[m] in ["default", "hide", "hide_items", "show_items", "hideItems", "showItems"]:
if data[m] == "hide_items": self.details[method_name] = "hideItems"
Expand Down Expand Up @@ -347,6 +349,10 @@ def replace_txt(txt):
self.methods.append((method_name, new_list))
elif method_name == "letterboxd_list":
self.methods.append((method_name, util.get_list(data[m], split=False)))
elif method_name == "letterboxd_list_details":
values = util.get_list(data[m], split=False)
self.summaries[method_name] = config.Letterboxd.get_list_description(values[0], self.library.Plex.language)
self.methods.append((method_name[:-8], values))
elif method_name in util.dictionary_lists:
if isinstance(data[m], dict):
def get_int(parent, method, data_in, default_in, minimum=1, maximum=None):
Expand Down Expand Up @@ -803,6 +809,7 @@ def get_summary(summary_method, summaries):
return summaries[summary_method]
if "summary" in self.summaries: summary = get_summary("summary", self.summaries)
elif "tmdb_description" in self.summaries: summary = get_summary("tmdb_description", self.summaries)
elif "letterboxd_description" in self.summaries: summary = get_summary("letterboxd_description", self.summaries)
elif "tmdb_summary" in self.summaries: summary = get_summary("tmdb_summary", self.summaries)
elif "tvdb_summary" in self.summaries: summary = get_summary("tvdb_summary", self.summaries)
elif "tmdb_biography" in self.summaries: summary = get_summary("tmdb_biography", self.summaries)
Expand Down
12 changes: 8 additions & 4 deletions modules/letterboxd.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,15 @@ def __init__(self):
self.url = "https://letterboxd.com"

@retry(stop_max_attempt_number=6, wait_fixed=10000)
def send_request(self, url, header):
return html.fromstring(requests.get(url, headers=header).content)
def send_request(self, url, language):
return html.fromstring(requests.get(url, header={"Accept-Language": language, "User-Agent": "Mozilla/5.0 x64"}).content)

def get_list_description(self, list_url, language):
descriptions = self.send_request(list_url, language).xpath("//meta[@property='og:description']/@content")
return descriptions[0] if len(descriptions) > 0 and len(descriptions[0]) > 0 else None

def parse_list_for_slugs(self, list_url, language):
response = self.send_request(list_url, header={"Accept-Language": language, "User-Agent": "Mozilla/5.0 x64"})
response = self.send_request(list_url, language)
slugs = response.xpath("//div[@class='poster film-poster really-lazy-load']/@data-film-slug")
next_url = response.xpath("//a[@class='next']/@href")
if len(next_url) > 0:
Expand All @@ -26,7 +30,7 @@ def get_tmdb_from_slug(self, slug, language):
return self.get_tmdb(f"{self.url}{slug}", language)

def get_tmdb(self, letterboxd_url, language):
response = self.send_request(letterboxd_url, header={"Accept-Language": language, "User-Agent": "Mozilla/5.0 x64"})
response = self.send_request(letterboxd_url, language)
ids = response.xpath("//body/@data-tmdb-id")
if len(ids) > 0:
return int(ids[0])
Expand Down
5 changes: 4 additions & 1 deletion modules/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ def retry_if_not_failed(exception):
"imdb_list": "IMDb List",
"imdb_id": "IMDb ID",
"letterboxd_list": "Letterboxd List",
"letterboxd_list_details": "Letterboxd List",
"mal_id": "MyAnimeList ID",
"mal_all": "MyAnimeList All",
"mal_airing": "MyAnimeList Airing",
Expand Down Expand Up @@ -220,6 +221,7 @@ def retry_if_not_failed(exception):
"imdb_list",
"imdb_id",
"letterboxd_list",
"letterboxd_list_details",
"mal_id",
"mal_all",
"mal_airing",
Expand Down Expand Up @@ -322,6 +324,7 @@ def retry_if_not_failed(exception):
]
movie_only_lists = [
"letterboxd_list",
"letterboxd_list_details",
"tmdb_collection",
"tmdb_collection_details",
"tmdb_movie",
Expand Down Expand Up @@ -454,7 +457,7 @@ def retry_if_not_failed(exception):
]
all_details = [
"sort_title", "content_rating",
"summary", "tmdb_summary", "tmdb_description", "tmdb_biography", "tvdb_summary", "tvdb_description", "trakt_description",
"summary", "tmdb_summary", "tmdb_description", "tmdb_biography", "tvdb_summary", "tvdb_description", "trakt_description", "letterboxd_description",
"collection_mode", "collection_order",
"url_poster", "tmdb_poster", "tmdb_profile", "tvdb_poster", "file_poster",
"url_background", "tmdb_background", "tvdb_background", "file_background",
Expand Down

0 comments on commit 1ebaf44

Please sign in to comment.