Node-ytdl-core: How to get notified when download finished?

Created on 11 Mar 2018  路  5Comments  路  Source: fent/node-ytdl-core

When completed the download is there a callback function or something to notify it is successful?

question

Most helpful comment

ytdl-core returns a standard node stream, which emits an end event when finished.

All 5 comments

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. :|

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cloudrac3r picture cloudrac3r  路  5Comments

FireController1847 picture FireController1847  路  5Comments

ajgeiss0702 picture ajgeiss0702  路  5Comments

cloudrac3r picture cloudrac3r  路  5Comments

Asaduji picture Asaduji  路  6Comments