better-youtube-api
Advanced tools
Comparing version 0.0.6 to 0.0.7
@@ -209,30 +209,21 @@ "use strict"; | ||
} | ||
let oldRes; | ||
let oldRes = results; | ||
let videos = []; | ||
const totalResults = results.pageInfo.totalResults; | ||
const perPage = 50; | ||
const pages = Math.floor(totalResults / perPage); | ||
results.items.forEach(item => { | ||
videos.push(new entities_1.Video(this, item)); | ||
}); | ||
const interval = setInterval(() => __awaiter(this, void 0, void 0, function* () { | ||
if (!results.nextPageToken || !oldRes.nextPageToken) { | ||
clearInterval(interval); | ||
} | ||
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; | ||
} | ||
if (pages === 0) { | ||
return videos; | ||
} | ||
for (let i = 0; i < pages; i++) { | ||
const { data: newResults } = yield youtube.playlistItems.list({ | ||
playlistId, | ||
part: 'snippet', | ||
auth: this.token, | ||
maxResults: 50, | ||
pageToken: oldRes.nextPageToken | ||
}); | ||
oldRes = newResults; | ||
@@ -242,3 +233,3 @@ newResults.items.forEach((item) => { | ||
}); | ||
}), 1); | ||
} | ||
return videos; | ||
@@ -245,0 +236,0 @@ }); |
{ | ||
"name": "better-youtube-api", | ||
"version": "0.0.6", | ||
"version": "0.0.7", | ||
"description": "Better than simple ones.", | ||
@@ -5,0 +5,0 @@ "main": "out/index.js", |
@@ -226,4 +226,7 @@ import { google, youtube_v3 } from 'googleapis' | ||
let oldRes: youtube_v3.Schema$PlaylistItemListResponse | ||
let oldRes: youtube_v3.Schema$PlaylistItemListResponse = results | ||
let videos: Video[] = [] | ||
const totalResults = results.pageInfo.totalResults | ||
const perPage = 50 | ||
const pages = Math.floor(totalResults / perPage) | ||
@@ -234,27 +237,15 @@ results.items.forEach(item => { | ||
const interval = setInterval(async () => { | ||
if (!results.nextPageToken || !oldRes.nextPageToken) { | ||
clearInterval(interval) | ||
} | ||
if (pages === 0) { | ||
return videos | ||
} | ||
let newResults: youtube_v3.Schema$PlaylistItemListResponse | ||
for (let i = 0; i < pages; i++) { | ||
const { data: newResults } = await youtube.playlistItems.list({ | ||
playlistId, | ||
part: 'snippet', | ||
auth: this.token, | ||
maxResults: 50, | ||
pageToken: oldRes.nextPageToken | ||
}) | ||
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 | ||
@@ -264,3 +255,3 @@ newResults.items.forEach((item) => { | ||
}) | ||
}, 1) | ||
} | ||
@@ -267,0 +258,0 @@ return videos |
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
59052
1284