youtu-get

1.1.3 • Public • Published

youtu-get

is project which can get your all name of songs and url from your youtube playlist. It returns array with name of songs and url as objects and the returned data can be save as json file. As my example, but it is optional if you define output variable.

demo

NPM npm npm GitHub code size in bytes GitHub repo size Coverage badge


Instalation

npm i youtu-get -g

Example running:

ytget id="PLxQ30nUCB0uNCCKBD_JW1udM7iYH27cu2" output="/yourOutputPath/youtube-playlist.json"

You can use this package for your next solution like this:

const { getYoutubeInfo } = require('youtu-get');
 
const idPlaylist = 'PLxQ30nUCB0uNCCKBD_JW1udM7iYH27cu2';
getYoutubeInfo(idPlaylist).then((data) => console.log(data));

If you want save output data yout can do it like this:

const { getYoutubeInfo } = require('youtu-get');
const path = require('path');
const username = require('os').userInfo().username;
 
const idPlaylist = 'PLxQ30nUCB0uNCCKBD_JW1udM7iYH27cu2';
 
const outputPath = path.resolve(
  `/Users/${username}/Downloads/`,
  'youtube-playlist.json'
);
 
getYoutubeInfo(idPlaylist).then((data) => {
  fs.writeFile(outputPath, JSON.stringify(data, null, 2), (err) => {
    if (err) console.error(err);
  });
});

If you want check your youtube playlist id before running getYoutubeInfo function you can use this:

const { getYoutubeInfo, isValidId } = require('youtu-get');
const path = require('path');
const username = require('os').userInfo().username;
 
const idPlaylist = 'PLxQ30nUCB0uNCCKBD_JW1udM7iYH27cu2';
const isValid = isValidId(id)
const outputPath = path.resolve(
  `/Users/${username}/Downloads/`,
  'youtube-playlist.json'
);
isValid ?
  getYoutubeInfo(idPlaylist).then(data => {
    fs.writeFile(outputPath, JSON.stringify(data, null, 2), err => {
      if (err) console.error(err);
    });
  });
  : console.error(`This youtube playlist id is not valid: ${idPlaylist}`);

Expected incorrect result if you don't define your youtube playlist id:

Alt 1

Expected correct result if you defined correct your youtube playlist id without defined output path:

Alt 2

Expected correct result if you defined correct your youtube playlist id with defined output path:

Alt 2

Package Sidebar

Install

npm i youtu-get

Weekly Downloads

4

Version

1.1.3

License

ISC

Unpacked Size

9.19 kB

Total Files

6

Last publish

Collaborators

  • lukas-frantal