Skip to content

Commit

Permalink
Update error checks to avoid unnecessary retries of player request
Browse files Browse the repository at this point in the history
  • Loading branch information
MoojMidge committed Apr 17, 2024
1 parent 762a2d3 commit 5ab565d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions resources/lib/youtube_plugin/youtube/helper/video_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,11 @@ def _get_video_info(self):
client_name = reason = status = None
client = playability_status = result = None

reasons = (
self._context.localize(574, 'country').lower(),
self._context.localize(10005, 'not available').lower(),
)

client_data = {'json': {'videoId': video_id}}
if self._access_token:
client_data['_access_token'] = self._access_token
Expand Down Expand Up @@ -1188,14 +1193,18 @@ def _get_video_info(self):
# Geo-blocked video with error reasons like:
# "This video contains content from XXX, who has blocked it in your country on copyright grounds"
# "The uploader has not made this video available in your country"
if status == 'UNPLAYABLE' and 'country' in reason:
# Reason language will vary based on Accept-Language and
# client hl, Kodi localised language is used for comparison
# but may not match reason language
if (status == 'UNPLAYABLE'
and any(why in reason for why in reasons)):
break
if status != 'ERROR':
continue
# This is used to check for error like:
# "The following content is not available on this app."
# Text will vary depending on Accept-Language and client hl
# YouTube support url is checked instead
# Reason language will vary based on Accept-Language and
# client hl, so YouTube support url is checked instead
url = self._get_error_details(
playability_status,
details=(
Expand All @@ -1211,9 +1220,9 @@ def _get_video_info(self):
if url and url.startswith('//support.google.com/youtube/answer/12318250'):
status = 'CONTENT_NOT_AVAILABLE_IN_THIS_APP'
continue
if video_id != video_details.get('videoId'):
if video_details and video_id != video_details.get('videoId'):
status = 'CONTENT_NOT_AVAILABLE_IN_THIS_APP'
reason = 'WATCH_ON_LATEST_VERSION_OF_YOUTUBE'
reason = 'Watch on the latest version of YouTube'
continue
break
# Only attempt to remove Authorization header if clients iterable
Expand Down

0 comments on commit 5ab565d

Please sign in to comment.