When completed the download is there a callback function or something to notify it is successful?
ytdl-core returns a standard node stream, which emits an end event when finished.
@fent Can you kindly share a sample code? Thanks
The finish event worked for me (end didn't):
ytdl(url).pipe(fs.createWriteStream("video.mp4")).on("finish", function() {
console.log("Finished!");
});
// or:
const stream = ytdl(url);
stream.pipe(fs.createWriteStream("video.mp4"));
stream.on("finish", function() {
console.log("Finished!");
});
that's because .pipe() returns the destination stream, in this case, the writestream to video.mp4. writestreams have a different set of events, including 'finish`.
your first example should work. but the 2nd one is listening to the original read stream, which emits an end event
Oh, good to know, thanks! I didn't test the second one - I just assumed that the two approaches were equivalent. :|
Most helpful comment
ytdl-core returns a standard node stream, which emits an
endevent when finished.