node-ytdl-core: ytdl.getInfo - Error: Status code: 404
The problem is that if i try get info from some urls i get this error. Example below.
const customVideoInfo = await ytdl.getInfo("http://www.youtube.com/watch?v=3Z61pOtkY7w")
Error: Status code: 404
at ClientRequest.<anonymous> (/workspace/node_modules/miniget/dist/index.js:211:27)
at Object.onceWrapper (events.js:421:26)
at ClientRequest.emit (events.js:314:20)
at ClientRequest.EventEmitter.emit (domain.js:506:15)
at HTTPParser.parserOnIncomingClient (_http_client.js:601:27)
at HTTPParser.parserOnHeadersComplete (_http_common.js:122:17)
at HTTPParser.execute (<anonymous>)
at TLSSocket.socketOnData (_http_client.js:474:22)
at TLSSocket.emit (events.js:314:20)
at TLSSocket.EventEmitter.emit (domain.js:506:15)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 9
- Comments: 19 (11 by maintainers)
Commits related to this issue
- still bug [fent/node-ytdl-core#923](https://github.com/fent/node-ytdl-core/issues/923) — committed to LoneExile/Bot_Discord_JS by LoneExile 3 years ago
I have some across this issue (Mainly on age restricted videos). This is an issue with fallback info endpoint “https://www.youtube.com/get_video_info”.
https://www.youtube.com/get_video_info?video_id=3Z61pOtkY7w This results in 404.
Adding a query parameter “html5=1” solves this issue. https://www.youtube.com/get_video_info?video_id=3Z61pOtkY7w&html5=1
Needs more testing though.
https://github.com/fent/node-ytdl-core/blob/b2df83c3fde965166fb875df6e0478f4bc81d6c9/lib/info.js#L328
Relying on this get_video_info, and blissfully unaware of the html5: 1 fix I had to do a bit of research today.
Seems YT has moved that get_info functionality into their INNERTUBE API which returns just the JSON data (responseContext) without the UrlEncoded wrapper.
Getting it requires a post request to https://www.youtube,com/youtubei/v1/player?key=YOUR_KEY
with videoId as a parameter along with some other innertube parameters (and the key) which are easy enough to pick out with any web request to youtube. It also requires a ‘x-goog-visitor-id’ in the header, which again you can pick out from the parameters.
This now conforms closely to their more efficient INNERTUBE API channel browse and search post requests.
I have working code that can do this now, if anyone is interested and can’t figure it out.
🤔 might have been some early signs of https://github.com/fent/node-ytdl-core/issues/939