qm-yt-api

0.3.1 • Public • Published

logo-qm

qm-yt-api npm version code style: prettier

Simple wrapper of youtube api for getting info about videos also ones in playlist.

Installation

$ npm i -S qm-yt-api

Usage

All module's functions returns promise object.

import ytAPI from "qm-yt-api";
 
// ...
 
const videoInfo = await ytAPI.getVideoInfo(key, videoId);
// => 
// {
//   id: "8CrOL-ydFMI",
//   title: "This Is Water ... "
// }
 
// or 
const videos = await ytAPI.getVideosInfoFromPlaylist(key, playlistId);
// =>
// {
//   playlistName: "...",
//   playlistId: "PL14-...",
//   itemsNumber: 2,
//   askDate": "Tue Oct 31 2017 09:19:50 GMT+0100 (STD)",
//   videos: [
//     {
//       position: 0,
//       id: "8CrOL-ydFMI",
//       publishedAt: "2017-10-21T16:44:15.000Z",
//       title:
//         "This Is Water ..."
//     },
//     {
//       position: 1,
//       id: "RnGvWTRQ9j4",
//       publishedAt: "2017-10-21T16:44:59.000Z",
//       title: "Everyday Virtue..."
//     }
//   ],
// };

Options

There's possibility to get raw youtube api response. All you need is set additional option:

const options = { rawApiData: true }; //default: false
const videoInfo = await ytAPI.getVideoInfo(apiKey, videoId, options, apiOptions)

You can modify api request by passing apiOptions argument. Default used are:

const apiOptions = {
  part: "snippet, contentDetails",
}

See additional options in Google documentation.

YT API Errors:

For all encounter API error messages the module throws an error.

Tests

Tests are made against real YT data, so for performing testing you need working google apikey and put it to ./test/key.json file. Use .key-tmeplate.json as reference.

Limitations

Due to access via api key getting private video information is limitted.

Credits

License

MIT © qaraluch

Readme

Keywords

none

Package Sidebar

Install

npm i qm-yt-api

Weekly Downloads

0

Version

0.3.1

License

MIT

Last publish

Collaborators

  • qaraluch