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

Commit

Permalink
support non-youtube (speificially vimeo) videos. fixes #39
Browse files Browse the repository at this point in the history
  • Loading branch information
fent committed Aug 17, 2014
1 parent f9c0c8f commit cd6938b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 35 deletions.
32 changes: 15 additions & 17 deletions lib/youtube-dl.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,21 @@ function call(video, args1, args2, options, callback) {
var args = args1.concat(util.parseOpts(args2));
options = options || {};

// Parse url.
var details = url.parse(video, true);
var query = details.query;

// Get possible IDs.
var id = query.v || '';

// Check for long and short youtube video url.
if (!id && isYouTubeRegex.test(video)) {
// Get possible IDs for youtu.be from urladdr.
id = details.pathname.slice(1).replace(/^v\//, '');
}

if (id === 'playlist') {
args.push(video);
if (isYouTubeRegex.test(video)) {
// Get possible IDs.
var details = url.parse(video, true);
var id = details.query.v || '';
if (id) {
args.push('http://www.youtube.com/watch?v=' + id);
} else {
// Get possible IDs for youtu.be from urladdr.
id = details.pathname.slice(1).replace(/^v\//, '');
if (id === 'playlist') {
args.push(video);
}
}
} else {
args.push('http://www.youtube.com/watch?v=' + id);
args.push(video);
}

var opt = [file, args];
Expand Down Expand Up @@ -153,7 +151,7 @@ function filterData(data) {
}


var resolutionRegex = /([0-9]+ - ([0-9]+x[0-9]+|\d+p))/;
var resolutionRegex = /( - ([0-9]+x[0-9]+|\d+p))/;

/**
* Gets info from a video.
Expand Down
52 changes: 34 additions & 18 deletions test/getInfo.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,52 @@
var vows = require('vows');
var ytdl = require('..');
var assert = require('assert');
var video = 'http://www.youtube.com/watch?v=90AiXO1pAiA';


var expected = {
title: 'lol',
id: '90AiXO1pAiA',
thumbnail: 'https://i1.ytimg.com/vi/90AiXO1pAiA/hqdefault.jpg',
description: 'Ridley High School\'s real American Bad ASS,A true Delco Savage. Filmed in 2003 before Youtube was invented. This is also the original I find it hilarious that there are copycat videos!',
filename: 'lol-90AiXO1pAiA.mp4',
itag: '18',
resolution: '640x360'
};

vows.describe('getInfo').addBatch({
'from a video': {
'from a youtube video': {
'topic': function() {
var video = 'http://www.youtube.com/watch?v=90AiXO1pAiA';
ytdl.getInfo(video, ['-f', '18/22/37/38'], this.callback);
},

'info returned': function(err, info) {
assert.isNull(err);
assert.isObject(info);
assert.equal(info.id, expected.id);
assert.equal(info.itag, expected.itag);
assert.equal(info.title, expected.title);
assert.equal(info.id, '90AiXO1pAiA');
assert.equal(info.itag, '18');
assert.equal(info.title, 'lol');
assert.isString(info.url);
assert.isString(info.thumbnail);
assert.equal(info.description,
'Ridley High School\'s real American Bad ASS,A true Delco Savage. ' +
'Filmed in 2003 before Youtube was invented. ' +
'This is also the original I find it hilarious that there ' +
'are copycat videos!');
assert.equal(info.filename, 'lol-90AiXO1pAiA.mp4');
assert.equal(info.resolution, '640x360');
}
},
'from a vimeo video': {
'topic': function() {
var video = 'https://vimeo.com/6586873';
ytdl.getInfo(video, this.callback);
},

'info returned': function(err, info) {
assert.isNull(err);
assert.isObject(info);
assert.equal(info.id, '6586873');
assert.equal(info.title, 'OWEN - good friends, bad habits');
assert.isString(info.url);
assert.isString(info.thumbnail);
assert.equal(info.description, expected.description);
assert.equal(info.filename, expected.filename);
assert.equal(info.resolution, expected.resolution);
assert.equal(info.description,
'Video for the song "Good Friends, Bad Habits" from the album ' +
'New Leaves. Directed by Joe Wigdahl. Purchase the album here: ' +
'hobbledehoyrecords.com/store');
assert.equal(info.filename,
'OWEN - good friends, bad habits-6586873.mp4');
assert.equal(info.resolution, '480x272');
}
}
}).export(module);

0 comments on commit cd6938b

Please sign in to comment.