Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction to: Percentage and Download #102

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions lib/YoutubeMp3Downloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,20 @@ class YoutubeMp3Downloader extends EventEmitter {
stream.on('error', function(err){
callback(err, null);
});

stream.on('response', function(httpResponse) {

let exec_one = (httpResponse)=>{
exec_one = (httpResponse)=>{return}

let file_length = parseInt(httpResponse.headers['content-length']);
if(httpResponse.headers['content-range']){
file_length = parseInt(httpResponse.headers['content-range'].split('/')[1])
}
// Setup of progress module
const str = progress({
length: parseInt(httpResponse.headers['content-length']),
length: file_length,
time: self.progressTimeout
});

// Add progress event listener
str.on('progress', function(progress) {
if (progress.percentage === 100) {
Expand Down Expand Up @@ -157,7 +163,13 @@ class YoutubeMp3Downloader extends EventEmitter {
return callback(null, resultObj);
})
.saveToFile(fileName);
}

//also called for reconnections
stream.on('response', function(httpResponse) {
exec_one(httpResponse);
});

};
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
"url": "https://github.com/ytb2mp3/youtube-mp3-downloader/issues"
},
"types": "./typings/index.d.ts"
}
}