0.0.4 • Published 2 years ago

@fabricio-191/youtube v0.0.4

Weekly downloads
12
License
Apache License 2....
Repository
github
Last release
2 years ago

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
0.0.3-1

2 years ago

0.0.3-2

2 years ago

0.0.2-7

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2-6

3 years ago

0.0.2-5

3 years ago

0.0.2-4

3 years ago

0.0.2-3

3 years ago

0.0.2-2

3 years ago

0.0.2-1

3 years ago

0.0.2-0

3 years ago

0.0.1-5

3 years ago

0.0.1-2

3 years ago

0.0.1-0

3 years ago

0.0.0-1

3 years ago

0.0.0-0

3 years ago