Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

better-youtube-api

Package Overview
Dependencies
Maintainers
1
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-youtube-api - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

out/util/request.js

58

out/index.js

@@ -14,7 +14,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
const googleapis_1 = require("googleapis");
const entities_1 = require("./entities");
const util_1 = require("./util");
__export(require("./entities"));
const youtube = googleapis_1.google.youtube('v3');
/**

@@ -36,6 +34,6 @@ * The main class used to interact with the YouTube API. Use this.

}
const { data: results } = yield youtube.search.list({
const results = yield util_1.request.api('search', {
q: searchTerm,
maxResults,
auth: this.token,
key: this.token,
part: 'snippet',

@@ -46,11 +44,15 @@ type

results.items.forEach(item => {
if (type === 'video') {
items.push(new entities_1.Video(this, item));
switch (type) {
case 'video':
items.push(new entities_1.Video(this, item));
break;
case 'channel':
items.push(new entities_1.Channel(this, item));
break;
case 'playlist':
items.push(new entities_1.Playlist(this, item));
break;
default:
throw new Error('Type must be a video, channel, or playlist');
}
else if (type === 'channel') {
items.push(new entities_1.Channel(this, item));
}
else if (type === 'playlist') {
items.push(new entities_1.Playlist(this, item));
}
});

@@ -64,21 +66,21 @@ return items;

if (type === 'video') {
result = (yield youtube.videos.list({
result = yield util_1.request.api('videos', {
id,
part: 'snippet,contentDetails,statistics,status',
auth: this.token
})).data;
key: this.token
});
}
else if (type === 'channel') {
result = (yield youtube.channels.list({
result = yield util_1.request.api('channels', {
id,
part: 'snippet,contentDetails,statistics,status',
auth: this.token
})).data;
key: this.token
});
}
else if (type === 'playlist') {
result = (yield youtube.playlists.list({
result = yield util_1.request.api('playlists', {
id,
part: 'snippet,contentDetails,player',
auth: this.token
})).data;
key: this.token
});
}

@@ -205,8 +207,8 @@ if (result.items.length === 0) {

}
let { data: results } = yield youtube.playlistItems.list({
const results = yield util_1.request.api('playlistItems', {
playlistId,
part: 'snippet',
auth: this.token,
key: this.token,
maxResults: full ? 50 : maxResults
}).catch(error => {
}).catch(() => {
return Promise.reject('Playlist not found');

@@ -224,7 +226,7 @@ });

let oldRes = results;
for (let i = 0; i < pages; i++) {
const { data: newResults } = yield youtube.playlistItems.list({
for (let i = 1; i < pages; i++) {
const newResults = yield util_1.request.api('playlistItems', {
playlistId,
part: 'snippet',
auth: this.token,
key: this.token,
maxResults: 50,

@@ -234,3 +236,3 @@ pageToken: oldRes.nextPageToken

oldRes = newResults;
newResults.items.forEach((item) => {
newResults.items.forEach(item => {
videos.push(new entities_1.Video(this, item));

@@ -237,0 +239,0 @@ });

@@ -7,1 +7,2 @@ "use strict";

__export(require("./util"));
__export(require("./request"));
{
"name": "better-youtube-api",
"version": "0.1.1",
"version": "0.1.2",
"description": "A very easy to use Youtube Data v3 API.",

@@ -12,5 +12,2 @@ "main": "out/index.js",

"license": "GPL-3.0",
"dependencies": {
"googleapis": "^32.0.0"
},
"keywords": [

@@ -17,0 +14,0 @@ "youtube",

# Better YouTube API
Want to access data from the YouTube Data v3 API? No problem! We've got ya covered. `npm i better-youtube-api`
Want to access data from the YouTube Data v3 API? Want a Node.js YouTube API wrapper with typings? No problem! We've got ya covered. `npm i better-youtube-api`

@@ -10,3 +10,3 @@ # Examples

```js
const YouTube = require('better-youtube-api').YouTube
const { YouTube } = require('better-youtube-api')
const youtube = new YouTube(apiKey)

@@ -13,0 +13,0 @@ ```

@@ -1,8 +0,5 @@

import { google } from 'googleapis'
import { Video, Channel, Playlist } from './entities'
import { parseUrl } from './util'
import { parseUrl, request } from './util'
export * from './entities'
const youtube = google.youtube('v3')
/**

@@ -27,6 +24,6 @@ * The main class used to interact with the YouTube API. Use this.

const { data: results } = await youtube.search.list({
const results = await request.api('search', {
q: searchTerm,
maxResults,
auth: this.token,
key: this.token,
part: 'snippet',

@@ -39,8 +36,14 @@ type

results.items.forEach(item => {
if (type === 'video') {
items.push(new Video(this, item))
} else if (type === 'channel') {
items.push(new Channel(this, item))
} else if (type === 'playlist') {
items.push(new Playlist(this, item))
switch (type) {
case 'video':
items.push(new Video(this, item))
break
case 'channel':
items.push(new Channel(this, item))
break
case 'playlist':
items.push(new Playlist(this, item))
break
default:
throw new Error('Type must be a video, channel, or playlist')
}

@@ -56,19 +59,19 @@ })

if (type === 'video') {
result = (await youtube.videos.list({
result = await request.api('videos', {
id,
part: 'snippet,contentDetails,statistics,status',
auth: this.token
})).data
key: this.token
})
} else if (type === 'channel') {
result = (await youtube.channels.list({
result = await request.api('channels', {
id,
part: 'snippet,contentDetails,statistics,status',
auth: this.token
})).data
key: this.token
})
} else if (type === 'playlist') {
result = (await youtube.playlists.list({
result = await request.api('playlists', {
id,
part: 'snippet,contentDetails,player',
auth: this.token
})).data
key: this.token
})
}

@@ -195,8 +198,8 @@

let { data: results } = await youtube.playlistItems.list({
const results = await request.api('playlistItems', {
playlistId,
part: 'snippet',
auth: this.token,
key: this.token,
maxResults: full ? 50 : maxResults
}).catch(error => {
}).catch(() => {
return Promise.reject('Playlist not found')

@@ -219,7 +222,7 @@ })

for (let i = 0; i < pages; i++) {
const { data: newResults } = await youtube.playlistItems.list({
for (let i = 1; i < pages; i++) {
const newResults = await request.api('playlistItems', {
playlistId,
part: 'snippet',
auth: this.token,
key: this.token,
maxResults: 50,

@@ -230,3 +233,3 @@ pageToken: oldRes.nextPageToken

oldRes = newResults
newResults.items.forEach((item) => {
newResults.items.forEach(item => {
videos.push(new Video(this, item))

@@ -233,0 +236,0 @@ })

export * from './util'
export * from './request'

@@ -69,5 +69,5 @@ import 'mocha'

it('should return an array with a length of <= 50 if maxResults is <= 50', async () => {
it('should return an array with a length of <= maxResults', async () => {
const youtube = new YouTube(apiKey)
expect((await youtube.getPlaylistItems('PLMC9KNkIncKvYin_USF1qoJQnIyMAfRxl', 2)).length).to.be.lessThan(51)
expect((await youtube.getPlaylistItems('PLMC9KNkIncKvYin_USF1qoJQnIyMAfRxl', 2)).length).to.be.lessThan(3)
})

@@ -74,0 +74,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc