npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

yt-info

v0.1.3

Published

Grab information from YouTube with ease

Downloads

39

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) and parsing (Parsing recieved files) are 0ms, 490ms and 25ms 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 video
  • Video.title: Title of the video
  • Video.description: Description of the video
  • Video.thumbnail: Video thumbnail file URL
  • Video.youtubeEmbed: URL to YouTube embed video (Not suggested)
  • Video.aspect_ratio: Aspect ratio of the video
  • Video.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 (Excluding html)
  • Video.scores: Returns scores (automated ratings) of the video
  • Video.channel: Returns channel info of the video
  • Video.date: Returns the creation date (String) of the video

TODO

  • Add support for hashtags, playlists, channels and more