przemyslawpluta / node-youtube-dl

youtube-dl driver for node
MIT License
1.71k stars 368 forks source link

Differences between normal download vs exec usage for non-youtube urls #294

Open yafp opened 4 years ago

yafp commented 4 years ago

I am able to download video and audio using node-youtube-dl for several supported sources if i am using .exec (see example from the project readme).

But if i try to use the normal download (which tends to offer advantages if it comes to progress etc) mode (not using .exec) it seems like only youtube content is fully working - while non-youtube urls fail.

How do they fail?

Well there is no error, but the output is only around some kb - like youtube-dl is not getting the full content, but just the header or something like that.

does this make any sense to you?

tldr:

luanlmd commented 4 years ago

I've been having the same problem, but it also happens with longer youtube videos. Using .exec works just fine but there is no way to watch the progress.

yafp commented 4 years ago

@luanlmd interessting.

but it also happens with longer youtube videos

How long is long in that context? :)

luanlmd commented 4 years ago

@yafp while coding an example with the said video, it just happned to work example of vimeo not working: (the commented line is the yt video that didn't work at first)

const fs = require('fs');
const youtubedl = require('youtube-dl');

//const video = youtubedl('https://www.youtube.com/watch?v=mRNIcerXzLw');
const video = youtubedl('https://vimeo.com/387590406');

video.on('info', function (info) {
    console.log('Download started')
    console.log('filename: ' + info._filename)
    console.log('size: ' + info.size)
})

video.on('error', function error(err) {
    console.log('error 2:', err)
})

video.pipe(fs.createWriteStream('file.mp4'))

output:

node example.js 
Download started
filename: LIGHT SPEED-387590406.mp4
size: 9848
jabbink commented 4 years ago

I noticed that this library likes to pass --dump-json which, by the documentation simulates "Simulate, quiet but print JSON information."

For some reason though, ytdl actually downloads YouTube videos with the simulate option on, for most other sites, it does not, and this library will fail to get the file/live stream.

yafp commented 4 years ago

@Kikobeats any insights you can give us here?

Kikobeats commented 4 years ago

@yafp not really – most of the time I just get the JSON version of the payload, skipping the download, so I'm not treating with this kind of problems

jabbink commented 4 years ago

@yafp try changing dump-json to print-json

yafp commented 4 years ago

@jabbink in my case i set a bunch of youtube-parameters myself.

I noticed that this library likes to pass --dump-json which, by the documentation simulates "Simulate, quiet but print JSON information."

How did you notice that? I did assume so far that it is using exactly the parameters i am giving it.

I can for sure add print-json, but i dont know how to replace dump-json which i dont set myself.

yafp commented 4 years ago

@Kikobeats if i do use

The download almost never works.

It

The resulting .mp4 is 148 Bytes.

Additional infos

I have no idea why but

ghost commented 4 years ago

Videos actually don't get downloaded via youtube-dl. node-youtube-dl only uses the --dump-json option to fetch the URL for the mp4 file and downloads it via the request node module. If it's a HLS video the m3u8 file will be downloaded instead of the video.

To actually download a video via youtube-dl you can use a module that just wraps it. I created my own solution for this, but there are also others out there.

masudhossain commented 3 years ago

@ghjbnm do you have an example electrons app with your implementation? Having issues downloading twitch vods atm too

ghost commented 3 years ago

@masudhossain You can use it just like you would in node. If you are trying to execute it in the render process you have to enable nodeIntegration when creating the BrowserWindow. Using it in the main process should just work,

const YoutubeDlWrap = require("youtube-dl-wrap");
const youtubeDlWrap = new YoutubeDlWrap("path/to/youtube-dl/binary");
await youtubeDlWrap.execPromise(["https://www.twitch.tv/videos/vodId",
    "-f", "best", "-o", "output.mp4"]);