Fix detect broken api episode endpoint and use fallback.

Fix detect correct old api endpoint pagination and use it.
This commit is contained in:
Prinz23 2023-05-21 17:38:27 +02:00 committed by JackDandy
parent 51d10fc245
commit 2c1c76885a
2 changed files with 29 additions and 6 deletions

View file

@ -25,6 +25,7 @@
* Add menu Shows/"TMDB Cards" * Add menu Shows/"TMDB Cards"
* Add a persons available socials (Youtube, LinkedIn, Reddit, Fansite, TikTok, Wikidata) * Add a persons available socials (Youtube, LinkedIn, Reddit, Fansite, TikTok, Wikidata)
* Change use TVDb genres on view-show if config/General/Interface/"Enable IMDb info" is disabled * Change use TVDb genres on view-show if config/General/Interface/"Enable IMDb info" is disabled
* Fix TVDb api episode issues
* Change remove Python 3.7 from CI * Change remove Python 3.7 from CI

View file

@ -1106,14 +1106,27 @@ class Tvdb(TVInfoBase):
page = 0 # type: int page = 0 # type: int
episodes = [] # type: list episodes = [] # type: list
episode_data_found = False # type: bool episode_data_found = False # type: bool
episode_data_broken = False # type: bool
page_count = 0 # type: int
pages_loaded = 0 # type: int
start_page = 0 # type: int
while page <= 400: while page <= 400:
episode_data = {} episode_data = {}
if self.is_apikey(): if self.is_apikey() and not episode_data_broken:
episode_data = self._getetsrc( episode_data = self._getetsrc(
self.config['url_series_episodes_info'] % (sid, page), language=language) self.config['url_series_episodes_info'] % (sid, page), language=language)
episode_data_found |= 0 == page and bool(episode_data) # fallback to correct old pagination
if 0 == page and None is episode_data:
page = 1
continue
if episode_data:
if 1 == page and not bool(episodes):
start_page = 1
pages_loaded += 1
episode_data_found |= start_page == page and bool(episode_data)
if not episode_data_found and isinstance(show_data, dict) and 'slug' in show_data: if episode_data_broken or \
(not episode_data_found and isinstance(show_data, dict) and 'slug' in show_data):
response = {'data': None} response = {'data': None}
items_found = False items_found = False
# fallback to page 'all' if dvd is enabled and response has no items # fallback to page 'all' if dvd is enabled and response has no items
@ -1176,12 +1189,16 @@ class Tvdb(TVInfoBase):
continue continue
if episode_data_found and not episode_data: if episode_data_found and not episode_data:
if pages_loaded < page_count or 0 == page_count:
episode_data_broken = True
continue
else:
break break
if None is episode_data and not bool(episodes) and not episode_data_found: if None is episode_data and not bool(episodes) and not episode_data_found:
raise TvdbError('Exception retrieving episodes for show') raise TvdbError('Exception retrieving episodes for show')
if isinstance(episode_data, dict) and not episode_data.get('data', []): if isinstance(episode_data, dict) and not episode_data.get('data', []):
if 0 != page: if start_page != page:
self.not_found = False self.not_found = False
break break
if not getattr(self, 'not_found', False) and None is not episode_data.get('data'): if not getattr(self, 'not_found', False) and None is not episode_data.get('data'):
@ -1190,11 +1207,16 @@ class Tvdb(TVInfoBase):
# check if page is a valid following page # check if page is a valid following page
if not isinstance(next_link, integer_types) or next_link <= page: if not isinstance(next_link, integer_types) or next_link <= page:
next_link = None next_link = None
if isinstance(episode_data, dict) and 'links' in episode_data \
and isinstance(episode_data['links'], dict) and 'last' in episode_data['links'] \
and isinstance(episode_data['links']['last'], int) \
and episode_data['links']['last'] > page_count:
page_count = episode_data['links']['last']
if not next_link and isinstance(episode_data, dict) \ if not next_link and isinstance(episode_data, dict) \
and isinstance(episode_data.get('data', []), list) and \ and isinstance(episode_data.get('data', []), list) and \
(100 > len(episode_data.get('data', [])) or episode_data.get('fallback')): (100 > len(episode_data.get('data', [])) or episode_data.get('fallback')):
break break
if next_link: if isinstance(next_link, int) and page + 1 == next_link:
page = next_link page = next_link
else: else:
page += 1 page += 1