better-youtube-api
Advanced tools
Comparing version 0.1.1 to 0.1.2
@@ -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 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57237
0
23
1617
1
- Removedgoogleapis@^32.0.0
- Removedabort-controller@3.0.0(transitive)
- Removedagent-base@4.3.0(transitive)
- Removedaxios@0.18.1(transitive)
- Removedbuffer-equal-constant-time@1.0.1(transitive)
- Removedcall-bind@1.0.7(transitive)
- Removeddefine-data-property@1.1.4(transitive)
- Removedecdsa-sig-formatter@1.0.11(transitive)
- Removedes-define-property@1.0.0(transitive)
- Removedes-errors@1.3.0(transitive)
- Removedes6-promise@4.2.8(transitive)
- Removedes6-promisify@5.0.0(transitive)
- Removedevent-target-shim@5.0.1(transitive)
- Removedextend@3.0.2(transitive)
- Removedfollow-redirects@1.5.10(transitive)
- Removedfunction-bind@1.1.2(transitive)
- Removedgaxios@1.8.4(transitive)
- Removedgcp-metadata@0.6.3(transitive)
- Removedget-intrinsic@1.2.4(transitive)
- Removedgoogle-auth-library@1.6.1(transitive)
- Removedgoogle-p12-pem@1.0.5(transitive)
- Removedgoogleapis@32.0.0(transitive)
- Removedgopd@1.0.1(transitive)
- Removedgtoken@2.3.3(transitive)
- Removedhas-property-descriptors@1.0.2(transitive)
- Removedhas-proto@1.0.3(transitive)
- Removedhas-symbols@1.0.3(transitive)
- Removedhasown@2.0.2(transitive)
- Removedhttps-proxy-agent@2.2.4(transitive)
- Removedis-buffer@2.0.5(transitive)
- Removedjwa@1.4.1(transitive)
- Removedjws@3.2.2(transitive)
- Removedlodash.isstring@4.0.1(transitive)
- Removedlru-cache@4.1.5(transitive)
- Removedmime@2.6.0(transitive)
- Removednode-fetch@2.7.0(transitive)
- Removednode-forge@0.10.0(transitive)
- Removedobject-inspect@1.13.3(transitive)
- Removedpify@3.0.04.0.1(transitive)
- Removedpseudomap@1.0.2(transitive)
- Removedqs@6.13.1(transitive)
- Removedretry-axios@0.3.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedset-function-length@1.2.2(transitive)
- Removedside-channel@1.0.6(transitive)
- Removedtr46@0.0.3(transitive)
- Removedurl-template@2.0.8(transitive)
- Removeduuid@3.4.0(transitive)
- Removedwebidl-conversions@3.0.1(transitive)
- Removedwhatwg-url@5.0.0(transitive)
- Removedyallist@2.1.2(transitive)