yt-info
v0.1.3
Published
Grab information from YouTube with ease
Downloads
16
Maintainers
Readme
yt-info
Grab information from YouTube with ease
Warning!
This package is incomplete and many features will be added later. Thankfully code that was already written will not be changed or removed so if you think it's useful you can use it without much worries.
What's New?
- Fixed unescaped characters in URLs
- Added
Video.fromUrl()
function
Example
// Destructure the package
const { Video } = require('yt-info');
// [https://youtu.be/][ENrzD9HAZK4]
// ^ (domain) ^ ^ (video ID) ^
// Create new video object
// Pass in the video ID
// (We will talk about "summary" in a bit)
let url = 'https://www.youtube.com/watch?v=ENrzD9HAZK4';
let videoID = Video.fromUrl(url);
let myVideo = new Video(videoID, (summary) => {
// Prints out the video title in a callback function
console.log(myVideo.title);
});
Output
Node.js Ultimate Beginner’s Guide in 7 Easy Steps
Invidious
Grabbing info straight from youtube.com is slow, since the YouTube website is heavily bloated with trackers and spywares. Instead this package grabs info from Invidious - an open sourced front end for YouTube to improve parsing speed! (YouTube responses are so long and 80% of them are useless tracking IDs)
There are multiple instances of Invidious out there, you can find the fastest one for you here, and use it instead of the package default inv.cthd.icu
// snip
// We are trying to use "invidio.xamh.de" instead of the default "inv.cthd.icu"
let myVideo = new Video('ENrzD9HAZK4', (summary) => {
console.log(myVideo.title);
}, { instance: 'invidio.xamh.de' });
Output
Node.js Ultimate Beginner’s Guide in 7 Easy Steps
Video
"Summary"
You can use summary
to see more information about what the package is doing. For example, ping in ms
and status code.
// snip
let myVideo = new Video('ENrzD9HAZK4', (summary) => {
console.log(summary);
});
Output
{ preprocessing: 0, pinging: 490, parsing: 25, statusCode: 200, valid: true }
As we can see here, the time spent in
preprocessing
(Before sending the request),pinging
(waiting for response) andparsing
(Parsing recieved files) are0ms
,490ms
and25ms
respectively. Let's see what will happen if we request an invalid video.
Invalid Videos
If a video is invalid, the response will be a bunch of undefined values, here's how you check if the video is valid or not.
// snip
// Let's see what will happen is an invalid video ID is provided
let invalidVideo = new Video('does-not-exist', (summary) => {
console.log(summary);
});
Output
{ valid: false, statusCode: 502 }
Video Information
Other than Video.title
we used above, there are many more properties of the Video
object. Here are some of its properties.
Video.html
: Get the html response of the videoVideo.title
: Title of the videoVideo.description
: Description of the videoVideo.thumbnail
: Video thumbnail file URLVideo.youtubeEmbed
: URL to YouTube embed video (Not suggested)Video.aspect_ratio
: Aspect ratio of the videoVideo.definitions
: Different definitions/quality that this video offers (+ Download links | Note: This returns an array of objects)Video.subtitle
: Subtitle tracks that this video offers (+ Download links | Note: This returns an array of objects)Video.files
: All the downloadable files that the video has (Note: This returns an array of objects)Video.data
: Returns everything about the video (Excludinghtml
)Video.scores
: Returns scores (automated ratings) of the videoVideo.channel
: Returns channel info of the videoVideo.date
: Returns the creation date (String) of the video
TODO
- Add support for hashtags, playlists, channels and more