better-youtube-api
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -136,10 +136,43 @@ "use strict"; | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const { data: results } = yield youtube.playlistItems.list({ | ||
let { data: results } = yield youtube.playlistItems.list({ | ||
playlistId, | ||
part: 'snippet', | ||
auth: this.token | ||
auth: this.token, | ||
maxResults: 50 | ||
}); | ||
let oldRes; | ||
let videos = []; | ||
for (let i = 0; i < results.items.length; i++) { | ||
videos.push(new entities_1.Video(this, results.items[i])); | ||
results.items.forEach(item => { | ||
videos.push(new entities_1.Video(this, item)); | ||
}); | ||
while (true) { | ||
if (!results.nextPageToken) { | ||
break; | ||
} | ||
let newResults; | ||
if (!oldRes) { | ||
newResults = (yield youtube.playlistItems.list({ | ||
playlistId, | ||
part: 'snippet', | ||
auth: this.token, | ||
maxResults: 50, | ||
pageToken: results.nextPageToken | ||
})).data; | ||
} | ||
else { | ||
newResults = (yield youtube.playlistItems.list({ | ||
playlistId, | ||
part: 'snippet', | ||
auth: this.token, | ||
maxResults: 50, | ||
pageToken: oldRes.nextPageToken | ||
})).data; | ||
} | ||
oldRes = newResults; | ||
newResults.items.forEach((item) => { | ||
videos.push(new entities_1.Video(this, item)); | ||
}); | ||
if (!oldRes.nextPageToken) { | ||
break; | ||
} | ||
} | ||
@@ -146,0 +179,0 @@ return videos; |
{ | ||
"name": "better-youtube-api", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Better than simple ones.", | ||
@@ -5,0 +5,0 @@ "main": "out/index.js", |
@@ -1,2 +0,2 @@ | ||
import { google } from 'googleapis' | ||
import { google, youtube_v3 } from 'googleapis' | ||
import { Video, Channel, Playlist } from './entities' | ||
@@ -138,12 +138,49 @@ import axios from 'axios' | ||
public async getPlaylistItems (playlistId: string) { | ||
const { data: results } = await youtube.playlistItems.list({ | ||
let { data: results } = await youtube.playlistItems.list({ | ||
playlistId, | ||
part: 'snippet', | ||
auth: this.token | ||
auth: this.token, | ||
maxResults: 50 | ||
}) | ||
let oldRes: youtube_v3.Schema$PlaylistItemListResponse | ||
let videos: Video[] = [] | ||
for (let i = 0; i < results.items.length; i++) { | ||
videos.push(new Video(this, results.items[i])) | ||
results.items.forEach(item => { | ||
videos.push(new Video(this, item)) | ||
}) | ||
while (true) { | ||
if (!results.nextPageToken) { | ||
break | ||
} | ||
let newResults: youtube_v3.Schema$PlaylistItemListResponse | ||
if (!oldRes) { | ||
newResults = (await youtube.playlistItems.list({ | ||
playlistId, | ||
part: 'snippet', | ||
auth: this.token, | ||
maxResults: 50, | ||
pageToken: results.nextPageToken | ||
})).data | ||
} else { | ||
newResults = (await youtube.playlistItems.list({ | ||
playlistId, | ||
part: 'snippet', | ||
auth: this.token, | ||
maxResults: 50, | ||
pageToken: oldRes.nextPageToken | ||
})).data | ||
} | ||
oldRes = newResults | ||
newResults.items.forEach((item) => { | ||
videos.push(new Video(this, item)) | ||
}) | ||
if (!oldRes.nextPageToken) { | ||
break | ||
} | ||
} | ||
@@ -150,0 +187,0 @@ |
Sorry, the diff of this file is not supported yet
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
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
45940
1064