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 403 forbidden error on audio urls #32882

Closed
3 tasks done
ReenigneArcher opened this issue Jul 26, 2024 · 20 comments
Closed
3 tasks done

YouTube 403 forbidden error on audio urls #32882

ReenigneArcher opened this issue Jul 26, 2024 · 20 comments
Labels

Comments

@ReenigneArcher
Copy link
Contributor

Checklist

  • I'm asking a question
  • I've looked through the README and FAQ for similar questions
  • I've searched the bugtracker for similar questions including closed ones

Question

Did something change in the YouTube audio formats, or are they returned differently than before? After merging e1b3fa2 into my codebase, I am getting (somewhat) random failures, but still very repeatable. I wasn't getting these errors with the previous version of ytdl, but there was a new error (#32842 (comment)) so had to update.

Plex is giving me 406 (unacceptable) errors when I try to upload the audio.

2024-07-26 20:31:01,164 (1e38) :  ERROR (logkit:22) - 7: Error uploading media: (406) not_acceptable; http://127.0.0.1:32400/library/metadata/7/themes?url=https%3A%2F%2Frr2---sn-vgqsknll.googlevideo.com%2Fvideoplayback%3Fsparams%3Dexpire%252Cei%252Cip%252Cid%252Citag%252Csource%252Crequiressl%252Cxpc%252Cbui%252Cspc%252Cvprv%252Csvpuc%252Cmime%252Cns%252Crqh%252Cgir%252Cclen%252Cdur%252Clmt%26ei%3DdwekZoOfFMiL2_gPr9aZ8QY%26ip%3D<ip_address>%26clen%3D2952380%26spc%3DNO7bAUSfQKp7wA51RtQGKsRLBRf5mthsur--MRW5fbsriZPkNA1qre4UysJp%26id%3Do-AAoY5UDjTl1nbz2ILx_0-6f07PC6a8wTiWVAlOzqqb7U%26keepalive%3Dyes%26svpuc%3D1%26gir%3Dyes%26xpc%3DEgVo2aDSNQ%253D%253D%26requiressl%3Dyes%26source%3Dyoutube%26mv%3Du%26sig%3DAJfQdSswRQIhAMf8bjXRaGzgiRSBkOqQ_D39zP9NvzqawnrrT5DUi7FiAiB5sA67GgEuGddyT9dBkO93JerPVjcdWgiGzv499zHq4A%253D%253D%26dur%3D185.852%26ns%3DsfVMzFqD1xnov-0SyNvSksYQ%26vprv%3D1%26lsig%3DAGtxev0wRQIhALDSyv0QtzedMTElYBf8wrYFLVu9AVKMUkS73YdG0JmCAiB1MAf-1V11K54VOSB7cgbzRiqKJlpJmgEwfMoqD0sIog%253D%253D%26lsparams%3Dmh%252Cmm%252Cmn%252Cms%252Cmv%252Cmvi%252Cpl%26lmt%3D1381172018924357%26c%3DWEB%26sefc%3D1%26expire%3D1722047447%26mime%3Daudio%252Fmp4%26fvip%3D1%26rqh%3D1%26itag%3D140%26mm%3D31%252C29%26mn%3Dsn-vgqsknll%252Csn-vgqsrnsr%26mh%3DRH%26n%3DByy7QEICFdfW5A%26mt%3D1722025513%26bui%3DAXc671J3DF8IaVyrVeX7P2gjoWIta83r8-VJE-frLLoYb-Qu34nQWYMq_tCvsDUUawSv_qeOTvQLUkSo%26pl%3D23%26ms%3Dau%252Crdu%26mvi%3D2 <html><head><title>Not Acceptable</title></head><body><h1>406 Not Acceptable</h1></body></html>

Here is my code for getting the audio url: https://github.com/LizardByte/Themerr-plex/blob/c948caa73991e05cebe8b24b88bce5ccb6bede4c/Contents/Code/youtube_dl_helper.py#L133-L161

I tested locally, and I'm still getting audio urls, but could be in formats that aren't supported by Plex. Last update for Plex was July 9th, so nothing on their end changed in the last few days.

Any ideas?

@ReenigneArcher
Copy link
Contributor Author

ReenigneArcher commented Jul 27, 2024

I dug a little deeper and the issue is that the url provided by youtube-dl is not accessible and gives a 403 error. This seems to be very random.

https://github.com/LizardByte/Themerr-plex/actions/runs/10119441078/job/27987941216?pr=486#step:8:276

This seems like a new development since the commit I linked above. Could youtube-dl validate that the url it gives is accessible before returning it? Possibly with some retry logic? I guess it may be too complex to validate all the format URLs.

@aiur-adept
Copy link
Contributor

Could you post the original youtube url you're fetching so we could see what youtube-dl is returning/do some debugger-work?

@ReenigneArcher
Copy link
Contributor Author

ReenigneArcher commented Jul 27, 2024

@aiur-adept sure, it can occur on seemingly any video. Here's two examples:

It seems like there is some kind of rate limiting happening, because if I try again in a little bit it will work.

I guess these might be related:

@ReenigneArcher ReenigneArcher changed the title YouTube audio formats changed? YouTube 403 forbidden error on audio urls Jul 27, 2024
@aiur-adept
Copy link
Contributor

Ah yeah, I've just seen the behaviour. It failed with 403 then after about 10 minutes it worked. Weird that they're sending a 403 when it's likely a rate limit. I'm not sure how to solve this as having the process wait for 10 minutes on a 403 isn't really a good solution.

@dirkf
Copy link
Contributor

dirkf commented Jul 27, 2024

If you are post-processing the download URLs, you could try using the equivalent back-up URL (specified in its query parameters) on unexpected 403, or 4xx generally. This has so far been deemed too hard in yt-dl[p], as it would need a custom downloader; also AFAIK no-one has conclusively shown that the backup URL work better than the original one.

The algorithm for generating the backup URL is in an old issue (also at yt-dlp) which I expect I can find if you can't.

@ReenigneArcher
Copy link
Contributor Author

ReenigneArcher commented Jul 27, 2024

I tried a small retry loop in my code as well, and it might have helped... still testing though.

I also tried not using a cookie file after seeing this: yt-dlp/yt-dlp#10046 ... that also may have helped... still testing that too.

Weird that they're sending a 403 when it's likely a rate limit.

From what I can see this is kind of standard for google products.

@dirkf, I am not using youtube-dl to do the downloading, and I'm handling that on my own. I did see this yt-dlp/yt-dlp#4100 (comment) I'm not sure I 100% understand though.

@aiur-adept
Copy link
Contributor

@dirkf @ReenigneArcher should we close this issue?

@ReenigneArcher
Copy link
Contributor Author

What's the algorithm for generating the backup url?

@dirkf
Copy link
Contributor

dirkf commented Jul 29, 2024

Probably this PR is the best source.

@ReenigneArcher
Copy link
Contributor Author

No luck: LizardByte/Themerr-plex@81df3d2

@ginahoy

This comment was marked as off-topic.

@tansy

This comment was marked as resolved.

@JstaClarkey
Copy link

I found that the issue was at least partially because of m4a chosen as the best audio format. If I force it with 'bestaudio[ext=webm]' then previously 403 error'd URLs download with no issues. Still not a good solution because there's a few URLs with no webm format.

@ReenigneArcher
Copy link
Contributor Author

@JstaClarkey thank you for that information. I'm also using m4a. I guess I will need to incorporate ffmpeg to solve this.

@seproDev
Copy link

seproDev commented Aug 2, 2024

This very much looks like the poToken experiment.
yt-dlp solved this by retrying the web api when the experiment is detected, since rollout is not yet at 100%.
In addition, yt-dlp switched away from the web client. As afaik. youtube-dl only support the web client, this will be more difficult to backport.

@dirkf
Copy link
Contributor

dirkf commented Aug 2, 2024

Yes, I've made a WIP that tests for poToken and so it could be made to retry.

The multiple client thing is conceptually straightforward (ie, instead of a single result to be traversed there is a list of results) but also brings in some related catch-up issues like extractor args.

@ReenigneArcher
Copy link
Contributor Author

@dirkf I'll be happy to test when it's ready. My CI tests about 30 videos, so it's pretty easy to hit this error.

@dirkf
Copy link
Contributor

dirkf commented Aug 3, 2024

My initial testing gives somewhat strange results. Getting the title from each item in a playlist brings up the poToken warning quite regularly. Downloading item 1 of the list works fine regardless of whether the warning appears.

Similar results with the two videos above.

@ReenigneArcher
Copy link
Contributor Author

Do you have a live branch for this?

@dirkf
Copy link
Contributor

dirkf commented Aug 9, 2024

Continued in #32905.

@dirkf dirkf closed this as not planned Won't fix, can't repro, duplicate, stale Aug 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants