-
Notifications
You must be signed in to change notification settings - Fork 4
/
run.js
36 lines (28 loc) · 913 Bytes
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var youtube = require('youtube-api');
var fs = require('fs');
function channelVideosRecursive(channelId, callStackSize, pageToken, currentItems, callback) {
youtube.search.list({
type: 'video',
part: 'snippet',
pageToken: pageToken,
maxResults: 50,
channelId: channelId,
}, function(err, data) {
if (err) return console.log('error: ' + err);
for (var x in data.items) {
currentItems.push(data.items[x]);
}
if (data.nextPageToken) {
channelVideosRecursive(channelId, callStackSize + 1, data.nextPageToken, currentItems, callback);
} else {
callback(currentItems);
}
});
}
exports.channelVideos = function(apiKey, channelId, done) {
youtube.authenticate({
type: 'key',
key: apiKey,
});
channelVideosRecursive(channelId, 0, null, [], done);
};