Skip to content
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

[Youtube] Got server error HTTP Error 403: Forbidden(latest master version) #32905

Open
6 tasks done
Linux2010 opened this issue Aug 8, 2024 · 105 comments
Open
6 tasks done

Comments

@Linux2010
Copy link

Linux2010 commented Aug 8, 2024

Checklist

  • I'm reporting a broken site support issue
  • I've verified that I'm running youtube-dl version 2024.08.07(the latest master version)
  • I've checked that all provided URLs are alive and playable in a browser
  • I've checked that all URLs and arguments with special characters are properly quoted or escaped
  • I've searched the bugtracker for similar bug reports including closed ones
  • I've read bugs section in FAQ

Verbose log

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['-v']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] youtube-dl version 2024.08.07.local
[debug] Python 3.8.5 (CPython x86_64 64bit) - macOS-10.16-x86_64-i386-64bit - OpenSSL 1.1.1h  22 Sep 2020
[debug] exe versions: ffmpeg 7.0.1-tessus, ffprobe 6.1.1, rtmpdump 2.4
[debug] Proxy map: {'http': 'http://127.0.0.1:58309', 'https': 'http://127.0.0.1:58309'}
Usage: youtube-dl [OPTIONS] URL [URL...]

youtube-dl: error: You must provide at least one URL.
Type youtube-dl --help to see a list of all options.

PASTE VERBOSE LOG HERE

Description

  • The download will run normally for a short time, and then a 403 error will appear
youtube-dl 'https://www.youtube.com/watch?v=lLSkbZ3-EOs'
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 2 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 3 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 4 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 5 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 6 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 7 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 8 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 9 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 41 (attempt 10 of 10)...
[download] Skipping fragment 41...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 42 (attempt 1 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 42 (attempt 2 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 42 (attempt 3 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 42 (attempt 4 of 10)...
@Linux2010 Linux2010 changed the title reoporting bug :Got server HTTP error: HTTP Error 403: Forbidden(the least version) reoporting bug :Got server HTTP error: HTTP Error 403: Forbidden(the latest version) Aug 8, 2024
@Linux2010 Linux2010 changed the title reoporting bug :Got server HTTP error: HTTP Error 403: Forbidden(the latest version) reoporting bug :Got server HTTP error: HTTP Error 403: Forbidden(the latest master version) Aug 8, 2024
@dirkf
Copy link
Contributor

dirkf commented Aug 8, 2024

Indeed this seems to be a pathological video where almost all video formats fail on the first fragment and 299 may fail later, regardless of Python 2.7/3.5/3.9 and User-Agent settings.

yt-dlp 2024.08.06 still works, apparently. It has fancy networking that we can't easily replicate: maybe punt to curl for all requests?

@dirkf dirkf changed the title reoporting bug :Got server HTTP error: HTTP Error 403: Forbidden(the latest master version) [Youtube]: Got server error HTTP Error 403: Forbidden(latest master version) Aug 8, 2024
@dirkf dirkf changed the title [Youtube]: Got server error HTTP Error 403: Forbidden(latest master version) [Youtube] Got server error HTTP Error 403: Forbidden(latest master version) Aug 8, 2024
@tansy
Copy link

tansy commented Aug 8, 2024

I have that with every single video I try. Curiously enough format '18' work all the time. Other formats that work are '136', '137', '248' and/or '160', but it depends on video - not always the case. Still, format '18' is the most reliable to work.

@dirkf
Copy link
Contributor

dirkf commented Aug 8, 2024

So

  1. poToken (I agree, this is always being detected today) randomly breaks the download rather than uniformly giving 403 as with the revised n-sig "throttling"?
  2. different clients get more or less functional links for formats with the same itag?

@GregoriusT
Copy link

Can confirm that a lot of the video-only formats are just being 403-ed in the middle with their downloads, resulting in me getting files that stop after about 10-20 minutes into the video, but still have full sized audio.

By now I have written something into my scripts to just pick format 18 as long as a flag is set, because i foresee this issue happening again in the future once it is eventually fixed... >.>

@dirkf
Copy link
Contributor

dirkf commented Aug 8, 2024

So has anyone tried fetching fragments in fragments of <1MB? We already had a work-around to download in fragments to avoid throttling IIRC.

Otherwise:

  1. actually ignore the data with poToken and use the existing "punt to API" logic with a selected unafflicted client.
  2. extend to user-specified other, or selection of, clients similar to the yt-dlp extractor logic.

@iactix
Copy link

iactix commented Aug 8, 2024

Apparently the latest fix worked for not even a day, that doesn't bode well. Personally I keep getting "giving up after 0 fragment retries" in my python stuff.

From what I read in yesterdays thread, it seems like this will just not work out with fake JS interpretation if they try to combat this in the slightest. Like, that almost doesn't deserve the name attack vector, that's an attack landscape.

@tansy
Copy link

tansy commented Aug 9, 2024

This change is significant. I checked old, pre quantum Firefox and videos don't work any more, when 3 days ago they did.

@dirkf
Copy link
Contributor

dirkf commented Aug 9, 2024

Maybe the new player JS uses some G JS syntax extension (aka ECMA2021+) that hadn't been contemplated in those FF versions. Is there an error in the JS console?

@tansy
Copy link

tansy commented Aug 9, 2024

It used to work as embedded or as mobile (when used mobile user agent). Now all of them display all saying error:

An error occurred. Please try again later. (Playback ID: j-bZsC_YehYVyZZ8)
Learn More (https://support.google.com/youtube/?p=player_error1&hl=en)

Loading any video at https://www.youtube.com/embed/1234567890a:

Content Security Policy: Couldn't process unknown directive 'require-trusted-types-for' <unknown>
mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create www-embed-player.js:26:77
InvalidStateError www-embed-player.js:1128:42

Then pressing play:

Error: WebGL: Error during native OpenGL init. base.js:11283:169
Error: WebGL: WebGL creation failed. base.js:11283:169

ED.

If it's of any help, despite what was said before, there are some videos that work.

First - this one doesn't, and gives following console log

Content Security Policy: Couldn't process unknown directive 'require-trusted-types-for' <unknown>
mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create www-embed-player.js:26:77
InvalidStateError www-embed-player.js:1128:42
Empty string passed to getElementById(). zVhcVoOEv7o line 2 > eval:795:28944

Error: WebGL: getParameter: parameter: invalid enum value <enum 0x9246> base.js:11283:254

This one does and, with this log:

Content Security Policy: Couldn't process unknown directive 'require-trusted-types-for' <unknown>
mutating the [[Prototype]] of an object will cause your code to run very slowly; instead create the object with the correct initial [[Prototype]] value using Object.create www-embed-player.js:26:77
InvalidStateError www-embed-player.js:1128:42
Empty string passed to getElementById(). KAR4fAX5T7Y line 2 > eval:4650:33869

So, after clicking 'play' it gives this error: Error: WebGL: getParameter: parameter: invalid enum value <enum 0x9246> base.js:11283:254.

@TheHolyRoger
Copy link

TheHolyRoger commented Aug 9, 2024

No matter what chunk size I use I'm seeing hard 403 errors at 1Meg as others have reported - I'm able to download as many fragments as I want up to 1Meg and then get a 403.

Have experimented with generating cpns (nonces) and adding them to the format fragment URLs without any luck as well as using rn (request numbers) in the URL query instead of byte ranges. Have tried sleeping between fragments to mimick video playback also without joy.

It feels like they've added a check somewhere which fails at the 1Meg mark but I haven't found anything yet where that might be.

Checking via the browser I can see that youtube is happily downloading /videoplayback fragment URLs above 1Meg without any issue...

@dirkf
Copy link
Contributor

dirkf commented Aug 9, 2024

But in the browser the media links have the pot parameter with its poToken challenge result, no? Which is what we can't haz.

In line with step 1 above, I'm gradually pulling stuff from the yt-dlp extractor, enough to download HLS with client ios, but plainly not yet enough to get unblocked links from tv or web_creator, eg with format 135. Should I be expecting that?

@TheHolyRoger
Copy link

TheHolyRoger commented Aug 9, 2024

But in the browser the media links have the pot parameter with its poToken challenge result, no? Which is what we can't haz.

In line with step 1 above, I'm gradually pulling stuff from the yt-dlp extractor, enough to download HLS with client ios, but plainly not yet enough to get unblocked links from tv or web_creator, eg with format 135. Should I be expecting that?

I'm not seeing a pot parameter in the query strings, I am seeing post data in the /videoplayback requests which is referred to in the source as playbackCookie

Edit: Looks like the playbackCookie / POST data is extracted from the bytes of the previous fragment response somehow

@8chanAnon
Copy link

This is the procedure that I am using in my own code.

Load https://www.youtube.com/embed/<id#> and find the base.js link. Do the usual to extract the sig and n-sig. Extract the signatureTimestamp for the next step.

Load https://www.youtube.com/youtubei/v1/player with the signatureTimestamp and TVHTML5_SIMPLY_EMBEDDED_PLAYER as the client name.

If the JSON response contains "formats" and/or "adaptiveFormats" then we're good. This covers most videos, including age-gated ones. The 403 problem occurs when we have go to the next step. We can't use "www.youtube.com". We must use "m.youtube.com" with the user agent set to something like "Mozilla/5.0 (Android 14)" which is what I'm using.

Load https://m.youtube.com/watch?v=<id#> and extract the JSON structures that you would otherwise have gotten from the previous step.

And that's it. The extra step is only required for videos that disallow embedding.

@dirkf
Copy link
Contributor

dirkf commented Aug 10, 2024

Please don't bother to supply any "me too" reports unless the log shows some novelty that may help with rectification. Just "Like", or whatever, an existing similar report.

You can see how a poToken is being sent in POST data by the browser in the Invidious code that shows how to capture the value. But I understood from yt-dlp discussions that a pot query parameter was used in the media links associated with the pot-ified session.

@8chanAnon's algorithm is what is currently done for age-gate videos, up to the last step with m.youtube.com which is new and interesting. What happens if you skip straight to that step?

Step 2 will only work if TVHTML5_SIMPLY_EMBEDDED_PLAYER is not pot-ified, and that seems to be in question.

@dirkf
Copy link
Contributor

dirkf commented Aug 10, 2024

Indeed, Android 14/FF 122 at m.youtube.com didn't list the poToken experiment IDs although yt-dlp has reported unsuccess with Android clients.

@TheHolyRoger
Copy link

TheHolyRoger commented Aug 10, 2024

I don't think it's worth trying to get around the poToken, it will eventually be required in all clients.

I keep digging into base.js when I get some time trying to understand how the token is created, it does seem to be extracted from the bytes of at least the first video fragment as far as I can tell, but not all fragments?...

There's a Uint8Array which appears to be the fragment response data?... manipulated several times and then 82/84/68 bytes of that array are stored as playbackCookie which is then sent in the POST data

@dirkf
Copy link
Contributor

dirkf commented Aug 10, 2024

At least it would be good to have a program that is not not-youtube-dl while a long term solution to the twattery is being investigated.

@PatrickJRed
Copy link

PatrickJRed commented Aug 10, 2024

@dirkf

yt-dlp 2024.08.06 still works, apparently. It has fancy networking that we can't easily replicate: maybe punt to curl for all requests?

On a lot of websites I want to download from youtube-dl and curl dont even get the correct html,
instead of the one i would get in my Browser , they receives a version that has the captcha.

Instead I have a bash-script that predownloads the non-captcha html via "https://github.com/lwthiker/curl-impersonate" (runs in docker container , i use tag: 0.5.2-ff-alpine)

AFAIK lwthiker/curl-impersonate is the only http client that completly impersonates an actual browser like firefox.
A lot of the problems I had with 403 errors in youtube-dl where captchas triggered by http-client not being exactly like an official version of firefox or chrome :) (this might even be valid for fragment-downloads)

@dirkf
Copy link
Contributor

dirkf commented Aug 10, 2024

Yes, but so far as captcha is generally understood (G/recaptcha, hacaptcha, Cloudflare challenge aka breaks the Web), that is not the problem. Even if it solved the poToken issue, a dependency running under Docker would not be an acceptable solution for the main functionality of the program, though it might be a PoC for a solution.

@TheHolyRoger
Copy link

Yeah not relevant here but I did bookmark it for other things, looks like a decent tool :)

@PatrickJRed
Copy link

I only said that i run it in docker.
Apparently it can be used as a library, see https://github.com/lwthiker/curl-impersonate?tab=readme-ov-file#Advanced-usage .
Though I have not looked into that as I run youtube-dl and almost any other apps via docker anyway :)

@Rekrullurker
Copy link

Well, it was nice while it lasted, but now it's throttled down to a crawl again. :(

@josephecombs
Copy link

josephecombs commented Nov 9, 2024

Adding --user-agent "Mozilla/5.0 (Android 14; Mobile; rv:128.0) Gecko/128.0 Firefox/128.0" worked for me just now on a previously failing

11:18:03 ruby-3.2.2 (master) ~/Dropbox/-> yd https://www.youtube.com/watch?v=cKw_Rjtn3uc
[youtube] cKw_Rjtn3uc: Downloading webpage
[youtube] cKw_Rjtn3uc: Downloading player baafab19
[dashsegments] Total fragments: 1
[download] Destination: Addison Rae - Diet Pepsi (Kastra Remix) _ Lyric Video-cKw_Rjtn3uc.m4a
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 1 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 2 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 3 of 10)...

where my alias yd is

alias yd='cd /Users/myusername/Dropbox/ && youtube-dl -x --audio-quality 0 --audio-format mp3 --user-agent "Mozilla/5.0 (Android 14; Mobile; rv:128.0) Gecko/128.0 Firefox/128.0"'

@umrashrf
Copy link

% youtube-dl -v 'https://www.youtube.com/watch?v=H9FrNLzK_WE'
[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['-v', 'https://www.youtube.com/watch?v=H9FrNLzK_WE']
[debug] Encodings: locale UTF-8, fs utf-8, out utf-8, pref UTF-8
[debug] youtube-dl version 2021.12.17
[debug] Git HEAD: 254bf3fe9d
[debug] Python version 3.12.7 (CPython) - macOS-14.6.1-arm64-arm-64bit
[debug] exe versions: none
[debug] Proxy map: {}
[youtube] H9FrNLzK_WE: Downloading webpage
WARNING: unable to extract uploader id; please report this issue on https://yt-dl.org/bug . Make sure you are using the latest version; see  https://yt-dl.org/update  on how to update. Be sure to call youtube-dl with the --verbose flag and include its complete output.
[debug] Default format spec: best/bestvideo+bestaudio
[debug] Invoking downloader on 'https://rr3---sn-t0aedn7l.googlevideo.com/videoplayback?expire=1732834411&ei=C6BIZ7PDGtbdybgPtJ-j2Qg&ip=2607%3Afa49%3A5742%3A2300%3A476%3A2fb1%3Ab8d7%3Ad61&id=o-AOkZjgb1dzkTyOPBDKo8oInLci42ttpNLSElS_NhMyPI&itag=18&source=youtube&requiressl=yes&xpc=EgVo2aDSNQ%3D%3D&met=1732812811%2C&mh=55&mm=31%2C29&mn=sn-t0aedn7l%2Csn-t0aekn7e&ms=au%2Crdu&mv=m&mvi=3&pl=40&rms=au%2Cau&initcwndbps=1460000&bui=AQn3pFT1TFynKpG2CnhOIXdwfZul4FSpPW7bbhM82STpcKAghKYFBQRzkp8avO_5ANpCRRzCEea1WoS8&spc=qtApASOyRgAezGj6GVdKg6vLgarZd9eUWee6RQ8T9WG1-QzDgjBnM9YysM7WlYc&vprv=1&svpuc=1&mime=video%2Fmp4&ns=5SgaM_LqEQXLSxvJv4w4VNoQ&rqh=1&gir=yes&clen=110270895&ratebypass=yes&dur=1420.968&lmt=1732325389520475&mt=1732812319&fvip=2&fexp=51326932%2C51335594&c=WEB&sefc=1&txp=5538434&n=D1oF9sMbE9u4Ls_l5EW&sparams=expire%2Cei%2Cip%2Cid%2Citag%2Csource%2Crequiressl%2Cxpc%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Cgir%2Cclen%2Cratebypass%2Cdur%2Clmt&sig=AJfQdSswRAIgXMxQE8XpsYWWdGUdQinMi--2O3dtEaQqqFIb49f3GjoCIFW6_4CMK3SISuymlGZSpEv_ehqzbgxEUq7xaHO-j0os&lsparams=met%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Crms%2Cinitcwndbps&lsig=AGluJ3MwRQIhAP37774uoPHg9nY6PZsS1q6E8TyHhGsz85338O8_o3F5AiB_OFeIsgQus4OjgDpP5RHL29ORLqyWpURWPY51l9LNsg%3D%3D'
ERROR: unable to download video data: HTTP Error 403: Forbidden
Traceback (most recent call last):
  File "/opt/homebrew/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.12/site-packages/youtube_dl/YoutubeDL.py", line 1976, in process_info
    success = dl(filename, info_dict)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.12/site-packages/youtube_dl/YoutubeDL.py", line 1915, in dl
    return fd.download(name, info)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.12/site-packages/youtube_dl/downloader/common.py", line 366, in download
    return self.real_download(filename, info_dict)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.12/site-packages/youtube_dl/downloader/http.py", line 351, in real_download
    establish_connection()
  File "/opt/homebrew/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.12/site-packages/youtube_dl/downloader/http.py", line 116, in establish_connection
    raise err
  File "/opt/homebrew/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.12/site-packages/youtube_dl/downloader/http.py", line 110, in establish_connection
    ctx.data = self.ydl.urlopen(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/youtube-dl/2021.12.17/libexec/lib/python3.12/site-packages/youtube_dl/YoutubeDL.py", line 2288, in urlopen
    return self._opener.open(req, timeout=self._socket_timeout)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 521, in open
    response = meth(req, response)
               ^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 630, in http_response
    response = self.parent.error(
               ^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 559, in error
    return self._call_chain(*args)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 492, in _call_chain
    result = func(*args)
             ^^^^^^^^^^^
  File "/opt/homebrew/Cellar/[email protected]/3.12.7_1/Frameworks/Python.framework/Versions/3.12/lib/python3.12/urllib/request.py", line 639, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 403: Forbidden

Same error with different flags like:

youtube-dl -v --user-agent "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.103 Mobile Safari/537.36" 'https://www.youtube.com/watch?v=H9FrNLzK_WE'

OR

youtube-dl -v -f mp4 --user-agent "Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.6533.103 Mobile Safari/537.36" 'https://www.youtube.com/watch?v=H9FrNLzK_WE'

@dirkf
Copy link
Contributor

dirkf commented Nov 28, 2024

  1. There's no point showing logs for the known problem.
  2. Point 3 above probably applies.
  3. Consider trying the UA that was found to work above.

@gleeglee217
Copy link

I have installed ffmpeg (6/20/2018) in Winds11 "Edit the sys environment variables" in "Environment variables" then "Path" then "edit" then added the last two as pictured. (youtube-dl.exe ver 2024.8.7 nightly build).
Screenshot 2024-11-28 121243

Now I am trying to only get mp3 files from YT and here is a screenshot of what issues I have in Windows Power Shell
win power shell

@dirkf
Copy link
Contributor

dirkf commented Nov 28, 2024

  1. When posting a log, please paste it as text rather than a screenshot and use the verbose option (--verbose/-v).
  2. As you apparently (but we can't be sure, because of the non-verbose log) haven't applied any of the work-arounds suggested above in the issue, the failure that you got was expected and so point 1 of my previous comment applies.
  3. You haven't reached the point where ffmpeg would be used but your PATH setting looks plausible as far as I can recall: if you should have a problem where yt-dl doesn't find ffmpeg you can specify the program or its (binary) directory using an option, and that option could be included in a user or system config file.
  4. Similarly, mp3 extraction is not relevant to the problem.
  5. Review the issue comments and apply the suggested work-arounds.

@Rekrullurker

This comment was marked as off-topic.

@Rekrullurker

This comment was marked as off-topic.

@nicolaasjan

This comment was marked as off-topic.

@Rekrullurker

This comment was marked as resolved.

@nicolaasjan

This comment was marked as off-topic.

@Rekrullurker
Copy link

Thank, that build worked great.

@dirkf
Copy link
Contributor

dirkf commented Dec 11, 2024

I've been using the UserAgent workaround for about a month now. Up until the last couple of days, it was working great. Now it seems to fail about 80-90% of the time, giving me multiple 403 errors. ...

Probably you were seeing the roll-out of the player JS as reported in #32986, with success depending on whether your request went to a server that was still sending the previous player.

@Rekrullurker
Copy link

Oops, I spoke too soon. It worked fine in my two quick tests, as well as a video I downloaded later, now it's back to giving me 403 errors.

@dirkf
Copy link
Contributor

dirkf commented Dec 11, 2024

Are you using the mobile UA option? If so, pls post verbose log.

@Rekrullurker
Copy link

Yes, I am. After some more testing, it seems it only fails on some videos. Here is the log from one such failure;

[debug] System config: []
[debug] User config: []
[debug] Custom config: []
[debug] Command-line args: ['--verbose', '--user-agent', 'Mozilla/5.0 (Android 14; Mobile; rv:128.0) Gecko/128.0 Firefox/128.0', 'https://www.youtube.com/watch?v=ZbelsTTZ0QE']
[debug] Encodings: locale cp1252, fs mbcs, out cp1252, pref cp1252
[debug] youtube-dl version 2024.12.10
[debug] Lazy loading extractors enabled
[debug] Single file build
[debug] Python 3.4.4 (CPython x86 32bit) - Windows-XP-5.1.2600-SP3 - OpenSSL 1.0.2d 9 Jul 2015
[debug] exe versions: ffmpeg N-105053-gc417616-Reino
[debug] Proxy map: {}
[youtube] ZbelsTTZ0QE: Downloading webpage
[debug] [youtube] Decrypted nsig J2T7YI_FVNuB1rbFlt => Pv42zso-RjFDsg
[debug] [youtube] Decrypted nsig nxJfsEvTaEBBjAFmdI => WmC7NoLmA6NMKg
[youtube] ZbelsTTZ0QE: Downloading API JSON
[debug] Default format spec: bestvideo+bestaudio/best
WARNING: Requested formats are incompatible for merge and will be merged into mkv.
[debug] Invoking downloader on 'https://rr1---sn-j5caxoxu-i2oe.googlevideo.com/videoplayback?clen=197680715&mm=31%2C29&expire=1733936581&n=WmC7NoLmA6NMKg&fexp=51326932%2C51331020%2C51335594%2C51347747&initcwndbps=4651250&aitags=133%2C134%2C135%2C136%2C137%2C160%2C242%2C243%2C244%2C247%2C248%2C278%2C394%2C395%2C396%2C397%2C398%2C399%2C597%2C598&xpc=EgVo2aDSNQ%3D%3D&svpuc=1&lmt=1705760126895911&sparams=expire%2Cei%2Cip%2Cid%2Caitags%2Csource%2Crequiressl%2Cxpc%2Cbui%2Cspc%2Cvprv%2Csvpuc%2Cmime%2Cns%2Crqh%2Cgir%2Cclen%2Cdur%2Clmt&fvip=3&spc=qtApAWdjprjT_XTFriEtZsm8lM2XNY_MngwQu6j_huq5MxvrU1ugSI3vLzFU6lXmSA&ei=ZXFZZ-PPKqy2kucPmIHVsQM&bui=AQn3pFRXKOA5CW96qDyDVdV3dApfkc7mOlIbyA7j1nTYH8ijcsOLxdF9T36pQPhmbz82eMcPRxZHpmQh&itag=137&source=youtube&mime=video%2Fmp4&rms=au%2Cau&c=MWEB&ms=au%2Crdu&txp=5432434&ip=24.44.111.244&rqh=1&requiressl=yes&vprv=1&mt=1733914628&lsparams=met%2Cmh%2Cmm%2Cmn%2Cms%2Cmv%2Cmvi%2Cpl%2Crms%2Cinitcwndbps&dur=1500.766&sefc=1&mh=HJ&pl=22&ns=zaPT_foz9hIdg3hYUktMjtUQ&sig=AJfQdSswRQIgVQQuKslmNCAToTk32xo0BhhmykeTM9Hc224RFz8FguICIQCT9_lCgewMeljrIwTyxFkRH51YFwLaQhQo_eKtydbDfg%3D%3D&mvi=1&id=o-APJn1Cpo42KU0qexogywzXvkNWrnrhR-PjkDm8NlWR6q&met=1733914981%2C&mn=sn-j5caxoxu-i2oe%2Csn-ab5sznzs&keepalive=yes&lsig=AGluJ3MwRQIhAIJ2A-jh_4ASdk4JS9Yr-iMpNb0L1xPnd6WhAEHpTYqzAiBf7l6LEsMycV_iNln99MBXRFPRB-6s9u5YBbLko703Sw%3D%3D&gir=yes&mv=m'
[dashsegments] Total fragments: 19
[download] Destination: Top 20 Gorgeous Adult & Violent Classic Anime That Are Beyond Awesome - Explored-ZbelsTTZ0QE.f137.mp4
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 1 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 2 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 3 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 4 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 5 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 6 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 7 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 8 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 9 of 10)...
[download] Got server HTTP error: HTTP Error 403: Forbidden. Retrying fragment 1 (attempt 10 of 10)...
ERROR: giving up after 10 fragment retries
File "main.py", line 19, in
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl_init_.py", line 477, in main
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl_init_.py", line 467, in _real_main
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 2254, in download
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 868, in extract_info
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 875, in wrapper
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 982, in __extract_info
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 1016, in process_ie_result
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 1860, in process_video_result
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 138, in wrapper
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 2152, in process_info
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 2088, in dl
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\downloader\common.py", line 380, in download
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\downloader\dash.py", line 78, in real_download
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\downloader\common.py", line 175, in report_error
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 678, in report_error
File "C:\Users\nico\Desktop\youtube-dl_source\youtube_dl\YoutubeDL.py", line 630, in trouble

@dirkf
Copy link
Contributor

dirkf commented Dec 13, 2024

It seems that the mobile UA work-around is failing now, though yt-dlp (2024-12-06) is able to pull the same listed formats. Testing video lLSkbZ3-EOs, I found format 18 was downloadable with the PR #32987 code, but I think there some videos that don't have this not-really-suitable-for-a-55"-TV format.

At a guess, the other formats are no longer accessible in the mobile page, or the UA isn't causing redirection: if they were found in the API JSON they would be listed but not downloadable because of not using sts, as noted above. More investigation needed, but it shouldn't de-rail the rewrite when I have time to get back to it.

@Rekrullurker
Copy link

When I use the mobile UA, it lists all the formats, it just won't download them.

@dirkf
Copy link
Contributor

dirkf commented Dec 13, 2024

Exactly, that's why I suspect it's trying to use the links from the API JSON which, as I was surprised to discover and noted above, haven't worked for years, except for the newer but also now probably ineffective age-gate code; tests didn't reveal that because links from the webpage were normally found and used.

If format 18 is being shown, try that.

@dirkf
Copy link
Contributor

dirkf commented Dec 13, 2024

Testing shows that the DASH formats from the mobile web client are failing, regardless of their origin. The same formats extracted by yt-dlp stable are OK, in a test setup using ffmpeg as downloader in each case.

The test code is #32987

adapted to use the player_response from an API call using MWEB client

            ...
            origin = 'https://m.youtube.com'
            pb_context = {'html5Preference': 'HTML5_PREF_WANTS'}

            player_url = self._extract_player_url(webpage)
            ytcfg = self._extract_ytcfg(video_id, webpage)
            sts = self._extract_signature_timestamp(video_id, player_url, ytcfg)
            if sts:
                pb_context['signatureTimestamp'] = sts

            query = {
                'playbackContext': {
                    'contentPlaybackContext': pb_context,
                    'contentCheckOk': True,
                    'racyCheckOk': True,
                },
                'context': {
                    'client': {
                        'clientName': 'MWEB',
                        'clientVersion': '2.20240726.01.00',
                        'hl': 'en',
                    },
                },
                'videoId': video_id,
            }
            headers = {
                'X-YouTube-Client-Name': '2',
                'X-YouTube-Client-Version': '2.0',
                'Origin': origin,
            }

            auth = self._generate_sapisidhash_header(origin)
            if auth is not None:
                headers['Authorization'] = auth
                headers['X-Origin'] = origin

            player_response = self._call_api('player', query, video_id, fatal=False, headers=headers)
            ...

These things are not enough to avoid 403 with #32987 adapted to use the player_response from an API call using MWEB client:

  • same UA in download
  • Sec-Fetch-Mode: navigate in download headers.

In at least one case the failing media URL had a spc query param not present in the successful media URL while lsig was present in the successful URL and not in the failing one, with other query params the same (not all the same values, because times and nsigs, etc, change)

@dirkf
Copy link
Contributor

dirkf commented Dec 14, 2024

Apparently the client parameters, including UA, need to be just right.

A temporary fix (that worked today)is included in PR #32987.

@dirkf
Copy link
Contributor

dirkf commented Dec 17, 2024

Please try https://github.com/ytdl-org/ytdl-nightly/releases/tag/2024.12.17 to resolve this issue for now.

ledav-net added a commit to ledav-net/youtube-mp3 that referenced this issue Dec 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests