fent / node-ytdl-core

YouTube video downloader in javascript.
MIT License
4.53k stars 805 forks source link

formats is empty #754

Closed daoquangphuong closed 4 years ago

daoquangphuong commented 4 years ago

ytdl-core v4

after running this code

const ytdlCore = require('ytdl-core');

const main = async () => {
    const info =  await ytdlCore.getInfo('https://www.youtube.com/watch?v=rButbqDqAe8');
    console.log(info.formats)
}

main().catch(console.error)

I get info.formats = []

[]
Roki100 commented 4 years ago

it mostly happens when the video is not available in your region

daoquangphuong commented 4 years ago

that's weird cause I still can view this video from my browser.

![Uploading Screen Shot 2020-10-28 at 15.12.15.png…]()

Roki100 commented 4 years ago

I cant see the image but I am not sure then. I don't get formats mostly when the video is not available in the region my server is in

daoquangphuong commented 4 years ago

sorry for the image. @Roki100 I got empty formats when I was running the code above on my computer. the weird thing, I can play the youtube link that was used in the code on my computer. so I don't think the reason is the region

https://www.youtube.com/watch?v=rButbqDqAe8

daoquangphuong commented 4 years ago

https://github.com/fent/node-ytdl-core/blob/c5290635a5035bdf81cfebc8c0de67ca56f8ba14/lib/info.js#L116

It happens to some youtube links that there is no embed permission.

I clone your code and fix it by adding this line

  info.player.args.player_response = info.player.args.player_response || info.playerResponse;

to

info.html5player = info.html5player || (info.player && info.player.assets && info.player.assets.js);
  info.player.args.player_response = info.player.args.player_response || info.playerResponse;
  return gotConfig(id, options, info, body);

When info.player.args.player_response = undefinied it should be taken from info.playerResponse

fent commented 4 years ago

thanks for the above tip on how to fix

going to mark this as dupe since #750 exists