node-ytdl
node-ytdl copied to clipboard
Playlist support?
It'd be nice to have a playlist flag that would iterate over an API call to get all of the videos in a playlist and download them into the current directory.
Feature Request ^
I agree, that feature would be awesome to have! Any update so far? :)
Maybe better to use something like this https://github.com/tjrgg/simple-youtube-api/blob/master/examples/playlist.js it requires an api key though...
EDIT: Oh this one: https://github.com/TimeForANinja/node-ytpl
This works:
const fs = require('fs');
const ytdl = require('ytdl-core');
const ytpl = require('ytpl');
const limit = 2;
const playlistId = 'UUht8qITGkBvXKsR1Byln-wA';
(async () => {
const playlist = await ytpl(playlistId);
const items = playlist.items.slice(0, limit);
console.log(items);
for (const { id, title, url } of items) {
console.log('Downloading', title);
const stream = ytdl(url).pipe(fs.createWriteStream(`${id}.mp4`));
await new Promise((resolve, reject) => {
stream.on('finish', resolve);
stream.on('error', reject);
});
}
})().catch(console.error);