diff --git a/modules/tvdb.py b/modules/tvdb.py index d2f2843a..5cbc0c2d 100644 --- a/modules/tvdb.py +++ b/modules/tvdb.py @@ -38,20 +38,30 @@ class TVDbObj: else: raise Failed(f"TVDb Error: Could not find a TVDb {self.media_type} ID at the URL {self.tvdb_url}") - results = response.xpath("//div[@class='change_translation_text' and @data-language='eng']/@data-title") - if len(results) > 0 and len(results[0]) > 0: - self.title = results[0] + def parse_page(xpath, fail=None, multi=False): + parse_results = response.xpath(xpath) + if len(parse_results) > 0: + parse_results = [r.strip() for r in parse_results if len(r) > 0] + if not multi and len(parse_results) > 0: + return parse_results[0] + elif len(parse_results) > 0: + return parse_results + elif fail is not None: + raise Failed(f"TVDb Error: {fail} not found from TVDb URL: {self.tvdb_url}") + else: + return None + + self.title = parse_page("//div[@class='change_translation_text' and not(@style='display:none')]/@data-title", fail="Name") + self.poster_path = parse_page("//div[@class='row hidden-xs hidden-sm']/div/img/@src") + self.background_path = parse_page("(//h2[@class='mt-4' and text()='Backgrounds']/following::div/a/@href)[1]") + self.summary = parse_page("//div[@class='change_translation_text' and not(@style='display:none')]/p/text()[normalize-space()]") + if self.is_movie: + self.directors = parse_page("//strong[text()='Directors']/parent::li/span/a/text()[normalize-space()]") + self.writers = parse_page("//strong[text()='Writers']/parent::li/span/a/text()[normalize-space()]") + self.studios = parse_page("//strong[text()='Studio']/parent::li/span/a/text()[normalize-space()]") else: - raise Failed(f"TVDb Error: Name not found from TVDb URL: {self.tvdb_url}") - - results = response.xpath("//div[@class='row hidden-xs hidden-sm']/div/img/@src") - self.poster_path = results[0] if len(results) > 0 and len(results[0]) > 0 else None - - results = response.xpath("(//h2[@class='mt-4' and text()='Backgrounds']/following::div/a/@href)[1]") - self.background_path = results[0] if len(results) > 0 and len(results[0]) > 0 else None - - results = response.xpath("//div[@class='block']/div[not(@style='display:none')]/p/text()") - self.summary = results[0] if len(results) > 0 and len(results[0]) > 0 else None + self.networks = parse_page("//strong[text()='Networks']/parent::li/span/a/text()[normalize-space()]") + self.genres = parse_page("//strong[text()='Genres']/parent::li/span/a/text()[normalize-space()]") tmdb_id = None imdb_id = None diff --git a/plex_meta_manager.py b/plex_meta_manager.py index 7f0fdf98..1efca2e1 100644 --- a/plex_meta_manager.py +++ b/plex_meta_manager.py @@ -279,7 +279,7 @@ def mass_metadata(config, library, items): if not tmdb_id and not tvdb_id: tmdb_id = library.get_tmdb_from_map(item) if not tmdb_id and not tvdb_id and library.is_show: - tmdb_id = library.get_tvdb_from_map(item) + tvdb_id = library.get_tvdb_from_map(item) if library.mass_trakt_rating_update: try: @@ -330,7 +330,17 @@ def mass_metadata(config, library, items): else: logger.info(util.adjust_space(f"{item.title[:25]:<25} | No IMDb ID for Guid: {item.guid}")) - if not tmdb_item and not omdb_item: + tvdb_item = None + if library.mass_genre_update == "tvdb": + if tvdb_id: + try: + tvdb_item = config.TVDb.get_item(tvdb_id, library.is_movie) + except Failed as e: + logger.error(util.adjust_space(str(e))) + else: + logger.info(util.adjust_space(f"{item.title[:25]:<25} | No TVDb ID for Guid: {item.guid}")) + + if not tmdb_item and not omdb_item and not tvdb_item: continue if library.mass_genre_update: @@ -339,6 +349,8 @@ def mass_metadata(config, library, items): new_genres = [genre.name for genre in tmdb_item.genres] elif omdb_item and library.mass_genre_update in ["omdb", "imdb"]: new_genres = omdb_item.genres + elif tvdb_item and library.mass_genre_update == "tvdb": + new_genres = tvdb_item.genres else: raise Failed item_genres = [genre.tag for genre in item.genres]