@fabricio-191/youtube
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

Issues Donate Discord

You can see the changelog here

You have to bear in mind that this does not use an official youtube api, there is no documentation and a change could cause it to throw an error, besides that there are things that I do not know, such as different privacy settings or rendering

Use example:

const { getVideo, getPlaylist, search } = require('@fabricio-191/youtube')
  .setDefaultOptions({
    location: 'AR',
    language: 'es-419'
  });

here you can see a JSON that shows the information that each method gives (I do not put it here, because it is a lot)

Methods:

getVideo(URLorID, options)

  • returns a Promise
getVideo('https://www.youtube.com/watch?v=H2wCwdHk-ao&list=PLDS0dpumEOi0pu_0pCGqvcaRkxg-o1gqg')
  .then(data => {
    console.log(data);
    //do something...
  })  
  .catch(console.error);

getPlaylist(URLorID, options)

  • returns a Promise
getPlaylist('https://www.youtube.com/watch?v=H2wCwdHk-ao&list=PLDS0dpumEOi0pu_0pCGqvcaRkxg-o1gqg')
  .then(data => {
    console.log(data);
    //do something...
  })  
  .catch(console.error);

search(searchString, options)

  • returns a Promise
search('Node.js', { quantity: 40 })
  .then(data => {
    const videos = data.results.filter(x => x.type === 'video');
    //do something...
  })  
  .catch(console.error);

setDefaultOptions(options)

  • returns this

Options:

The default options are:

{
  language: 'en',
  location: 'US',
  quantity: 'all',
  requestsOptions: {}
}

The default quantity for a search is 20

The requestsOptions are passed directly to the http.request() (or https) method
here you can see which can be

And here you can see a list of valid locations and languages

When you pass options to a method, the options without value, will be taken from the default values

Notes:

  • In an array of Thumbnails, the first will always be the bigger
  • Some structures have a toString() method that returns the clear text in it, for others is an URL, like in an array of thumbnails

To-do

  • A method to download videos
  • Make typings and JSDoc
  • Improve error handling
  • A method to get info and videos from a channel
  • Get comments from a video

Credits

  • ytpl for the bases and the how-to
  • This stack overflow post for the regex to get videos ID's from URL's

Package Sidebar

Install

npm i @fabricio-191/youtube

Weekly Downloads

37

Version

0.0.4

License

Apache License 2.0

Unpacked Size

69.8 kB

Total Files

15

Last publish

Collaborators

  • fabricio-191