tube-api
TypeScript icon, indicating that this package has built-in type declarations

1.0.5 • Public • Published

Welcome to tube-api 👋

Version Documentation Maintenance License: MIT

  • 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

Package Sidebar

Install

npm i tube-api

Weekly Downloads

0

Version

1.0.5

License

MIT

Unpacked Size

27.6 kB

Total Files

18

Last publish

Collaborators

  • bishkou