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

Commit

Permalink
add hms to duration, twitch test
Browse files Browse the repository at this point in the history
  • Loading branch information
przemyslawpluta committed Sep 29, 2017
1 parent 88ec7c8 commit 9ea3ff1
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
1 change: 1 addition & 0 deletions example/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ ytdl.getInfo(url, function(err, info) {
console.log('description:', info.description);
console.log('filename:', info._filename);
console.log('duration:', info.duration);
console.log('duration_hms:', info.duration_hms);
console.log('format_id:', info.format_id);
});
7 changes: 6 additions & 1 deletion lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var http = require('http');
var streamify = require('streamify');
var request = require('request');
var util = require('./util');
var hms = require('hh-mm-ss');

var detailsPath = path.join(__dirname, '..', 'bin/details'),
ytdlBinary;
Expand Down Expand Up @@ -245,7 +246,10 @@ function parseInfo(data) {
return info.format.split(' - ')[1];
}
});
info.duration = util.formatDuration(info.duration);

info.duration_hms = (info.duration) ? hms.fromS(info.duration, 'hh:mm:ss') : info.duration;
info.duration = (info.duration) ? util.formatDuration(info.duration) : info.duration;

return info;
}

Expand Down Expand Up @@ -280,6 +284,7 @@ ytdl.getInfo = function getInfo(url, args, options, callback) {
call(url, defaultArgs, args, options, function done(err, data) {
if (err) { return callback(err); }
var info;

try {
info = data.map(parseInfo);
} catch (err) {
Expand Down
15 changes: 14 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"test": "vows ./test/*.js --spec"
},
"dependencies": {
"hh-mm-ss": "^1.2.0",
"mkdirp": "^0.5.1",
"request": "^2.83.0",
"streamify": "^0.2.9"
Expand All @@ -34,4 +35,4 @@
"vows": "*"
},
"license": "MIT"
}
}
21 changes: 19 additions & 2 deletions test/getInfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ vows.describe('getInfo').addBatch({
'This is also the original I find it hilarious that there are copycat videos!');
assert.equal(info._filename, 'lol-90AiXO1pAiA.mp4');
assert.equal(info.format, '18 - 480x360 (medium)');
assert.equal(info.duration_hms, '00:00:11');
assert.equal(info.duration, '11');
assert.equal(info.width, 480);
assert.equal(info.height, 360);
Expand Down Expand Up @@ -111,6 +112,7 @@ vows.describe('getInfo').addBatch({
assert.equal(info._filename,
'OWEN - good friends, bad habits-6586873.mp4');
assert.equal(info.format, 'http-360p - 480x272');
assert.equal(info.duration_hms, '00:03:55');
assert.equal(info.duration, '3:55');
}
},
Expand All @@ -120,14 +122,15 @@ vows.describe('getInfo').addBatch({
'use strict';
var vimeo = 'https://vimeo.com/6586873';
var youtube = 'http://www.youtube.com/watch?v=90AiXO1pAiA';
ytdl.getInfo([vimeo, youtube], ['--no-warnings'], this.callback);
var twitch = 'https://clips.twitch.tv/RelentlessOptimisticPterodactylRitzMitz';
ytdl.getInfo([vimeo, youtube, twitch], ['--no-warnings'], this.callback);
},

'info returned': function(err, info) {
'use strict';
assert.isNull(err);
assert.isArray(info);
assert.equal(info.length, 2);
assert.equal(info.length, 3);
assert.equal(info[0].id, '6586873');
assert.equal(info[0].title, 'OWEN - good friends, bad habits');
assert.isString(info[0].url);
Expand All @@ -139,6 +142,7 @@ vows.describe('getInfo').addBatch({
assert.equal(info[0]._filename,
'OWEN - good friends, bad habits-6586873.mp4');
assert.equal(info[0].format, 'http-360p - 480x272');
assert.equal(info[0].duration_hms, '00:03:55');
assert.equal(info[0].duration, '3:55');
assert.equal(info[1].id, '90AiXO1pAiA');
assert.equal(info[1].format_id, '43');
Expand All @@ -151,10 +155,23 @@ vows.describe('getInfo').addBatch({
'This is also the original I find it hilarious that there are copycat videos!');
assert.equal(info[1]._filename, 'lol-90AiXO1pAiA.webm');
assert.equal(info[1].format, '43 - 640x360 (medium)');
assert.equal(info[1].duration_hms, '00:00:11');
assert.equal(info[1].duration, '11');
assert.equal(info[1].width, 640);
assert.equal(info[1].height, 360);
assert.isArray(info[1].formats);
assert.equal(info[2].id, 'RelentlessOptimisticPterodactylRitzMitz');
assert.equal(info[2].format_id, '1080');
assert.equal(info[2].title, 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor');
assert.isString(info[2].url);
assert.isString(info[2].thumbnail);
assert.equal(info[2].fulltitle, 'Worlds 2017 Play-In: Rampage vs. 1907 Fenerbahçe Espor');
assert.equal(info[2]._filename, 'Worlds 2017 Play-In - Rampage vs. 1907 Fenerbahçe Espor-RelentlessOptimisticPterodactylRitzMitz.mp4');
assert.equal(info[2].format, '1080 - 1080p');
assert.equal(info[2].height, 1080);
assert.equal(info[2].duration_hms, undefined);
assert.equal(info[2].duration, undefined);
assert.isArray(info[2].formats);
}
}
}).export(module);

0 comments on commit 9ea3ff1

Please sign in to comment.