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

tube-api

v1.0.5

Published

Youtube Api v3 Wrapper, Channel Details, Videos List and Video Details

Downloads

15

Readme

  • YOU NEED A YOUTUBE_API_KEY from Google Developers Console
  • Fetch Channel Details by Channel ID.
  • Fetch a Channel's video list by uploads_id
  • Fetch Video Details by Video ID

🏠 Homepage

Install

npm i tube-api

Get Channel details by ID

/** channelDetails fetchs the api for channel info **/
import { Youtube } from 'tube-api';

const YOUTUBE_API_KEY = 'MY_YOUTUBE_API_KEY' // your youtube_api_key
const ytube = new Youtube(YOUTUBE_API_KEY);


/**
 * @param {string} channelId 
 * @example
 * Channel URL: https://www.youtube.com/channel/UCn8zNIfYAQNdrFRrr8oibKw
 * channelId is UCn8zNIfYAQNdrFRrr8oibKw 
 */
const details = await ytube.channelDetails('UCn8zNIfYAQNdrFRrr8oibKw')

console.log(details);
/**
{
  title: 'freeCodeCamp.org',
  thumbnails: {
    default: {
      url: 'https://yt3.ggpht.com/ytc/AAUvwnifaQZvAunS0OFb2y_cieoVjLCVjqQW8Exf3BC1gg=s88-c-k-c0x00ffffff-no-rj',
      width: 88,
      height: 88
    },
    medium: {
      url: 'https://yt3.ggpht.com/ytc/AAUvwnifaQZvAunS0OFb2y_cieoVjLCVjqQW8Exf3BC1gg=s240-c-k-c0x00ffffff-no-rj',
      width: 240,
      height: 240
    },
    high: {
      url: 'https://yt3.ggpht.com/ytc/AAUvwnifaQZvAunS0OFb2y_cieoVjLCVjqQW8Exf3BC1gg=s800-c-k-c0x00ffffff-no-rj',
      width: 800,
      height: 800
    }
  },
  country: 'US',
  uploads_id: 'UU8butISFwT-Wl7EV0hUK0BQ', // The Id we use to get the list of videos on this channel
  statistics: {
    viewCount: '177010008',
    subscriberCount: '3480000',
    hiddenSubscriberCount: false,
    videoCount: '1253'
  }
}
**/

Fetch Video List of the Channel

NOTE : Calling this function might take some time depending on how many videos a channel has, generally if it's below 50 it will be fast.

/** videosList fetch the api for the list of video on the channel **/
import { Youtube } from 'tube-api';

const YOUTUBE_API_KEY = '' // your youtube_api_key
const ytube = new Youtube(YOUTUBE_API_KEY);

/** We first need to fetch the channel details to get the uploads_id **/


/**
 * @param {string} channelId 
 * @example
 * Channel URL: https://www.youtube.com/channel/UCn8zNIfYAQNdrFRrr8oibKw
 * channelId is UCn8zNIfYAQNdrFRrr8oibKw 
 */
const details = await ytube.channelDetails('UCn8zNIfYAQNdrFRrr8oibKw');

/** Now we use the uploads_id from the channelDetails result **/

/**
 * @param {string} uploads_id Taken from the channelDetails result
 * @param {Array} empty array
 */
const videos = await ytube.videosList(details.uploads_id, [])

console.log(vidoes)
/**
[ {
    title: 'Tkinter Calculator - Python Basics with Sam',
    video_id: 'PkLwJicRI8s',
    thumbnails: {
      default: [Object],
      medium: [Object],
      high: [Object],
      standard: [Object],
      maxres: [Object]
    },
    statistics: {
      viewCount: '22679',
      likeCount: '797',
      dislikeCount: '10',
      favoriteCount: '0',
      commentCount: '26'
    }
  },
  ... 1153 more items
]

 **/

Fetch Video Details by ID

/** videoInfo fetchs the api for the video details **/
import { Youtube } from 'tube-api';

const YOUTUBE_API_KEY = '' // your youtube_api_key
const ytube = new Youtube(YOUTUBE_API_KEY);

/**
 * @param {string} videoId
 * @example
 * Video URL: https://www.youtube.com/watch?v=RBSGKlAvoiM
 * videoId is RBSGKlAvoiM 
 */
const video = await ytube.videoInfo('RBSGKlAvoiM');


/**
{
  title: 'Data Structures Easy to Advanced Course - Full Tutorial from a Google Engineer',
  video_id: 'RBSGKlAvoiM',
  thumbnails: {
    default: {
      url: 'https://i.ytimg.com/vi/RBSGKlAvoiM/default.jpg',
      width: 120,
      height: 90
    },
    medium: {
      url: 'https://i.ytimg.com/vi/RBSGKlAvoiM/mqdefault.jpg',
      width: 320,
      height: 180
    },
    high: {
      url: 'https://i.ytimg.com/vi/RBSGKlAvoiM/hqdefault.jpg',
      width: 480,
      height: 360
    },
    standard: {
      url: 'https://i.ytimg.com/vi/RBSGKlAvoiM/sddefault.jpg',
      width: 640,
      height: 480
    },
    maxres: {
      url: 'https://i.ytimg.com/vi/RBSGKlAvoiM/maxresdefault.jpg',
      width: 1280,
      height: 720
    }
  },
  statistics: {
    viewCount: '2748752',
    likeCount: '67222',
    dislikeCount: '655',
    favoriteCount: '0',
    commentCount: '1541'
  }
}

 **/

Author

👤 Chedy

🤝 Contributing

Contributions, issues and feature requests are welcome!Feel free to check issues page. You can also take a look at the contributing guide.

Show your support

Give a STAR if this project helped you!

Source of the data

📝 License

  • Copyright © 2021 Chedy.
  • This project is MIT licensed.

This README was generated with by readme-md-generator