1.0.5 ā€¢ Published 3 years ago

tube-api v1.0.5

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago
  • 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