node-ytdl icon indicating copy to clipboard operation
node-ytdl copied to clipboard

Playlist support?

Open milesflo opened this issue 7 years ago • 3 comments

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.

milesflo avatar Dec 18 '17 21:12 milesflo

Feature Request ^

milesflo avatar Dec 18 '17 21:12 milesflo

I agree, that feature would be awesome to have! Any update so far? :)

Ishidres avatar Nov 08 '19 23:11 Ishidres

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);

mifi avatar Apr 26 '20 05:04 mifi