added tvdb_language

pull/420/head
meisnate12 3 years ago
parent 39c9bfa28d
commit 89beded782

@ -29,6 +29,15 @@ settings: # Can be individually specified
show_missing: true
save_missing: true
run_again_delay: 2
released_missing_only: false
create_asset_folders: false
missing_only_released: false
collection_minimum: 1
delete_below_minimum: true
notifiarr_collection_creation: false
notifiarr_collection_addition: false
notifiarr_collection_removing: false
tvdb_language: eng
plex: # Can be individually specified per library as well
url: http://192.168.1.12:32400
token: ####################
@ -67,6 +76,9 @@ sonarr: # Can be individually specified
cutoff_search: false
omdb:
apikey: ########
notifiarr:
apikey: ####################################
error_notification: true
trakt:
client_id: ################################################################
client_secret: ################################################################

@ -651,9 +651,9 @@ class CollectionBuilder:
elif method_name == "tmdb_biography":
self.summaries[method_name] = self.config.TMDb.get_person(util.regex_first_int(method_data, "TMDb Person ID")).biography
elif method_name == "tvdb_summary":
self.summaries[method_name] = self.config.TVDb.get_movie_or_show(method_data, self.language, self.library.is_movie).summary
self.summaries[method_name] = self.config.TVDb.get_item(method_data, self.library.is_movie).summary
elif method_name == "tvdb_description":
self.summaries[method_name] = self.config.TVDb.get_list_description(method_data, self.language)
self.summaries[method_name] = self.config.TVDb.get_list_description(method_data)
elif method_name == "trakt_description":
self.summaries[method_name] = self.config.Trakt.list_description(self.config.Trakt.validate_trakt(method_data, self.library.is_movie)[0])
elif method_name == "letterboxd_description":
@ -671,7 +671,7 @@ class CollectionBuilder:
url_slug = self.config.TMDb.get_person(util.regex_first_int(method_data, 'TMDb Person ID')).profile_path
self.posters[method_name] = f"{self.config.TMDb.image_url}{url_slug}"
elif method_name == "tvdb_poster":
self.posters[method_name] = f"{self.config.TVDb.get_item(method_data, self.language, self.library.is_movie).poster_path}"
self.posters[method_name] = f"{self.config.TVDb.get_item(method_data, self.library.is_movie).poster_path}"
elif method_name == "file_poster":
if os.path.exists(method_data):
self.posters[method_name] = os.path.abspath(method_data)
@ -685,7 +685,7 @@ class CollectionBuilder:
url_slug = self.config.TMDb.get_movie_show_or_collection(util.regex_first_int(method_data, 'TMDb ID'), self.library.is_movie).poster_path
self.backgrounds[method_name] = f"{self.config.TMDb.image_url}{url_slug}"
elif method_name == "tvdb_background":
self.posters[method_name] = f"{self.config.TVDb.get_item(method_data, self.language, self.library.is_movie).background_path}"
self.posters[method_name] = f"{self.config.TVDb.get_item(method_data, self.library.is_movie).background_path}"
elif method_name == "file_background":
if os.path.exists(method_data):
self.backgrounds[method_name] = os.path.abspath(method_data)
@ -1041,7 +1041,7 @@ class CollectionBuilder:
values = util.get_list(method_data)
if method_name.endswith("_details"):
if method_name.startswith(("tvdb_movie", "tvdb_show")):
item = self.config.TVDb.get_item(self.language, values[0], method_name.startswith("tvdb_movie"))
item = self.config.TVDb.get_item(values[0], method_name.startswith("tvdb_movie"))
if hasattr(item, "description") and item.description:
self.summaries[method_name] = item.description
if hasattr(item, "background_path") and item.background_path:
@ -1049,7 +1049,7 @@ class CollectionBuilder:
if hasattr(item, "poster_path") and item.poster_path:
self.posters[method_name] = f"{self.config.TMDb.image_url}{item.poster_path}"
elif method_name.startswith("tvdb_list"):
self.summaries[method_name] = self.config.TVDb.get_list_description(values[0], self.language)
self.summaries[method_name] = self.config.TVDb.get_list_description(values[0])
for value in values:
self.builders.append((method_name[:-8] if method_name.endswith("_details") else method_name, value))
@ -1104,7 +1104,7 @@ class CollectionBuilder:
mal_ids = self.config.MyAnimeList.get_mal_ids(method, value)
ids = self.config.Convert.myanimelist_to_ids(mal_ids, self.library)
elif "tvdb" in method:
ids = self.config.TVDb.get_tvdb_ids(method, value, self.language)
ids = self.config.TVDb.get_tvdb_ids(method, value)
elif "imdb" in method:
ids = self.config.IMDb.get_imdb_ids(method, value, self.language)
elif "icheckmovies" in method:
@ -1693,7 +1693,7 @@ class CollectionBuilder:
missing_shows_with_names = []
for missing_id in self.missing_shows:
try:
show = self.config.TVDb.get_series(self.language, missing_id)
show = self.config.TVDb.get_series(missing_id)
except Failed as e:
logger.error(e)
continue
@ -2101,7 +2101,7 @@ class CollectionBuilder:
for missing_id in self.run_again_shows:
if missing_id not in self.library.show_map:
try:
title = self.config.TVDb.get_series(self.language, missing_id).title
title = self.config.TVDb.get_series(missing_id).title
except Failed as e:
logger.error(e)
continue

@ -192,7 +192,8 @@ class Config:
"delete_below_minimum": check_for_attribute(self.data, "delete_below_minimum", parent="settings", var_type="bool", default=False),
"notifiarr_collection_creation": check_for_attribute(self.data, "notifiarr_collection_creation", parent="settings", var_type="bool", default=False),
"notifiarr_collection_addition": check_for_attribute(self.data, "notifiarr_collection_addition", parent="settings", var_type="bool", default=False),
"notifiarr_collection_removing": check_for_attribute(self.data, "notifiarr_collection_removing", parent="settings", var_type="bool", default=False)
"notifiarr_collection_removing": check_for_attribute(self.data, "notifiarr_collection_removing", parent="settings", var_type="bool", default=False),
"tvdb_language": check_for_attribute(self.data, "tvdb_language", parent="settings", default="default")
}
if self.general["cache"]:
util.separator()
@ -304,7 +305,7 @@ class Config:
if self.AniDB is None:
self.AniDB = AniDB(self, None)
self.TVDb = TVDb(self)
self.TVDb = TVDb(self, self.general["tvdb_language"])
self.IMDb = IMDb(self)
self.Convert = Convert(self)
self.AniList = AniList(self)

@ -38,20 +38,18 @@ class TVDbObj:
else:
raise Failed(f"TVDb Error: Could not find a TVDb {self.media_type} ID at the URL {self.tvdb_url}")
def parse_page(xpath, fail=None, multi=False):
def parse_page(xpath):
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
return parse_results[0] if len(parse_results) > 0 else None
self.title = parse_page(f"//div[@class='change_translation_text' and @data-language='{self.language}']/@data-title")
if not self.title:
self.title = parse_page("//div[@class='change_translation_text' and not(@style='display:none')]/@data-title")
if not self.title:
raise Failed(f"TVDb Error: Name not found from TVDb URL: {self.tvdb_url}")
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()]")
@ -84,49 +82,50 @@ class TVDbObj:
self.imdb_id = imdb_id
class TVDb:
def __init__(self, config):
def __init__(self, config, tvdb_language):
self.config = config
self.tvdb_language = tvdb_language
def get_item(self, language, tvdb_url, is_movie):
return self.get_movie(language, tvdb_url) if is_movie else self.get_series(language, tvdb_url)
def get_item(self, tvdb_url, is_movie):
return self.get_movie(tvdb_url) if is_movie else self.get_series(tvdb_url)
def get_series(self, language, tvdb_url):
def get_series(self, tvdb_url):
try:
tvdb_url = f"{urls['series_id']}{int(tvdb_url)}"
except ValueError:
pass
return TVDbObj(tvdb_url, language, False, self.config)
return TVDbObj(tvdb_url, self.tvdb_language, False, self.config)
def get_movie(self, language, tvdb_url):
def get_movie(self, tvdb_url):
try:
tvdb_url = f"{urls['movie_id']}{int(tvdb_url)}"
except ValueError:
pass
return TVDbObj(tvdb_url, language, True, self.config)
return TVDbObj(tvdb_url, self.tvdb_language, True, self.config)
def get_list_description(self, tvdb_url, language):
response = self.config.get_html(tvdb_url, headers=util.header(language))
def get_list_description(self, tvdb_url):
response = self.config.get_html(tvdb_url, headers=util.header(self.tvdb_language))
description = response.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 _ids_from_url(self, tvdb_url, language):
def _ids_from_url(self, tvdb_url):
ids = []
tvdb_url = tvdb_url.strip()
if tvdb_url.startswith((urls["list"], urls["alt_list"])):
try:
response = self.config.get_html(tvdb_url, headers=util.header(language))
response = self.config.get_html(tvdb_url, headers=util.header(self.tvdb_language))
items = response.xpath("//div[@class='col-xs-12 col-sm-12 col-md-8 col-lg-8 col-md-pull-4']/div[@class='row']")
for item in items:
title = item.xpath(".//div[@class='col-xs-12 col-sm-9 mt-2']//a/text()")[0]
item_url = item.xpath(".//div[@class='col-xs-12 col-sm-9 mt-2']//a/@href")[0]
if item_url.startswith("/series/"):
try:
ids.append((self.get_series(language, f"{base_url}{item_url}").id, "tvdb"))
ids.append((self.get_series(f"{base_url}{item_url}").id, "tvdb"))
except Failed as e:
logger.error(f"{e} for series {title}")
elif item_url.startswith("/movies/"):
try:
movie = self.get_movie(language, f"{base_url}{item_url}")
movie = self.get_movie(f"{base_url}{item_url}")
if movie.tmdb_id:
ids.append((movie.tmdb_id, "tmdb"))
elif movie.imdb_id:
@ -145,19 +144,19 @@ class TVDb:
else:
raise Failed(f"TVDb Error: {tvdb_url} must begin with {urls['list']}")
def get_tvdb_ids(self, method, data, language):
def get_tvdb_ids(self, method, data):
if method == "tvdb_show":
logger.info(f"Processing TVDb Show: {data}")
return [(self.get_series(language, data).id, "tvdb")]
return [(self.get_series(data).id, "tvdb")]
elif method == "tvdb_movie":
logger.info(f"Processing TVDb Movie: {data}")
movie = self.get_movie(language, data)
movie = self.get_movie(data)
if movie.tmdb_id:
return [(movie.tmdb_id, "tmdb")]
elif movie.imdb_id:
return [(movie.imdb_id, "imdb")]
elif method == "tvdb_list":
logger.info(f"Processing TVDb List: {data}")
return self._ids_from_url(data, language)
return self._ids_from_url(data)
else:
raise Failed(f"TVDb Error: Method {method} not supported")

@ -109,7 +109,7 @@ def logger_input(prompt, timeout=60):
else: raise SystemError("Input Timeout not supported on this system")
def header(language="en-US,en;q=0.5"):
return {"Accept-Language": language, "User-Agent": "Mozilla/5.0 x64"}
return {"Accept-Language": "eng" if language == "default" else language, "User-Agent": "Mozilla/5.0 x64"}
def alarm_handler(signum, frame):
raise TimeoutExpired

Loading…
Cancel
Save