[youtube] fix reason

This commit is contained in:
Mort Yao 2024-10-28 17:29:05 +01:00
parent 5b4142dc4a
commit ab9a9785c0
No known key found for this signature in database
GPG Key ID: 07DA00CB78203251

View File

@ -188,10 +188,17 @@ class YouTube(VideoExtractor):
playerResponseStatus = ytInitialPlayerResponse["playabilityStatus"]["status"] playerResponseStatus = ytInitialPlayerResponse["playabilityStatus"]["status"]
if playerResponseStatus != STATUS_OK: if playerResponseStatus != STATUS_OK:
try:
reason = ytInitialPlayerResponse["playabilityStatus"]['errorScreen']\
['playerErrorMessageRenderer']['reason']['runs'][0]['text']
reason += ' ' + ytInitialPlayerResponse["playabilityStatus"]['errorScreen']\
['playerErrorMessageRenderer']['subreason']['runs'][0]['text']
except:
reason = ytInitialPlayerResponse["playabilityStatus"].get("reason", "") reason = ytInitialPlayerResponse["playabilityStatus"].get("reason", "")
raise AssertionError( if reason:
f"Server refused to provide video details. Returned status: {playerResponseStatus}, reason: {reason}." log.wtf(f'Server refused to provide video details. Returned status: {playerResponseStatus}. Reason: {reason}')
) else:
log.wtf(f'Server refused to provide video details. Returned status: {playerResponseStatus}.')
def prepare(self, **kwargs): def prepare(self, **kwargs):
self.ua = 'Mozilla/5.0 (Linux; Android 15) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.73 Mobile Safari/537.36' self.ua = 'Mozilla/5.0 (Linux; Android 15) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.6723.73 Mobile Safari/537.36'