mirror of
https://github.com/soimort/you-get.git
synced 2025-02-02 16:24:00 +03:00
Add ytInitialPlayerResponse checker to let user easily know problem
This commit is contained in:
parent
899e2b6b2b
commit
4ab02216cd
@ -175,6 +175,16 @@ class YouTube(VideoExtractor):
|
|||||||
pass
|
pass
|
||||||
# FIXME: show DASH stream sizes (by default) for playlist videos
|
# FIXME: show DASH stream sizes (by default) for playlist videos
|
||||||
|
|
||||||
|
def check_playability_response(self, ytInitialPlayerResponse):
|
||||||
|
STATUS_OK = "OK"
|
||||||
|
|
||||||
|
playerResponseStatus = ytInitialPlayerResponse["playabilityStatus"]["status"]
|
||||||
|
if playerResponseStatus != STATUS_OK:
|
||||||
|
reason = ytInitialPlayerResponse["playabilityStatus"].get("reason", "")
|
||||||
|
raise AssertionError(
|
||||||
|
f"Server refused to provide video details. Returned status: {playerResponseStatus}, reason: {reason}."
|
||||||
|
)
|
||||||
|
|
||||||
def prepare(self, **kwargs):
|
def prepare(self, **kwargs):
|
||||||
assert self.url or self.vid
|
assert self.url or self.vid
|
||||||
|
|
||||||
@ -202,6 +212,7 @@ class YouTube(VideoExtractor):
|
|||||||
|
|
||||||
logging.debug('Loading ytInitialPlayerResponse...')
|
logging.debug('Loading ytInitialPlayerResponse...')
|
||||||
ytInitialPlayerResponse = json.loads(re.search('ytInitialPlayerResponse\s*=\s*([^\n]+?});(\n|</script>|var )', video_page).group(1))
|
ytInitialPlayerResponse = json.loads(re.search('ytInitialPlayerResponse\s*=\s*([^\n]+?});(\n|</script>|var )', video_page).group(1))
|
||||||
|
self.check_playability_response(ytInitialPlayerResponse)
|
||||||
|
|
||||||
# Get the video title
|
# Get the video title
|
||||||
self.title = ytInitialPlayerResponse["videoDetails"]["title"]
|
self.title = ytInitialPlayerResponse["videoDetails"]["title"]
|
||||||
|
Loading…
Reference in New Issue
Block a user