From 86dc07e895bc5d3aeb73c6b0cbda5e3cae03dd4a Mon Sep 17 00:00:00 2001 From: meisnate12 Date: Wed, 31 Aug 2022 09:49:52 -0400 Subject: [PATCH] [9] add item_genre detail --- VERSION | 2 +- modules/builder.py | 15 +++++++++++++-- modules/letterboxd.py | 21 +++++++-------------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/VERSION b/VERSION index ecfc8aaf..e670ea3c 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.17.3-develop8 +1.17.3-develop9 diff --git a/modules/builder.py b/modules/builder.py index dd796d89..5bb78146 100644 --- a/modules/builder.py +++ b/modules/builder.py @@ -52,8 +52,8 @@ collectionless_details = ["collection_order", "plex_collectionless", "label", "l poster_details + background_details + summary_details + string_details item_false_details = ["item_lock_background", "item_lock_poster", "item_lock_title"] item_bool_details = ["item_tmdb_season_titles", "revert_overlay", "item_assets", "item_refresh"] + item_false_details -item_details = ["non_item_remove_label", "item_label", "item_radarr_tag", "item_sonarr_tag", "item_refresh_delay"] + item_bool_details + list(plex.item_advance_keys.keys()) -none_details = ["label.sync", "item_label.sync", "radarr_taglist", "sonarr_taglist"] +item_details = ["non_item_remove_label", "item_label", "item_genre", "item_radarr_tag", "item_sonarr_tag", "item_refresh_delay"] + item_bool_details + list(plex.item_advance_keys.keys()) +none_details = ["label.sync", "item_label.sync", "item_genre.sync", "radarr_taglist", "sonarr_taglist"] radarr_details = [ "radarr_add_missing", "radarr_add_existing", "radarr_upgrade_existing", "radarr_folder", "radarr_monitor", "radarr_search", "radarr_availability", "radarr_quality", "radarr_tag", "item_radarr_tag" @@ -930,6 +930,12 @@ class CollectionBuilder: if "item_label.remove" in methods and "item_label.sync" in methods: raise Failed(f"{self.Type} Error: Cannot use item_label.remove and item_label.sync together") self.item_details[method_final] = util.get_list(method_data) if method_data else [] + if method_name == "item_genre": + if "item_genre" in methods and "item_genre.sync" in methods: + raise Failed(f"{self.Type} Error: Cannot use item_genre and item_genre.sync together") + if "item_genre.remove" in methods and "item_genre.sync" in methods: + raise Failed(f"{self.Type} Error: Cannot use item_genre.remove and item_genre.sync together") + self.item_details[method_final] = util.get_list(method_data) if method_data else [] elif method_name == "non_item_remove_label": if not method_data: raise Failed(f"{self.Type} Error: non_item_remove_label is blank") @@ -2350,6 +2356,10 @@ class CollectionBuilder: remove_tags = self.item_details["item_label.remove"] if "item_label.remove" in self.item_details else None sync_tags = self.item_details["item_label.sync"] if "item_label.sync" in self.item_details else None + add_genres = self.item_details["item_genres"] if "item_genres" in self.item_details else None + remove_genres = self.item_details["item_genres.remove"] if "item_genres.remove" in self.item_details else None + sync_genres = self.item_details["item_genres.sync"] if "item_genres.sync" in self.item_details else None + if "non_item_remove_label" in self.item_details: rk_compare = [item.ratingKey for item in self.items] for non_item in self.library.search(label=self.item_details["non_item_remove_label"], libtype=self.builder_level): @@ -2363,6 +2373,7 @@ class CollectionBuilder: if "item_assets" in self.item_details and self.library.asset_directory and "Overlay" not in current_labels: self.library.find_and_upload_assets(item, current_labels) self.library.edit_tags("label", item, add_tags=add_tags, remove_tags=remove_tags, sync_tags=sync_tags) + self.library.edit_tags("genre", item, add_tags=add_genres, remove_tags=remove_genres, sync_tags=sync_genres) path = os.path.dirname(str(item.locations[0])) if self.library.is_movie else str(item.locations[0]) if self.library.Radarr and item.ratingKey in self.library.movie_rating_key_map: path = path.replace(self.library.Radarr.plex_path, self.library.Radarr.radarr_path) diff --git a/modules/letterboxd.py b/modules/letterboxd.py index f4bed556..a2a075c8 100644 --- a/modules/letterboxd.py +++ b/modules/letterboxd.py @@ -12,29 +12,22 @@ class Letterboxd: self.config = config def _parse_page(self, list_url, language): - list_url = list_url.replace("https://letterboxd.com/films", "https://letterboxd.com/films/ajax") + if "ajax" not in list_url: + list_url = list_url.replace("https://letterboxd.com/films", "https://letterboxd.com/films/ajax") response = self.config.get_html(list_url, headers=util.header(language)) - letterboxd_ids = response.xpath( - "//li[contains(@class, 'poster-container') or contains(@class, 'film-detail')]/div/@data-film-id") + letterboxd_ids = response.xpath("//li[contains(@class, 'poster-container') or contains(@class, 'film-detail')]/div/@data-film-id") items = [] for letterboxd_id in letterboxd_ids: slugs = response.xpath(f"//div[@data-film-id='{letterboxd_id}']/@data-film-slug") - comments = response.xpath( - f"//div[@data-film-id='{letterboxd_id}']/parent::li/div[@class='film-detail-content']/div/p/text()") - ratings = response.xpath( - f"//div[@data-film-id='{letterboxd_id}']/parent::li/div[@class='film-detail-content']//span[contains(@class, 'rating')]/@class") - years = response.xpath( - f"//div[@data-film-id='{letterboxd_id}']/parent::li/div[@class='film-detail-content']/h2/small/a/text()") + comments = response.xpath(f"//div[@data-film-id='{letterboxd_id}']/parent::li/div[@class='film-detail-content']/div/p/text()") + ratings = response.xpath(f"//div[@data-film-id='{letterboxd_id}']/parent::li/div[@class='film-detail-content']//span[contains(@class, 'rating')]/@class") + years = response.xpath(f"//div[@data-film-id='{letterboxd_id}']/parent::li/div[@class='film-detail-content']/h2/small/a/text()") rating = None if ratings: match = re.search("rated-(\\d+)", ratings[0]) if match: rating = int(match.group(1)) - items.append((letterboxd_id, slugs[0], - int(years[0]) if years else None, - comments[0] if comments else None, - rating - )) + items.append((letterboxd_id, slugs[0], int(years[0]) if years else None, comments[0] if comments else None, rating)) next_url = response.xpath("//a[@class='next']/@href") return items, next_url