-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1060 #1067
Fix #1060 #1067
Conversation
Why do you change "player_response" to something else? Is this really necessary? This will break downstream projects. |
I did so because the old endpoint doesn't work anymore and the JSON output of the new endpoint has a new key name. Which is Quick check:
curl "https://www.youtube.com/youtubei/v1/player" -H 'X-Goog-Api-Key: AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' -H "Content-Type: application/json" -X POST -d '{"context":{"client":{"clientName":"ANDROID","clientVersion":"16.05"}},"videoId":"9bZkp7q19f0"}' | jq .player_response
curl "https://www.youtube.com/youtubei/v1/player" -H 'X-Goog-Api-Key: AIzaSyAO_FJ2SlqU8Q4STEHLGCilw_Y9_11qcW8' -H "Content-Type: application/json" -X POST -d '{"context":{"client":{"clientName":"ANDROID","clientVersion":"16.05"}},"videoId":"9bZkp7q19f0"}' | jq .responseContext |
It turns out that local class method |
@glubsy I got your point. I decided to alterate the new endpoint output to ensure backward compatibility. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm
I've been wanting to swap over to using innertube exclusively for months now (see: #1022, #994), however I keep running into the same issue which is why I haven't made the jump yet, and that's still applicable here. Innertube can't seem to bypass any age-restrictions on videos. If you test this code against this video, you'll see the problem |
Changed variable name to avoid conflict with method name
I made one minor change to your code, and added some stuff to innertube. Doesn't seem to fix the problem for age-gated videos though. |
…cess_token as Bearer Authorization header. Need to investigate more.
I need to sleep -- the oauth flow almost works. It seems to correctly get an I've been using video id from pytube.innertube import InnerTube
video_id = 'DkffTDkSADI'
i = InnerTube(use_oauth=True, allow_cache=True)
i.player(video_id) |
It looks like other project got the same issue (see ytdl-org/youtube-dl#29086 ) and didn't found workaround yet. Nice work for the oAuth. The 400 error says : {
"error": {
"code": 400,
"message": "The API Key and the authentication credential are from different projects.",
"errors": [
{
"message": "The API Key and the authentication credential are from different projects.",
"domain": "global",
"reason": "badRequest"
}
],
"status": "INVALID_ARGUMENT"
}
} Note that your oAuth implementation works with a non restricted video. I don't think there is a "good" workaround to bypass that. We can either ask the user to provide an account with API key, or register an account for pytube that might be ban. Since the whole project is broken for now, maybe should you release the fix (without oAuth ?) and open a new issue for age restricted video ? |
Ty for providing the output of that 400 error, it was getting too late for me to investigate further last night, but it made it much easier to debug this morning. I got OAuth working, just need to incorporate it into the main part of the library now. |
I'm working on carving out some of the old code now that we're accessing very differently-formatted data, it's being finnicky about though. Hopefully will have an update this evening. |
Running into a 403 error on age-restricted videos that still needs solving. Normal videos seem to work though currently. |
Your fix works on my computer. However, I encounter a 403 error for a video that has no age restriction: from pytube import YouTube
yt = YouTube('http://youtube.com/watch?v=_Tr1lrd4co0')
yt.streams.filter(progressive=True, file_extension='mp4').first().download() Error:
|
I've set this branch to default to the android client, in spite of the fact that we do lose some stream types as a result. Worth testing to see if there are any further 403 errors, but in my very brief testing I couldn't produce any. I've also bundled some miscellaneous bugfixes for other issues and linked them into this. W/r/t signature calculation, I'm seeing something a little unusual in how signatures are being calculated:
It looks like the calculation is incomplete, and I'm unsure why that is. When looking at dev tools in Chrome, the signature for the video typically resembles a b64-encoded string, with the |
Hopefully not off-topic, since I saw that age-gating is a problem in this PR I would like to point to the new bypass method: yt-dlp/yt-dlp#574 (comment) which should have the same success rate as the old method |
Same for me, nice job 👍🏻 . Do you have a video sample where the signature is not already provided ? |
Definitely not off-topic, thanks for the tip! I've incorporated that bypass into this patch. Pytube will default to the normal android client. If it fails to retrieve the stream data, it will attempt to fall back to using that bypass instead. The videos that I've been testing against seem to work correctly for me, but would appreciate some additional testing. I'm going to note once again so it doesn't get lost: |
pytube/__main__.py
Outdated
|
||
# If we still can't access the video, raise an exception | ||
# (tier 3 age restriction) | ||
if playability_status == 'LOGIN_REQUIRED': |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: Tier 3 videos will return an UNPLAYABLE
status on embed clients instead (as they're likely just videos with embed disabled by creator)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
I have been doing some silly tests today with the fixes in this branch, and I ran into an error when trying to retrieve the captions of a video:
I'm not sure if this error arose with this fix. |
Looking into a fix for this now. I think sometimes caption details return in two different formats, not sure what causes it. |
With your commit, I can now download XML captions, however, conversion to SRT fails. By exploring the XML files and reading the <?xml version="1.0" encoding="utf-8" ?><timedtext format="3">
<body>
<p t="2254" d="2872">FRIDAY</p>
<p t="33434" d="1193">IT IS TIME FOR THE BOYS</p>
</body>
</timedtext> So now, the root element |
It looks like this is inconsistent between auto-generated and user-provided captions. I'll work on a fix for captions as a separate PR, rather than trying to fix that in this one. |
Now that tests have been fixed, I'm going to merge this and get pypi updated. |
Pypi should be updated. |
Here is a proposition for #1060 . The commit name says "#1342" because I was thinking about spotDL/spotify-downloader#1342 (which is the same issue) while fixing the bug.