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

Prevent YouTube throttling #2222

Closed
wants to merge 2 commits into from
Closed

Prevent YouTube throttling #2222

wants to merge 2 commits into from

Conversation

putara
Copy link

@putara putara commented Jun 28, 2021

Hi there, I'm trying to fix #2194.

Though this is unfinished and a bit unstable, the parch seems working on PC/RPI4.
(I'm testing on a docker instance. #2147 needs RUN apk add --no-cache make to build this patch.)

Unfortunately it now requires a real JS interpreter (duktape) because the decryption code was too complicated without it.

ytdl-org/youtube-dl#29326 says

This does change with different player versions, so youtube-dl will need to extract this for every video that it fetches and then modify the n parameter as such.

but it's not changed so often, and fetching it for every video is pretty expensive. This needs more investigating.

Anyway, I implemented two level caches to prevent refetching it for every video. The decryption function is called dozens times on page load. (you can see cache #1 and cache #2 in the debug log)

invidious_1  | 2021-06-28 05:54:47 UTC [debug] decrypt_n: 1LaKH5etJoE fn = cha n = RFcl_9VK-CZhPMH89IYrX -> Fcw3Gl6gxDsX_A
invidious_1  | 2021-06-28 05:54:47 UTC [debug] decrypt_n: 1LaKH5etJoE fn = (cache #1) n = RFcl_9VK-CZhPMH89IYrX -> Fcw3Gl6gxDsX_A
invidious_1  | 2021-06-28 05:54:48 UTC [debug] decrypt_n: 1LaKH5etJoE fn = (cache #2) n = Fbc5fFBLqpj0fJOfAj4Gr -> 48_sUCeKYn_LHg
invidious_1  | 2021-06-28 05:54:48 UTC [debug] decrypt_n: 1LaKH5etJoE fn = (cache #1) n = Fbc5fFBLqpj0fJOfAj4Gr -> 48_sUCeKYn_LHg
invidious_1  | 2021-06-28 05:54:48 UTC [debug] decrypt_n: 1LaKH5etJoE fn = (cache #1) n = Fbc5fFBLqpj0fJOfAj4Gr -> 48_sUCeKYn_LHg
invidious_1  | 2021-06-28 05:54:48 UTC [debug] decrypt_n: 1LaKH5etJoE fn = (cache #1) n = Fbc5fFBLqpj0fJOfAj4Gr -> 48_sUCeKYn_LHg
   :

@shoxie007

This comment has been minimized.

@unixfox
Copy link
Member

unixfox commented Jun 28, 2021

Hello,

Thank you for your contribution.

In the PR #2220 I'm working on fetching the videoplayback URLs from the internal YouTube API using an Android client.

I do think the given videoplayback URLs aren't throttled but I'm not sure that's why could you take a look at?
By either running Invidious patched with the PR #2220 or by fetching the videoplayback URLs manually using the technique described here: TeamNewPipe/NewPipeExtractor#562

@putara
Copy link
Author

putara commented Jun 28, 2021

@unixfox Thanks, I will install #2220 locally and see if it can avoid throttling.

If the internal API works without any decryption, that will be great.
I personally am not a fan of polling a decryption function every minute. 😅

@SamantazFox
Copy link
Member

You should split the fetching and execute parts, btw. Add a Job to fetch the function every hour or every day, idk, store the string, and then run it when a video needs it.

@SamantazFox SamantazFox added the unfinished More work is needed on this PR, or on something this PR uses. label Jun 28, 2021
@SamantazFox SamantazFox added this to Work In progress in Todo - Invidious Jun 28, 2021
@putara putara mentioned this pull request Jun 29, 2021
3 tasks
@unixfox unixfox marked this pull request as draft July 16, 2021 12:23
@unixfox unixfox removed the unfinished More work is needed on this PR, or on something this PR uses. label Jul 16, 2021
@syeopite syeopite marked this pull request as ready for review August 9, 2021 18:55
@SamantazFox SamantazFox added the blocked require something else first label Aug 23, 2021
@SamantazFox
Copy link
Member

Marking this as "blocked" because this fix is not required anymore since #2220 has been merged.

@putara While we honnestly appreciate and thank you for your work, we don't want to add an extra dependency now, and will reconsider this PR if the problem occurs again.

@putara
Copy link
Author

putara commented Aug 24, 2021

@SamantazFox Yes, I totally agree with you. I will close this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked require something else first
Projects
Status: Ongoing discussions
Todo - Invidious
Ongoing discussions
Development

Successfully merging this pull request may close these issues.

[Bug] YouTube throtle speed on some videos
4 participants