├── README.md ├── package.json ├── LICENSE └── run.js /README.md: -------------------------------------------------------------------------------- 1 | # PullPlaylist # 2 | 3 | pullPlaylist is a small library that downloads all the videos in a particular Youtube Playlist and converts them into mp3 for audio consumption. 4 | 5 | 6 | ### Install ### 7 | ``` 8 | npm install pullplaylist 9 | 10 | ``` 11 | 12 | ### Usage ### 13 | ``` 14 | var ppl = require('pullplaylist'); 15 | ppl.pullplaylist("YOUR_YOUTUBE_API_KEY", "PLAYLIST_ID", "audioFile" ); 16 | ``` 17 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pullplaylist", 3 | "description": "Youtube video downloader in pure javascript.", 4 | "keywords": [ 5 | "youtube", 6 | "video", 7 | "download" 8 | ], 9 | "version": "0.1.0", 10 | "repository": { 11 | "type": "git", 12 | "url": "git://github.com/sameid/pullplaylist.git" 13 | }, 14 | "author": "Sameid Usmani (http://sameidusmani.com)", 15 | "main": "run.js", 16 | "dependencies": { 17 | "ytdl-core": "*", 18 | "youtube-api": "*" 19 | }, 20 | "licenses": [ 21 | { 22 | "type": "MIT", 23 | "url": "http://github.com/sameid/pullplaylist/raw/master/LICENSE" 24 | } 25 | ], 26 | "bugs": { 27 | "url": "https://github.com/sameid/pullplaylist/issues" 28 | }, 29 | "homepage": "https://github.com/sameid/pullplaylist", 30 | "devDependencies": {}, 31 | "scripts": { 32 | "test": "echo \"Error: no test specified\" && exit 1" 33 | }, 34 | "license": "MIT" 35 | } 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (C) 2012 by Sameid Usmani 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /run.js: -------------------------------------------------------------------------------- 1 | var youtube = require("youtube-api"); 2 | var ytdl = require("ytdl-core"); 3 | var fs = require("fs"); 4 | 5 | function pullPlayListRecursive (playlistId, fileName, callStackSize, pageToken){ 6 | youtube.playlistItems.list({ 7 | part:"snippet", 8 | pageToken: pageToken, 9 | maxResults:50, 10 | playlistId:playlistId 11 | }, function(err, data){ 12 | if (err) return console.log("error"); 13 | for (var x in data.items){ 14 | var test = "https://www.youtube.com/watch?v=" + 15 | data.items[x].snippet.resourceId.videoId; 16 | var y = parseInt(x) + callStackSize*50 17 | ytdl(test, 18 | { 19 | filter: function(format) { 20 | return format.container === 'mp4' && format.resolution == null && format.audioBitrate == 128; 21 | } 22 | } 23 | ).pipe(fs.createWriteStream(fileName + y +'.mp3')); 24 | } 25 | 26 | if (data.nextPageToken){ 27 | pullPlayListRecursive(playlistId, fileName, callStackSize+1, data.nextPageToken); 28 | } 29 | }); 30 | } 31 | 32 | 33 | exports.pullPlaylist = function (apiKey, playlistId, fileName){ 34 | 35 | youtube.authenticate({ 36 | type: "key", 37 | key: apiKey 38 | }); 39 | 40 | pullPlayListRecursive(playlistId, fileName, 0, null); 41 | } 42 | 43 | // pullPlayList("playlist id here", "name of mp3 here"); 44 | --------------------------------------------------------------------------------