Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Move formatDuration to util.js
Browse files Browse the repository at this point in the history
  • Loading branch information
jaimeMF committed Feb 12, 2015
1 parent 4ecda89 commit c309c24
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
20 changes: 20 additions & 0 deletions lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,23 @@ exports.getHumanTime = function(ms) {

return str + ms + ' ms';
};

/**
* Converts seconds to format hh:mm:ss
*
* @param {Number} seconds
* @return {String}
*/
exports.formatDuration = function(seconds) {
var parts = [];
parts.push(seconds % 60);
var minutes = Math.floor(seconds / 60);
if (minutes > 0) {
parts.push(minutes % 60)
var hours = Math.floor(minutes / 60);
if (hours > 0) {
parts.push(hours);
}
}
return parts.reverse().join(':');
};
15 changes: 1 addition & 14 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,10 @@ function call(video, args1, args2, options, callback) {
*/
function filterData(data) {
var info = JSON.parse(data);
function formatDuration(duration) {
var parts = [];
parts.push(duration % 60);
var minutes = Math.floor(duration / 60);
if (minutes > 0) {
parts.push(minutes % 60)
var hours = Math.floor(minutes / 60);
if (hours > 0) {
parts.push(hours);
}
}
return parts.reverse().join(':');
}

// Add and process some entries to keep backwards compatibility
info.filename = info._filename;
info.duration = formatDuration(info.duration);
info.duration = util.formatDuration(info.duration);
info.itag = info.format_id;
info.resolution = info.format.split(' - ')[1];
return info;
Expand Down

0 comments on commit c309c24

Please sign in to comment.