-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathrun.js
More file actions
43 lines (36 loc) · 1.15 KB
/
Copy pathrun.js
File metadata and controls
43 lines (36 loc) · 1.15 KB
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
36
37
38
39
40
41
42
43
var youtube = require("youtube-api");
var ytdl = require("ytdl-core");
var fs = require("fs");
function pullPlayListRecursive (playlistId, fileName, callStackSize, pageToken){
youtube.playlistItems.list({
part:"snippet",
pageToken: pageToken,
maxResults:50,
playlistId:playlistId
}, function(err, data){
if (err) return console.log("error");
for (var x in data.items){
var test = "https://www.youtube.com/watch?v=" +
data.items[x].snippet.resourceId.videoId;
var y = parseInt(x) + callStackSize*50
ytdl(test,
{
filter: function(format) {
return format.container === 'mp4' && format.resolution == null && format.audioBitrate == 128;
}
}
).pipe(fs.createWriteStream(fileName + y +'.mp3'));
}
if (data.nextPageToken){
pullPlayListRecursive(playlistId, fileName, callStackSize+1, data.nextPageToken);
}
});
}
exports.pullPlaylist = function (apiKey, playlistId, fileName){
youtube.authenticate({
type: "key",
key: apiKey
});
pullPlayListRecursive(playlistId, fileName, 0, null);
}
// pullPlayList("playlist id here", "name of mp3 here");