added tvdb details methods #92

pull/83/head
meisnate12 4 years ago
parent e3ffced219
commit 5156d92b7c

@ -529,6 +529,38 @@ class CollectionBuilder:
logger.warning(f"Collection Warning: {method_name} must be an integer greater then 0 defaulting to 20") logger.warning(f"Collection Warning: {method_name} must be an integer greater then 0 defaulting to 20")
list_count = 20 list_count = 20
self.methods.append((method_name, [list_count])) self.methods.append((method_name, [list_count]))
elif "tvdb" in method_name:
values = util.get_list(data[m])
if method_name[-8:] == "_details":
if method_name == "tvdb_movie_details":
try:
item = config.TVDb.get_movie(self.library.Plex.language, tvdb_id=int(values[0])).id
except ValueError:
item = config.TVDb.get_movie(self.library.Plex.language, tvdb_url=values[0]).id
if hasattr(item, "description") and item.description:
self.summaries[method_name] = item.description
if hasattr(item, "background_path") and item.background_path:
self.backgrounds[method_name] = f"{config.TMDb.image_url}{item.background_path}"
if hasattr(item, "poster_path") and item.poster_path:
self.posters[method_name] = f"{config.TMDb.image_url}{item.poster_path}"
elif method_name == "tvdb_show_details":
try:
item = config.TVDb.get_series(self.library.Plex.language, tvdb_id=int(values[0])).id
except ValueError:
item = config.TVDb.get_series(self.library.Plex.language, tvdb_url=values[0]).id
if hasattr(item, "description") and item.description:
self.summaries[method_name] = item.description
if hasattr(item, "background_path") and item.background_path:
self.backgrounds[method_name] = f"{config.TMDb.image_url}{item.background_path}"
if hasattr(item, "poster_path") and item.poster_path:
self.posters[method_name] = f"{config.TMDb.image_url}{item.poster_path}"
elif method_name == "tvdb_list_details":
description = config.TVDb.get_list_description(self.library.Plex.language, values[0])
if description and len(description) > 0:
self.summaries[method_name] = description
self.methods.append((method_name[:-8], values))
else:
self.methods.append((method_name, values))
elif method_name in util.tmdb_lists: elif method_name in util.tmdb_lists:
values = config.TMDb.validate_tmdb_list(util.get_int_list(data[m], f"TMDb {util.tmdb_type[method_name]} ID"), util.tmdb_type[method_name]) values = config.TMDb.validate_tmdb_list(util.get_int_list(data[m], f"TMDb {util.tmdb_type[method_name]} ID"), util.tmdb_type[method_name])
if method_name[-8:] == "_details": if method_name[-8:] == "_details":
@ -761,6 +793,8 @@ class CollectionBuilder:
elif "tmdb_producer_details" in self.summaries: summary = get_summary("tmdb_producer_details", self.summaries) elif "tmdb_producer_details" in self.summaries: summary = get_summary("tmdb_producer_details", self.summaries)
elif "tmdb_writer_details" in self.summaries: summary = get_summary("tmdb_writer_details", self.summaries) elif "tmdb_writer_details" in self.summaries: summary = get_summary("tmdb_writer_details", self.summaries)
elif "tmdb_movie_details" in self.summaries: summary = get_summary("tmdb_movie_details", self.summaries) elif "tmdb_movie_details" in self.summaries: summary = get_summary("tmdb_movie_details", self.summaries)
elif "tvdb_movie_details" in self.summaries: summary = get_summary("tvdb_movie_details", self.summaries)
elif "tvdb_show_details" in self.summaries: summary = get_summary("tvdb_show_details", self.summaries)
elif "tmdb_show_details" in self.summaries: summary = get_summary("tmdb_show_details", self.summaries) elif "tmdb_show_details" in self.summaries: summary = get_summary("tmdb_show_details", self.summaries)
else: summary = None else: summary = None
if summary: if summary:
@ -868,6 +902,8 @@ class CollectionBuilder:
elif "tmdb_producer_details" in self.posters: set_image("tmdb_producer_details", self.posters) elif "tmdb_producer_details" in self.posters: set_image("tmdb_producer_details", self.posters)
elif "tmdb_writer_details" in self.posters: set_image("tmdb_writer_details", self.posters) elif "tmdb_writer_details" in self.posters: set_image("tmdb_writer_details", self.posters)
elif "tmdb_movie_details" in self.posters: set_image("tmdb_movie_details", self.posters) elif "tmdb_movie_details" in self.posters: set_image("tmdb_movie_details", self.posters)
elif "tvdb_movie_details" in self.posters: set_image("tvdb_movie_details", self.posters)
elif "tvdb_show_details" in self.posters: set_image("tvdb_show_details", self.posters)
elif "tmdb_show_details" in self.posters: set_image("tmdb_show_details", self.posters) elif "tmdb_show_details" in self.posters: set_image("tmdb_show_details", self.posters)
else: logger.info("No poster to update") else: logger.info("No poster to update")
@ -884,6 +920,8 @@ class CollectionBuilder:
elif "asset_directory" in self.backgrounds: set_image("asset_directory", self.backgrounds, is_background=True) elif "asset_directory" in self.backgrounds: set_image("asset_directory", self.backgrounds, is_background=True)
elif "tmdb_collection_details" in self.backgrounds: set_image("tmdb_collection_details", self.backgrounds, is_background=True) elif "tmdb_collection_details" in self.backgrounds: set_image("tmdb_collection_details", self.backgrounds, is_background=True)
elif "tmdb_movie_details" in self.backgrounds: set_image("tmdb_movie_details", self.backgrounds, is_background=True) elif "tmdb_movie_details" in self.backgrounds: set_image("tmdb_movie_details", self.backgrounds, is_background=True)
elif "tvdb_movie_details" in self.backgrounds: set_image("tvdb_movie_details", self.backgrounds, is_background=True)
elif "tvdb_show_details" in self.backgrounds: set_image("tvdb_show_details", self.backgrounds, is_background=True)
elif "tmdb_show_details" in self.backgrounds: set_image("tmdb_show_details", self.backgrounds, is_background=True) elif "tmdb_show_details" in self.backgrounds: set_image("tmdb_show_details", self.backgrounds, is_background=True)
else: logger.info("No background to update") else: logger.info("No background to update")

@ -36,6 +36,12 @@ class TVDbObj:
results = response.xpath("//div[@class='row hidden-xs hidden-sm']/div/img/@src") 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 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.description = results[0] if len(results) > 0 and len(results[0]) > 0 else None
tmdb_id = None tmdb_id = None
if is_movie: if is_movie:
results = response.xpath("//*[text()='TheMovieDB.com']/@href") results = response.xpath("//*[text()='TheMovieDB.com']/@href")
@ -81,6 +87,10 @@ class TVDbAPI:
tvdb_url = f"{self.movie_id_url}{tvdb_id}" tvdb_url = f"{self.movie_id_url}{tvdb_id}"
return TVDbObj(tvdb_url, language, True, self) return TVDbObj(tvdb_url, language, True, self)
def get_list_description(self, language, tvdb_url):
description = self.send_request(tvdb_url, language).xpath("//div[@class='block']/div[not(@style='display:none')]/p/text()")
return description[0] if len(description) > 0 and len(description[0]) > 0 else ""
def get_tvdb_ids_from_url(self, tvdb_url, language): def get_tvdb_ids_from_url(self, tvdb_url, language):
show_ids = [] show_ids = []
movie_ids = [] movie_ids = []

@ -145,11 +145,15 @@ pretty_names = {
"tmdb_writer": "TMDb Writer", "tmdb_writer": "TMDb Writer",
"tmdb_writer_details": "TMDb Writer", "tmdb_writer_details": "TMDb Writer",
"trakt_list": "Trakt List", "trakt_list": "Trakt List",
"trakt_list_details": "Trakt List",
"trakt_trending": "Trakt Trending", "trakt_trending": "Trakt Trending",
"trakt_watchlist": "Trakt Watchlist", "trakt_watchlist": "Trakt Watchlist",
"tvdb_list": "TVDb List", "tvdb_list": "TVDb List",
"tvdb_list_details": "TVDb List",
"tvdb_movie": "TVDb Movie", "tvdb_movie": "TVDb Movie",
"tvdb_show": "TVDb Show" "tvdb_movie_details": "TVDb Movie",
"tvdb_show": "TVDb Show",
"tvdb_show_details": "TVDb Show"
} }
mal_ranked_name = { mal_ranked_name = {
"mal_all": "all", "mal_all": "all",
@ -261,11 +265,15 @@ all_lists = [
"tmdb_writer", "tmdb_writer",
"tmdb_writer_details", "tmdb_writer_details",
"trakt_list", "trakt_list",
"trakt_list_details",
"trakt_trending", "trakt_trending",
"trakt_watchlist", "trakt_watchlist",
"tvdb_list", "tvdb_list",
"tvdb_list_details",
"tvdb_movie", "tvdb_movie",
"tvdb_show" "tvdb_movie_details",
"tvdb_show",
"tvdb_show_details"
] ]
collectionless_lists = [ collectionless_lists = [
"sort_title", "content_rating", "sort_title", "content_rating",
@ -308,7 +316,8 @@ show_only_lists = [
"tmdb_network", "tmdb_network",
"tmdb_show", "tmdb_show",
"tmdb_show_details", "tmdb_show_details",
"tvdb_show" "tvdb_show",
"tvdb_show_details"
] ]
movie_only_lists = [ movie_only_lists = [
"letterboxd_list", "letterboxd_list",
@ -317,7 +326,8 @@ movie_only_lists = [
"tmdb_movie", "tmdb_movie",
"tmdb_movie_details", "tmdb_movie_details",
"tmdb_now_playing", "tmdb_now_playing",
"tvdb_movie" "tvdb_movie",
"tvdb_movie_details"
] ]
movie_only_searches = [ movie_only_searches = [
"actor", "actor.not", "actor", "actor.not",

Loading…
Cancel
Save