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

Add parameters to get_video_info endpoint to fix 404 errors #938

Merged
merged 6 commits into from Jun 26, 2021

Conversation

D3SOX
Copy link
Contributor

@D3SOX D3SOX commented Jun 19, 2021

This fixes 404 errors.
See zerodytrash/Simple-YouTube-Age-Restriction-Bypass#18 (comment) for more information about this issue

Fixes #939

@BenCarmichael01
Copy link

this fixes the 404 error but it also seems to add about 5 second delay to a getInfo as well

lib/info.js Outdated
@@ -325,6 +325,8 @@ const VIDEO_EURL = 'https://youtube.googleapis.com/v/';
const getVideoInfoPage = async(id, options) => {
const url = new URL(`https://${INFO_HOST}${INFO_PATH}`);
url.searchParams.set('video_id', id);
url.searchParams.set('c', 'TVHTML5');
url.searchParams.set('cver', '7.20190319');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to get this number from one of the prev. fetched pages? not a big fan of hard coding version numbers... 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, I got the information from @zerodytrash. StackOverflow answers also suggest 6.20180913 for the version
https://stackoverflow.com/questions/67615278/get-video-info-youtube-endpoint-suddenly-returning-404-not-found

I tried it with other random numbers and strings and it seems to work too so I guess it only has to be set to something.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually just searching the watch page gave me this
image
cver: 7.20190319 is over 1 year old...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I change it to that value?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

setting cver to 2.20210621.02.00 seems to cause the issue all over again

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok seems like to set cver to 2.20210621.02.00,you need to set c to WEB. but when i did this it still caused 404s sometimes

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now i am applying a local patch with c set to TVHTML5 and cver set to 6.20180913

@D3SOX D3SOX changed the title Add useful parameters to get_video_info endpoint Add parameters to get_video_info endpoint to fix 404 errors Jun 22, 2021
@D3SOX
Copy link
Contributor Author

D3SOX commented Jun 22, 2021

seems to add about 5 second delay

@Jaques22 Hm I didn't notice any delay. Are you sure this is the culprit?

@D3SOX
Copy link
Contributor Author

D3SOX commented Jun 22, 2021

@AlbinGrans Are those defined when you send the request without those parameters? Or is it just giving a 404 instead?
Maybe they renamed some parameters. I haven't looked at those yet.

@BenCarmichael01
Copy link

BenCarmichael01 commented Jun 22, 2021

seems to add about 5 second delay

@Jaques22 Hm I didn't notice any delay. Are you sure this is the culprit?

I should note that I am using ytdl-core-discord which relies upon this so maybe a problem with that wrapper.
I just did some very basic testing and it seems like the getinfo call takes longer now

try { 
                const results = await youtube.searchVideos(search, 1, { part: "snippet" });
                console.log(results);
                console.log("start getInfo");
                songInfo = await ytdl.getInfo(results[0].url);
                console.log("end getInfo");
...

results definitely returns before the "start" log then it's about 5 seconds before the "end" log whereas before it was maybe 1-2s.
Though with this being a youtube api change its probably on the api side not ytdl

@decahedron1
Copy link

decahedron1 commented Jun 22, 2021

New endpoint removes microformat metadata as well

@TimeForANinja
Copy link
Collaborator

results definitely returns before the "start" log then it's about 5 seconds before the "end" log whereas before it was maybe 1-2s.
Though with this being a youtube api change its probably on the api side not ytdl

have heard of that befor in another context 🤔 so this might not be related to the 404's

@BenCarmichael01
Copy link

results definitely returns before the "start" log then it's about 5 seconds before the "end" log whereas before it was maybe 1-2s.
Though with this being a youtube api change its probably on the api side not ytdl

have heard of that befor in another context 🤔 so this might not be related to the 404's

Yeh it's probably not related, just thought I'd add in case a faster alternative was doable but I guess we'll see if someone comes up with one

@D3SOX
Copy link
Contributor Author

D3SOX commented Jun 22, 2021

The metadata seems to have changed with this. The duration no longer works. I might investigate this later today. If anyone has an idea let me know

@JeHwanYoo
Copy link

JeHwanYoo commented Jun 23, 2021

it perfectly works thank you.
I'll use this temporarily until the official version is updated.

@Zigecek
Copy link

Zigecek commented Jun 23, 2021

Hi, when will be this merged?

@D3SOX
Copy link
Contributor Author

D3SOX commented Jun 23, 2021

@timbly5000 I personally use patch-package for now. You can apply the patch inside node_modules and then run patch-package ytdl-core or put this into a file named ytdl-core+4.8.2.patch in a patches folder relative the root of your project

diff --git a/node_modules/ytdl-core/lib/info-extras.js b/node_modules/ytdl-core/lib/info-extras.js
index c806c9f..0cfe685 100644
--- a/node_modules/ytdl-core/lib/info-extras.js
+++ b/node_modules/ytdl-core/lib/info-extras.js
@@ -283,7 +283,7 @@ exports.cleanVideoDetails = (videoDetails, info) => {
   // Use more reliable `lengthSeconds` from `playerMicroformatRenderer`.
   videoDetails.lengthSeconds =
     info.player_response.microformat &&
-    info.player_response.microformat.playerMicroformatRenderer.lengthSeconds;
+    info.player_response.microformat.playerMicroformatRenderer.lengthSeconds || info.player_response.videoDetails.lengthSeconds;
   return videoDetails;
 };
 
diff --git a/node_modules/ytdl-core/lib/info.js b/node_modules/ytdl-core/lib/info.js
index 417f876..a2dd09a 100644
--- a/node_modules/ytdl-core/lib/info.js
+++ b/node_modules/ytdl-core/lib/info.js
@@ -325,6 +325,8 @@ const VIDEO_EURL = 'https://youtube.googleapis.com/v/';
 const getVideoInfoPage = async(id, options) => {
   const url = new URL(`https://${INFO_HOST}${INFO_PATH}`);
   url.searchParams.set('video_id', id);
+  url.searchParams.set('c', 'TVHTML5');
+  url.searchParams.set('cver', '7.20190319');
   url.searchParams.set('eurl', VIDEO_EURL + id);
   url.searchParams.set('ps', 'default');
   url.searchParams.set('gl', 'US');

@D3SOX
Copy link
Contributor Author

D3SOX commented Jun 23, 2021

Only player_response.videoDetails.lengthSeconds seems to be set with these parameters. I added it as a fallback to be included in the info result's videoDetails property

@AlbinGrans Can you confirm that it's working now?

@AlbinGrans
Copy link

Only player_response.videoDetails.lengthSeconds seems to be set with these parameters. I added it as a fallback to be included in the info result's videoDetails property

@AlbinGrans Can you confirm that it's working now?

Yep lengthSeconds is there now! publishDate is still undefined.

Copy link

@1001Josias 1001Josias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change worked perfectly for me.

@TimeForANinja
Copy link
Collaborator

ok - thinking about giving this a pass, even though this breaks basically all videoDetails
it's the fix youtube-dl went for and i don't see any other option
did test some with other cver but no success... hope this doesn't end in a "update cver every 3 months"

@skick1234
Copy link
Contributor

skick1234 commented Jun 24, 2021

did test some with other cver but no success... hope this doesn't end in a "update cver every 3 months"

We can get the client version from the web and replace 2.version with 7.version to change it to TV client version.

Like 2.20210622.10.00 -> 7.20210622.10.00

@mpirescarvalho
Copy link

mpirescarvalho commented Jun 24, 2021

It's not fully working for me, still getting 404 in, let's say, half of the requests

Edit: yeah, definitively not working for me

@TimeForANinja
Copy link
Collaborator

did test some with other cver but no success... hope this doesn't end in a "update cver every 3 months"

We can get the client version from the web and replace 2.version with 7.version to change it to TV client version.

Like 2.20210622.10.00 -> 7.20210622.10.00

that sound's promising... didn't try that yet

200percentmicky added a commit to 200percentmicky/chadtube that referenced this pull request Jun 24, 2021
@skick1234 skick1234 mentioned this pull request Jun 24, 2021
@D3SOX
Copy link
Contributor Author

D3SOX commented Jun 24, 2021

did test some with other cver but no success... hope this doesn't end in a "update cver every 3 months"

We can get the client version from the web and replace 2.version with 7.version to change it to TV client version.

Like 2.20210622.10.00 -> 7.20210622.10.00

Are you sure the version numbers work like that? If so, we would need to pass the information from getWatchHTMLPage.

I did a little test (with #946 applied) and adding this at the bottom of getWatchHTMLPage seems to do it:

const clientVersion = info.response.responseContext.serviceTrackingParams
    .find(param => param.service === 'CSI').params
    .find(param => param.key === 'cver').value;
const tvVersion = `7${clientVersion.substring(1)}`;

(quick and dirty without any sanity checks)

If this is going to be the way to go, how do we want to implement it? I thought about setting it to something like options.tvVersion and then using it inside getVideoInfoPage.

What should we use as a fallback value if getWatchHTMLPage fails?

@TimeForANinja
Copy link
Collaborator

thought about using utils.between(body, '{"key":"cver","value":"', '"}')
that would make it independant of finding a player config

besides that, i don't think that

What should we use as a fallback value if getWatchHTMLPage fails?

is a real problem. If getWatchHTMLPage completely fails something is wrong with the video. If we don't find a player config we should still find the cver

another option would be just caching it in a global variable... default value could be sth. like 7.20210622.10.00, update it every time we do any getWatchHTMLPage and it would therefor always be present

@jbelford
Copy link

Thought I'd share this PR on lavaplayer sedmelluq/lavaplayer#640

Tested on my own branch and c=ANDROID and cver=16.24 also works

@mome0320
Copy link
Contributor

Thought I'd share this PR on lavaplayer sedmelluq/lavaplayer#640

Tested on my own branch and c=ANDROID and cver=16.24 also works

It also lengthSeconds, publishDate is still undefined.

@redbrain redbrain mentioned this pull request Jun 25, 2021
@D3SOX
Copy link
Contributor Author

D3SOX commented Jun 25, 2021

@TimeForANinja Thank you, that should do it.

Copy link

@Lazy-C0der Lazy-C0der left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

at line 312 in info.js can you explain me what actually this code do ??

@omenocal
Copy link

@TimeForANinja thanks for looking into this issue. I've got a large project that heavily relies on this library, do you have an ETA when a new release with these fixes will be published to NPM? Thanks,

@TimeForANinja
Copy link
Collaborator

@TimeForANinja thanks for looking into this issue. I've got a large project that heavily relies on this library, do you have an ETA when a new release with these fixes will be published to NPM? Thanks,

Waiting for some feedback from the other devs
Might merge after that

@TimeForANinja
Copy link
Collaborator

Thanks again for the PR @D3SOX and everyone else who helped
For further Problems with (especially) video details check out #958

@github-actions
Copy link

🎉 This PR is included in version 4.8.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MinigetError: input stream: Status code: 404