youtube-mp3-downloader
Advanced tools
Comparing version 0.2.0 to 0.3.0
@@ -25,5 +25,5 @@ "use strict"; | ||
//Async download/transcode queue | ||
self.downloadQueue = async.queue(function (videoId, callback) { | ||
self.downloadQueue = async.queue(function (task, callback) { | ||
self.performDownload(videoId, function(err, result) { | ||
self.performDownload(task, function(err, result) { | ||
callback(err, result); | ||
@@ -38,7 +38,11 @@ }); | ||
YoutubeMp3Downloader.prototype.download = function(videoId) { | ||
YoutubeMp3Downloader.prototype.download = function(videoId, fileName) { | ||
var self = this; | ||
var task = { | ||
videoId: videoId, | ||
fileName: fileName | ||
}; | ||
self.downloadQueue.push(videoId, function (err, data) { | ||
self.downloadQueue.push(task, function (err, data) { | ||
if (err) { | ||
@@ -53,6 +57,6 @@ self.emit("error", err); | ||
YoutubeMp3Downloader.prototype.performDownload = function(videoId, cb) { | ||
YoutubeMp3Downloader.prototype.performDownload = function(task, cb) { | ||
var self = this; | ||
var videoUrl = self.youtubeBaseUrl+videoId; | ||
var videoUrl = self.youtubeBaseUrl+task.videoId; | ||
@@ -75,4 +79,6 @@ ytdl.getInfo(videoUrl, function(err, info){ | ||
var fileName = self.outputPath + '/' + videoTitle + '.mp3'; | ||
//Derive file name, if given, use it, if not, from video title | ||
var fileName = (task.fileName ? self.outputPath + '/' + task.fileName : self.outputPath + '/' + videoTitle + '.mp3'); | ||
//Stream setup | ||
var stream = ytdl(videoUrl, { | ||
@@ -101,11 +107,8 @@ quality: self.youtubeVideoQuality | ||
} | ||
self.emit("progress", {videoId: videoId, progress: progress}) | ||
self.emit("progress", {videoId: task.videoId, progress: progress}) | ||
}); | ||
//Pipe through progress module | ||
var videoStream = stream.pipe(str); | ||
//Start encoding | ||
var proc = new ffmpeg({ | ||
source: videoStream | ||
source: stream.pipe(str) | ||
}) | ||
@@ -123,3 +126,3 @@ .audioBitrate(info.formats[0].audioBitrate) | ||
resultObj.file = fileName; | ||
resultObj.videoId = videoId; | ||
resultObj.videoId = task.videoId; | ||
resultObj.youtubeUrl = videoUrl; | ||
@@ -126,0 +129,0 @@ resultObj.videoTitle = videoTitle; |
{ | ||
"name": "youtube-mp3-downloader", | ||
"version": "0.2.0", | ||
"version": "0.3.0", | ||
"description": "Downloads Youtube videos (in parallel, as streams), encodes the audio data as mp3 and stores them in a defineable location", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -51,2 +51,26 @@ # Youtube MP3 Downloader | ||
You can also pass a file name for the respective video, which will then be used. Otherwise, the file name will be derived from the video title. | ||
``` | ||
YD.download("rnkuRQ8tjIE", "Nancy Sinatra - Jackson.mp3"); | ||
``` | ||
While downloading, every `progressTimeout` timeframe, there will be an `progress` event triggered, outputting an object like | ||
``` | ||
{ | ||
"videoId": "rnkuRQ8tjIE", | ||
"progress": { | ||
"percentage": 76.81, | ||
"transferred": 5619680, | ||
"length": "7315910", | ||
"remaining": 1696230, | ||
"eta": 3, | ||
"runtime": 8, | ||
"delta": 1834992, | ||
"speed": 661138.82 | ||
} | ||
} | ||
``` | ||
Upon finish, the following output will be returned: | ||
@@ -53,0 +77,0 @@ |
9735
107
91