js-video-url-parser
Advanced tools
Comparing version 0.1.6 to 0.2.0
@@ -1,40 +0,57 @@ | ||
function URLParser() { | ||
"use strict"; | ||
function UrlParser() { | ||
'use strict'; | ||
this.plugins = {}; | ||
} | ||
URLParser.prototype.parse = function (url) { | ||
"use strict"; | ||
var th = this, | ||
match = url.match(/(?:(?:https?:)?\/\/)?(?:[^\.]+\.)?(\w+)\./i), | ||
provider = match ? match[1] : undefined, | ||
result; | ||
if (match && provider && th.plugins[provider] && th.plugins[provider].parse) { | ||
result = th.plugins[provider].parse.call(this, url, getQueryParams(url)); | ||
if (result) { | ||
if (result.params && Object.keys(result.params).length === 0) { | ||
delete result.params; | ||
} | ||
result.provider = th.plugins[provider].provider; | ||
return result; | ||
} | ||
UrlParser.prototype.parseProvider = function (url) { | ||
'use strict'; | ||
var match = url.match( | ||
/(?:(?:https?:)?\/\/)?(?:[^\.]+\.)?(\w+)\./i | ||
); | ||
return match ? match[1] : undefined; | ||
}; | ||
UrlParser.prototype.removeEmptyParameters = function (result) { | ||
'use strict'; | ||
if (result.params && Object.keys(result.params).length === 0) { | ||
delete result.params; | ||
} | ||
return undefined; | ||
return result; | ||
}; | ||
URLParser.prototype.bind = function (plugin) { | ||
"use strict"; | ||
var th = this; | ||
th.plugins[plugin.provider] = plugin; | ||
UrlParser.prototype.parse = function (url) { | ||
'use strict'; | ||
var _this = this; | ||
var provider = _this.parseProvider(url); | ||
var result; | ||
var plugin = _this.plugins[provider]; | ||
if (!provider || !plugin || !plugin.parse) { | ||
return undefined; | ||
} | ||
result = plugin.parse.apply( | ||
plugin, [url, getQueryParams(url)] | ||
); | ||
if (result) { | ||
result = _this.removeEmptyParameters(result); | ||
result.provider = plugin.provider; | ||
} | ||
return result; | ||
}; | ||
UrlParser.prototype.bind = function (plugin) { | ||
'use strict'; | ||
this.plugins[plugin.provider] = plugin; | ||
if (plugin.alternatives) { | ||
for (var i = 0; i < plugin.alternatives.length; i += 1) { | ||
th.plugins[plugin.alternatives[i]] = plugin; | ||
this.plugins[plugin.alternatives[i]] = plugin; | ||
} | ||
} | ||
}; | ||
URLParser.prototype.create = function (op) { | ||
"use strict"; | ||
var th = this, | ||
vi = op.videoInfo, | ||
params = op.params, | ||
plugin = th.plugins[vi.provider]; | ||
UrlParser.prototype.create = function (op) { | ||
'use strict'; | ||
var vi = op.videoInfo; | ||
var params = op.params; | ||
var plugin = this.plugins[vi.provider]; | ||
params = (params === 'internal') ? vi.params : params || {}; | ||
@@ -45,3 +62,3 @@ | ||
if (plugin.formats.hasOwnProperty(op.format)) { | ||
return plugin.formats[op.format](vi, cloneObject(params)); | ||
return plugin.formats[op.format].apply(plugin, [vi, cloneObject(params)]); | ||
} | ||
@@ -51,3 +68,3 @@ } | ||
}; | ||
var urlParser = new URLParser(); | ||
var urlParser = new UrlParser(); | ||
@@ -61,3 +78,3 @@ if (typeof module !== 'undefined' && typeof module.exports !== 'undefined') { | ||
/*jshint unused:true */ | ||
"use strict"; | ||
'use strict'; | ||
if (obj === null || typeof obj !== 'object') { | ||
@@ -69,3 +86,5 @@ return obj; | ||
for (var key in obj) { | ||
temp[key] = cloneObject(obj[key]); | ||
if (obj.hasOwnProperty(key)) { | ||
temp[key] = cloneObject(obj[key]); | ||
} | ||
} | ||
@@ -79,3 +98,3 @@ | ||
/*jshint unused:true */ | ||
"use strict"; | ||
'use strict'; | ||
if (typeof qs !== 'string') { | ||
@@ -86,7 +105,9 @@ return {}; | ||
var params = {}, | ||
match = qs.match( | ||
/(?:[\?](?:[^=]+)=(?:[^&#]*)(?:[&](?:[^=]+)=(?:[^&#]*))*(?:[#].*)?)|(?:[#].*)/ | ||
), | ||
split; | ||
var params = {}; | ||
var match = qs.match( | ||
/*jshint ignore:start */ | ||
/(?:[\?](?:[^=]+)=(?:[^&#]*)(?:[&](?:[^=]+)=(?:[^&#]*))*(?:[#].*)?)|(?:[#].*)/ | ||
/*jshint ignore:end */ | ||
); | ||
var split; | ||
@@ -110,3 +131,3 @@ if (match === null) { | ||
/*jshint unused:true */ | ||
"use strict"; | ||
'use strict'; | ||
if (typeof op !== 'object') { | ||
@@ -142,13 +163,12 @@ return ''; | ||
/*jshint unused:true */ | ||
"use strict"; | ||
var totalSeconds = 0, | ||
timeValues = { | ||
's': 1, | ||
'm': 1 * 60, | ||
'h': 1 * 60 * 60, | ||
'd': 1 * 60 * 60 * 24, | ||
'w': 1 * 60 * 60 * 24 * 7 | ||
}, | ||
timePairs; | ||
'use strict'; | ||
var totalSeconds = 0; | ||
var timeValues = { | ||
's': 1, | ||
'm': 1 * 60, | ||
'h': 1 * 60 * 60, | ||
'd': 1 * 60 * 60 * 24, | ||
'w': 1 * 60 * 60 * 24 * 7 | ||
}; | ||
var timePairs; | ||
//is the format 1h30m20s etc | ||
@@ -169,273 +189,641 @@ if (!timeString.match(/^(\d+[smhdw]?)+$/)) { | ||
urlParser.bind({ | ||
'provider': 'dailymotion', | ||
'alternatives': ['dai'], | ||
'parse': function (url, params) { | ||
"use strict"; | ||
var match, | ||
id, | ||
result = { | ||
params: params | ||
}; | ||
function CanalPlus() { | ||
'use strict'; | ||
this.provider = 'canalplus'; | ||
this.defaultFormat = 'embed'; | ||
this.formats = { | ||
embed: this.createEmbedUrl | ||
}; | ||
this.mediaTypes = { | ||
VIDEO: 'video' | ||
}; | ||
} | ||
match = url.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i); | ||
id = match ? match[1] : undefined; | ||
CanalPlus.prototype.parseParameters = function (params) { | ||
'use strict'; | ||
delete params.vid; | ||
return params; | ||
}; | ||
if (params.hasOwnProperty('start')) { | ||
params.start = getTime(params.start); | ||
} | ||
CanalPlus.prototype.parse = function (url, params) { | ||
'use strict'; | ||
var _this = this; | ||
var result = { | ||
mediaType: this.mediaTypes.VIDEO, | ||
id: params.vid | ||
}; | ||
result.params = _this.parseParameters(params); | ||
if (!id) { | ||
return undefined; | ||
} | ||
result.mediaType = 'video'; | ||
result.id = id; | ||
if (!result.id) { | ||
return undefined; | ||
} | ||
return result; | ||
}; | ||
return result; | ||
}, | ||
defaultFormat: 'long', | ||
formats: { | ||
short: function (vi) { | ||
"use strict"; | ||
return 'https://dai.ly/' + vi.id; | ||
}, | ||
long: function (vi, params) { | ||
"use strict"; | ||
return 'https://dailymotion.com/video/' + | ||
vi.id + | ||
combineParams({ | ||
params: params | ||
}); | ||
}, | ||
embed: function (vi, params) { | ||
"use strict"; | ||
return '//www.dailymotion.com/embed/video/' + | ||
vi.id + | ||
combineParams({ | ||
params: params | ||
}); | ||
} | ||
CanalPlus.prototype.createEmbedUrl = function (vi, params) { | ||
'use strict'; | ||
var url = 'http://player.canalplus.fr/embed/'; | ||
params.vid = vi.id; | ||
url += combineParams({ | ||
params: params | ||
}); | ||
return url; | ||
}; | ||
urlParser.bind(new CanalPlus()); | ||
function Coub() { | ||
'use strict'; | ||
this.provider = 'coub'; | ||
this.defaultFormat = 'long'; | ||
this.formats = { | ||
long: this.createLongUrl, | ||
embed: this.createEmbedUrl | ||
}; | ||
this.mediaTypes = { | ||
VIDEO: 'video' | ||
}; | ||
} | ||
Coub.prototype.parseUrl = function (url) { | ||
'use strict'; | ||
var match = url.match( | ||
/(?:embed|view)\/([a-zA-Z\d]+)/i | ||
); | ||
return match ? match[1] : undefined; | ||
}; | ||
Coub.prototype.parse = function (url, params) { | ||
'use strict'; | ||
var result = { | ||
mediaType: this.mediaTypes.VIDEO, | ||
params: params, | ||
id: this.parseUrl(url) | ||
}; | ||
if (!result.id) { | ||
return undefined; | ||
} | ||
// | ||
}); | ||
return result; | ||
}; | ||
urlParser.bind({ | ||
'provider': 'twitch', | ||
'parse': function (url, params) { | ||
"use strict"; | ||
var match, | ||
id, | ||
channel, | ||
idPrefix, | ||
result = {}; | ||
Coub.prototype.createUrl = function (baseUrl, vi, params) { | ||
'use strict'; | ||
var url = baseUrl + vi.id; | ||
url += combineParams({ | ||
params: params | ||
}); | ||
return url; | ||
}; | ||
match = url.match(/twitch\.tv\/(\w+)(?:\/(.)\/(\d+))?/i); | ||
channel = match ? match[1] : undefined; | ||
idPrefix = match ? match[2] : undefined; | ||
id = match ? match[3] : undefined; | ||
Coub.prototype.createLongUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl('https://coub.com/view/', vi, params); | ||
}; | ||
channel = params.channel || params.utm_content || channel; | ||
Coub.prototype.createEmbedUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl('//coub.com/embed/', vi, params); | ||
}; | ||
if (!channel) { | ||
return undefined; | ||
} | ||
if (id) { | ||
result.mediaType = 'video'; | ||
result.id = id; | ||
result.idPrefix = idPrefix; | ||
} else { | ||
result.mediaType = 'stream'; | ||
} | ||
result.channel = channel; | ||
urlParser.bind(new Coub()); | ||
return result; | ||
}, | ||
defaultFormat: 'long', | ||
formats: { | ||
long: function (vi, params) { | ||
"use strict"; | ||
var url = ''; | ||
if (vi.mediaType === 'stream') { | ||
url = 'https://twitch.tv/' + vi.channel; | ||
} else if (vi.mediaType === 'video') { | ||
url = 'https://twitch.tv/' + vi.channel + '/' + vi.idPrefix + '/' + vi.id; | ||
} | ||
url += combineParams({ | ||
params: params | ||
}); | ||
function Dailymotion() { | ||
'use strict'; | ||
this.provider = 'dailymotion'; | ||
this.alternatives = ['dai']; | ||
this.defaultFormat = 'long'; | ||
this.formats = { | ||
short: this.createShortUrl, | ||
long: this.createLongUrl, | ||
embed: this.createEmbedUrl | ||
}; | ||
this.mediaTypes = { | ||
VIDEO: 'video' | ||
}; | ||
} | ||
return url; | ||
}, | ||
embed: function (vi, params) { | ||
"use strict"; | ||
return '//www.twitch.tv/' + | ||
vi.channel + | ||
'/embed' + | ||
combineParams({ | ||
params: params | ||
}); | ||
}, | ||
Dailymotion.prototype.parseParameters = function (params) { | ||
'use strict'; | ||
return this.parseTime(params); | ||
}; | ||
Dailymotion.prototype.parseTime = function (params) { | ||
'use strict'; | ||
if (params.start) { | ||
params.start = getTime(params.start); | ||
} | ||
}); | ||
return params; | ||
}; | ||
urlParser.bind({ | ||
provider: 'vimeo', | ||
alternatives: ['vimeopro'], | ||
parse: function (url, params) { | ||
"use strict"; | ||
var match; | ||
var result = { | ||
mediaType: 'video', | ||
Dailymotion.prototype.parseUrl = function (url) { | ||
'use strict'; | ||
var match = url.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i); | ||
return match ? match[1] : undefined; | ||
}; | ||
Dailymotion.prototype.parse = function (url, params) { | ||
'use strict'; | ||
var _this = this; | ||
var result = { | ||
mediaType: this.mediaTypes.VIDEO, | ||
params: _this.parseParameters(params), | ||
id: _this.parseUrl(url) | ||
}; | ||
return result.id ? result : undefined; | ||
}; | ||
Dailymotion.prototype.createUrl = function (base, vi, params) { | ||
'use strict'; | ||
return base + vi.id + | ||
combineParams({ | ||
params: params | ||
}; | ||
}); | ||
}; | ||
match = url.match( | ||
/(?:\/(?:channels\/[\w]+|(?:(?:album\/\d+|groups\/[\w]+)\/)?videos?))?\/(\d+)/i | ||
); | ||
result.id = match ? match[1] : undefined; | ||
Dailymotion.prototype.createShortUrl = function (vi) { | ||
'use strict'; | ||
return this.createUrl('https://dai.ly/', vi, {}); | ||
}; | ||
if (!result.id) { | ||
return undefined; | ||
} | ||
Dailymotion.prototype.createLongUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl('https://dailymotion.com/video/', vi, params); | ||
}; | ||
if (params.hasOwnProperty('t')) { | ||
params.start = getTime(params.t); | ||
delete params.t; | ||
} | ||
Dailymotion.prototype.createEmbedUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl('//www.dailymotion.com/embed/video/', vi, params); | ||
}; | ||
return result; | ||
}, | ||
defaultFormat: 'long', | ||
formats: { | ||
long: function (vi, params) { | ||
"use strict"; | ||
var url = 'https://vimeo.com/' + vi.id; | ||
var startTime = params.start; | ||
urlParser.bind(new Dailymotion()); | ||
function Twitch() { | ||
'use strict'; | ||
this.provider = 'twitch'; | ||
this.defaultFormat = 'long'; | ||
this.formats = { | ||
long: this.createLongUrl, | ||
embed: this.createEmbedUrl | ||
}; | ||
this.mediaTypes = { | ||
VIDEO: 'video', | ||
STREAM: 'stream', | ||
EMBEDVIDEO: 'embed-video' | ||
}; | ||
} | ||
Twitch.prototype.seperateId = function (id) { | ||
'use strict'; | ||
return { | ||
pre: id[0], | ||
id: id.substr(1) | ||
}; | ||
}; | ||
Twitch.prototype.parseChannel = function (result, params) { | ||
'use strict'; | ||
/*jshint camelcase:false */ | ||
var channel = params.channel || params.utm_content || result.channel; | ||
delete params.utm_content; | ||
/*jshint camelcase:true */ | ||
delete params.channel; | ||
return channel; | ||
}; | ||
Twitch.prototype.parseUrl = function (url, result, params) { | ||
'use strict'; | ||
var match; | ||
match = url.match( | ||
/twitch\.tv\/(\w+)(?:\/(.)\/(\d+))?/i | ||
); | ||
result.channel = match ? match[1] : undefined; | ||
if (match && match[2] && match[3]) { | ||
result.id = match[2] + match[3]; | ||
} else if (params.video) { | ||
result.id = params.video; | ||
delete params.video; | ||
} | ||
return result; | ||
}; | ||
Twitch.prototype.parseMediaType = function (result) { | ||
'use strict'; | ||
var mediaType; | ||
if (result.channel) { | ||
mediaType = result.id ? this.mediaTypes.VIDEO : this.mediaTypes.STREAM; | ||
} else if (result.id) { | ||
mediaType = this.mediaTypes.EMBEDVIDEO; | ||
delete result.channel; | ||
} | ||
return mediaType; | ||
}; | ||
Twitch.prototype.parseParameters = function (params) { | ||
'use strict'; | ||
if (params.t) { | ||
params.start = getTime(params.t); | ||
delete params.t; | ||
} | ||
return params; | ||
}; | ||
Twitch.prototype.parse = function (url, params) { | ||
'use strict'; | ||
var _this = this; | ||
var result = {}; | ||
result = _this.parseUrl(url, result, params); | ||
result.channel = _this.parseChannel(result, params); | ||
result.mediaType = _this.parseMediaType(result); | ||
result.params = _this.parseParameters(params); | ||
return result.channel || result.id ? result : undefined; | ||
}; | ||
Twitch.prototype.createLongUrl = function (vi, params) { | ||
'use strict'; | ||
var url = ''; | ||
if (vi.mediaType === this.mediaTypes.STREAM) { | ||
url = 'https://twitch.tv/' + vi.channel; | ||
} else if (vi.mediaType === this.mediaTypes.VIDEO) { | ||
var sep = this.seperateId(vi.id); | ||
url = 'https://twitch.tv/' + vi.channel + '/' + sep.pre + '/' + sep.id; | ||
if (params.start) { | ||
params.t = params.start + 's'; | ||
delete params.start; | ||
url += combineParams({ | ||
params: params | ||
}); | ||
if (startTime) { | ||
url += '#t=' + startTime; | ||
} | ||
return url; | ||
}, | ||
embed: function (vi, params) { | ||
"use strict"; | ||
var url = '//player.vimeo.com/video/' + vi.id; | ||
var startTime = params.start; | ||
delete params.start; | ||
url += combineParams({ | ||
params: params | ||
}); | ||
if (startTime) { | ||
url += '#t=' + startTime; | ||
} | ||
return url; | ||
} | ||
} | ||
}); | ||
url += combineParams({ | ||
params: params | ||
}); | ||
urlParser.bind({ | ||
'provider': 'youtube', | ||
'alternatives': ['youtu'], | ||
'parse': function (url, params) { | ||
"use strict"; | ||
var match, | ||
id, | ||
list, | ||
result = { | ||
params: params | ||
}; | ||
return url; | ||
}; | ||
match = url.match(/(?:(?:v|be|videos|embed)\/(?!videoseries)|v=)([\w\-]{11})/i); | ||
id = match ? match[1] : undefined; | ||
if (params.v === id) { | ||
delete params.v; | ||
} | ||
Twitch.prototype.createEmbedUrl = function (vi, params) { | ||
'use strict'; | ||
var url = 'https://player.twitch.tv/'; | ||
if (params.list === id) { | ||
delete params.list; | ||
} else { | ||
list = params.list; | ||
if (vi.mediaType === this.mediaTypes.STREAM) { | ||
params.channel = vi.channel; | ||
} else if (vi.mediaType === this.mediaTypes.VIDEO || | ||
vi.mediaType === this.mediaTypes.EMBEDVIDEO) { | ||
params.video = vi.id; | ||
if (params.start) { | ||
params.t = params.start + 's'; | ||
delete params.start; | ||
} | ||
} | ||
if (params.hasOwnProperty('start')) { | ||
params.start = getTime(params.start); | ||
} | ||
if (params.hasOwnProperty('t')) { | ||
params.start = getTime(params.t); | ||
delete params.t; | ||
} | ||
url += combineParams({ | ||
params: params | ||
}); | ||
if (id) { | ||
result.mediaType = 'video'; | ||
result.id = id; | ||
if (list) { | ||
result.list = list; | ||
} | ||
} else if (list) { | ||
result.mediaType = 'playlist'; | ||
result.list = list; | ||
} else { | ||
return undefined; | ||
return url; | ||
}; | ||
urlParser.bind(new Twitch()); | ||
function Vimeo() { | ||
'use strict'; | ||
this.provider = 'vimeo'; | ||
this.alternatives = ['vimeopro']; | ||
this.defaultFormat = 'long'; | ||
this.formats = { | ||
long: this.createLongUrl, | ||
embed: this.createEmbedUrl | ||
}; | ||
this.mediaTypes = { | ||
VIDEO: 'video' | ||
}; | ||
} | ||
Vimeo.prototype.parseUrl = function (url) { | ||
'use strict'; | ||
var match = url.match( | ||
/*jshint ignore:start */ | ||
/(?:\/(?:channels\/[\w]+|(?:(?:album\/\d+|groups\/[\w]+)\/)?videos?))?\/(\d+)/i | ||
/*jshint ignore:end */ | ||
); | ||
return match ? match[1] : undefined; | ||
}; | ||
Vimeo.prototype.parseParameters = function (params) { | ||
'use strict'; | ||
return this.parseTime(params); | ||
}; | ||
Vimeo.prototype.parseTime = function (params) { | ||
'use strict'; | ||
if (params.t) { | ||
params.start = getTime(params.t); | ||
delete params.t; | ||
} | ||
return params; | ||
}; | ||
Vimeo.prototype.parse = function (url, params) { | ||
'use strict'; | ||
var result = { | ||
mediaType: this.mediaTypes.VIDEO, | ||
params: this.parseParameters(params), | ||
id: this.parseUrl(url) | ||
}; | ||
return result.id ? result : undefined; | ||
}; | ||
Vimeo.prototype.createUrl = function (baseUrl, vi, params) { | ||
'use strict'; | ||
var url = baseUrl + vi.id; | ||
var startTime = params.start; | ||
delete params.start; | ||
url += combineParams({ | ||
params: params | ||
}); | ||
if (startTime) { | ||
url += '#t=' + startTime; | ||
} | ||
return url; | ||
}; | ||
Vimeo.prototype.createLongUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl('https://vimeo.com/', vi, params); | ||
}; | ||
Vimeo.prototype.createEmbedUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl('//player.vimeo.com/video/', vi, params); | ||
}; | ||
urlParser.bind(new Vimeo()); | ||
function YouTube() { | ||
'use strict'; | ||
this.provider = 'youtube'; | ||
this.alternatives = ['youtu', 'ytimg']; | ||
this.defaultFormat = 'long'; | ||
this.formats = { | ||
short: this.createShortUrl, | ||
long: this.createLongUrl, | ||
embed: this.createEmbedUrl, | ||
shortImage: this.createShortImageUrl, | ||
longImage: this.createLongImageUrl | ||
}; | ||
this.imageQualities = { | ||
'0': '0', | ||
'1': '1', | ||
'2': '2', | ||
'3': '3', | ||
DEFAULT: 'default', | ||
HQDEFAULT: 'hqdefault', | ||
SDDEFAULT: 'sddefault', | ||
MQDEFAULT: 'mqdefault', | ||
MAXRESDEFAULT: 'maxresdefault', | ||
}; | ||
this.defaultImageQuality = this.imageQualities.HQDEFAULT; | ||
this.mediaTypes = { | ||
VIDEO: 'video', | ||
PLAYLIST: 'playlist', | ||
SHARE: 'share' | ||
}; | ||
} | ||
YouTube.prototype.parseUrl = function (url) { | ||
'use strict'; | ||
var match = url.match( | ||
/(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w\-]{11})/i | ||
); | ||
return match ? match[1] : undefined; | ||
}; | ||
YouTube.prototype.parseTime = function (params) { | ||
'use strict'; | ||
params.start = getTime(params.start || params.t); | ||
delete params.t; | ||
return params; | ||
}; | ||
YouTube.prototype.parseParameters = function (params, result) { | ||
'use strict'; | ||
if (params.start || params.t) { | ||
params.start = getTime(params.start || params.t); | ||
delete params.t; | ||
} | ||
if (params.v === result.id) { | ||
delete params.v; | ||
} | ||
if (params.list === result.id) { | ||
delete params.list; | ||
} | ||
return params; | ||
}; | ||
YouTube.prototype.parseMediaType = function (result) { | ||
'use strict'; | ||
if (result.params.list) { | ||
result.list = result.params.list; | ||
delete result.params.list; | ||
} | ||
if (result.id && !result.params.ci) { | ||
result.mediaType = this.mediaTypes.VIDEO; | ||
} else if (result.list) { | ||
delete result.id; | ||
result.mediaType = this.mediaTypes.PLAYLIST; | ||
} else if (result.params.ci) { | ||
delete result.params.ci; | ||
result.mediaType = this.mediaTypes.SHARE; | ||
} else { | ||
return undefined; | ||
} | ||
return result; | ||
}; | ||
YouTube.prototype.parse = function (url, params) { | ||
'use strict'; | ||
var _this = this; | ||
var result = { | ||
params: params, | ||
id: _this.parseUrl(url) | ||
}; | ||
result.params = _this.parseParameters(params, result); | ||
result = _this.parseMediaType(result); | ||
return result; | ||
}; | ||
YouTube.prototype.createShortUrl = function (vi, params) { | ||
'use strict'; | ||
var url = 'https://youtu.be/' + vi.id; | ||
if (params.start) { | ||
url += '#t=' + params.start; | ||
} | ||
return url; | ||
}; | ||
YouTube.prototype.createLongUrl = function (vi, params) { | ||
'use strict'; | ||
var url = ''; | ||
var startTime = params.start; | ||
delete params.start; | ||
if (vi.mediaType === this.mediaTypes.PLAYLIST) { | ||
params.feature = 'share'; | ||
url += 'https://youtube.com/playlist'; | ||
} else if (vi.mediaType === this.mediaTypes.VIDEO) { | ||
params.v = vi.id; | ||
url += 'https://youtube.com/watch'; | ||
} else if (vi.mediaType === this.mediaTypes.SHARE) { | ||
params.ci = vi.id; | ||
url += 'https://www.youtube.com/shared'; | ||
} | ||
if (vi.list) { | ||
params.list = vi.list; | ||
} | ||
url += combineParams({ | ||
params: params | ||
}); | ||
if (vi.mediaType !== this.mediaTypes.PLAYLIST && startTime) { | ||
url += '#t=' + startTime; | ||
} | ||
return url; | ||
}; | ||
YouTube.prototype.createEmbedUrl = function (vi, params) { | ||
'use strict'; | ||
var url = '//youtube.com/embed'; | ||
if (vi.mediaType === this.mediaTypes.PLAYLIST) { | ||
params.listType = 'playlist'; | ||
} else { | ||
url += '/' + vi.id; | ||
//loop hack | ||
if (params.loop === '1') { | ||
params.playlist = vi.id; | ||
} | ||
} | ||
return result; | ||
}, | ||
defaultFormat: 'long', | ||
formats: { | ||
short: function (vi, params) { | ||
"use strict"; | ||
var url = 'https://youtu.be/' + vi.id; | ||
if (params.start) { | ||
url += '#t=' + params.start; | ||
} | ||
return url; | ||
}, | ||
embed: function (vi, params) { | ||
"use strict"; | ||
var url = '//youtube.com/embed'; | ||
if (vi.list) { | ||
params.list = vi.list; | ||
} | ||
if (vi.mediaType === 'playlist') { | ||
params.listType = 'playlist'; | ||
} else { | ||
url += '/' + vi.id; | ||
//loop hack | ||
if (params.loop == 1) { | ||
params.playlist = vi.id; | ||
} | ||
} | ||
url += combineParams({ | ||
params: params | ||
}); | ||
url += combineParams({ | ||
params: params | ||
}); | ||
return url; | ||
}; | ||
return url; | ||
}, | ||
long: function (vi, params) { | ||
"use strict"; | ||
var url = '', | ||
startTime = params.start; | ||
delete params.start; | ||
YouTube.prototype.createImageUrl = function (baseUrl, vi, params) { | ||
'use strict'; | ||
var url = baseUrl + vi.id + '/'; | ||
var quality = params.imageQuality || this.defaultImageQuality; | ||
if (vi.mediaType === 'playlist') { | ||
params.feature = 'share'; | ||
url += 'https://youtube.com/playlist'; | ||
} else { | ||
params.v = vi.id; | ||
url += 'https://youtube.com/watch'; | ||
} | ||
return url + quality + '.jpg'; | ||
}; | ||
url += combineParams({ | ||
params: params | ||
}); | ||
YouTube.prototype.createShortImageUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createImageUrl('https://i.ytimg.com/vi/', vi, params); | ||
}; | ||
if (vi.mediaType !== 'playlist' && startTime) { | ||
url += '#t=' + startTime; | ||
} | ||
return url; | ||
}, | ||
'default': 'long' | ||
YouTube.prototype.createLongImageUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createImageUrl('https://img.youtube.com/vi/', vi, params); | ||
}; | ||
urlParser.bind(new YouTube()); | ||
function Youku() { | ||
'use strict'; | ||
this.provider = 'youku'; | ||
this.defaultFormat = 'embed'; | ||
this.formats = { | ||
embed: this.createEmbedUrl, | ||
long: this.createLongUrl, | ||
flash: this.createFlashUrl, | ||
static: this.createStaticUrl | ||
}; | ||
this.mediaTypes = { | ||
VIDEO: 'video' | ||
}; | ||
} | ||
Youku.prototype.parseUrl = function (url) { | ||
'use strict'; | ||
var match = url.match( | ||
/(?:(?:embed|sid)\/|v_show\/id_|VideoIDS=)([a-zA-Z0-9]+)/ | ||
); | ||
return match ? match[1] : undefined; | ||
}; | ||
Youku.prototype.parseParameters = function (params) { | ||
'use strict'; | ||
if (params.VideoIDS) { | ||
delete params.VideoIDS; | ||
} | ||
}); | ||
return params; | ||
}; | ||
Youku.prototype.parse = function (url, params) { | ||
'use strict'; | ||
var _this = this; | ||
var result = { | ||
mediaType: this.mediaTypes.VIDEO, | ||
id: _this.parseUrl(url), | ||
params: _this.parseParameters(params) | ||
}; | ||
if (!result.id) { | ||
return undefined; | ||
} | ||
return result; | ||
}; | ||
Youku.prototype.createUrl = function (baseUrl, vi, params) { | ||
'use strict'; | ||
var url = baseUrl + vi.id; | ||
url += combineParams({ | ||
params: params | ||
}); | ||
return url; | ||
}; | ||
Youku.prototype.createEmbedUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl('http://player.youku.com/embed/', vi, params); | ||
}; | ||
Youku.prototype.createLongUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl('http://v.youku.com/v_show/id_', vi, params); | ||
}; | ||
Youku.prototype.createStaticUrl = function (vi, params) { | ||
'use strict'; | ||
return this.createUrl( | ||
'http://static.youku.com/v1.0.0638/v/swf/loader.swf?VideoIDS=', | ||
vi, params | ||
); | ||
}; | ||
Youku.prototype.createFlashUrl = function (vi, params) { | ||
'use strict'; | ||
var url = 'http://player.youku.com/player.php/sid/' + vi.id + '/v.swf'; | ||
url += combineParams({ | ||
params: params | ||
}); | ||
return url; | ||
}; | ||
urlParser.bind(new Youku()); |
@@ -1,1 +0,1 @@ | ||
function URLParser(){"use strict";this.plugins={}}function cloneObject(a){"use strict";if(null===a||"object"!=typeof a)return a;var b=a.constructor();for(var c in a)b[c]=cloneObject(a[c]);return b}function getQueryParams(a){"use strict";if("string"!=typeof a)return{};a=a.split("+").join(" ");var b,c={},d=a.match(/(?:[\?](?:[^=]+)=(?:[^&#]*)(?:[&](?:[^=]+)=(?:[^&#]*))*(?:[#].*)?)|(?:[#].*)/);if(null===d)return{};b=d[0].substr(1).split(/[&#=]/);for(var e=0;e<b.length;e+=2)c[decodeURIComponent(b[e])]=decodeURIComponent(b[e+1]||"");return c}function combineParams(a){"use strict";if("object"!=typeof a)return"";a.params=a.params||{};var b="",c=0,d=Object.keys(a.params);if(0===d.length)return"";for(d.sort(),a.hasParams||(b+="?"+d[0]+"="+a.params[d[0]],c+=1);c<d.length;c+=1)b+="&"+d[c]+"="+a.params[d[c]];return b}function getTime(a){"use strict";var b,c=0,d={s:1,m:60,h:3600,d:86400,w:604800};if(!a.match(/^(\d+[smhdw]?)+$/))return 0;a=a.replace(/([smhdw])/g," $1 ").trim(),b=a.split(" ");for(var e=0;e<b.length;e+=2)c+=parseInt(b[e],10)*d[b[e+1]||"s"];return c}URLParser.prototype.parse=function(a){"use strict";var b,c=this,d=a.match(/(?:(?:https?:)?\/\/)?(?:[^\.]+\.)?(\w+)\./i),e=d?d[1]:void 0;return d&&e&&c.plugins[e]&&c.plugins[e].parse&&(b=c.plugins[e].parse.call(this,a,getQueryParams(a)))?(b.params&&0===Object.keys(b.params).length&&delete b.params,b.provider=c.plugins[e].provider,b):void 0},URLParser.prototype.bind=function(a){"use strict";var b=this;if(b.plugins[a.provider]=a,a.alternatives)for(var c=0;c<a.alternatives.length;c+=1)b.plugins[a.alternatives[c]]=a},URLParser.prototype.create=function(a){"use strict";var b=this,c=a.videoInfo,d=a.params,e=b.plugins[c.provider];return d="internal"===d?c.params:d||{},e&&(a.format=a.format||e.defaultFormat,e.formats.hasOwnProperty(a.format))?e.formats[a.format](c,cloneObject(d)):void 0};var urlParser=new URLParser;"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports=urlParser),urlParser.bind({provider:"dailymotion",alternatives:["dai"],parse:function(a,b){"use strict";var c,d,e={params:b};return c=a.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i),d=c?c[1]:void 0,b.hasOwnProperty("start")&&(b.start=getTime(b.start)),d?(e.mediaType="video",e.id=d,e):void 0},defaultFormat:"long",formats:{"short":function(a){"use strict";return"https://dai.ly/"+a.id},"long":function(a,b){"use strict";return"https://dailymotion.com/video/"+a.id+combineParams({params:b})},embed:function(a,b){"use strict";return"//www.dailymotion.com/embed/video/"+a.id+combineParams({params:b})}}}),urlParser.bind({provider:"twitch",parse:function(a,b){"use strict";var c,d,e,f,g={};return c=a.match(/twitch\.tv\/(\w+)(?:\/(.)\/(\d+))?/i),e=c?c[1]:void 0,f=c?c[2]:void 0,d=c?c[3]:void 0,(e=b.channel||b.utm_content||e)?(d?(g.mediaType="video",g.id=d,g.idPrefix=f):g.mediaType="stream",g.channel=e,g):void 0},defaultFormat:"long",formats:{"long":function(a,b){"use strict";var c="";return"stream"===a.mediaType?c="https://twitch.tv/"+a.channel:"video"===a.mediaType&&(c="https://twitch.tv/"+a.channel+"/"+a.idPrefix+"/"+a.id),c+=combineParams({params:b})},embed:function(a,b){"use strict";return"//www.twitch.tv/"+a.channel+"/embed"+combineParams({params:b})}}}),urlParser.bind({provider:"vimeo",alternatives:["vimeopro"],parse:function(a,b){"use strict";var c,d={mediaType:"video",params:b};return c=a.match(/(?:\/(?:channels\/[\w]+|(?:(?:album\/\d+|groups\/[\w]+)\/)?videos?))?\/(\d+)/i),d.id=c?c[1]:void 0,d.id?(b.hasOwnProperty("t")&&(b.start=getTime(b.t),delete b.t),d):void 0},defaultFormat:"long",formats:{"long":function(a,b){"use strict";var c="https://vimeo.com/"+a.id,d=b.start;return delete b.start,c+=combineParams({params:b}),d&&(c+="#t="+d),c},embed:function(a,b){"use strict";var c="//player.vimeo.com/video/"+a.id,d=b.start;return delete b.start,c+=combineParams({params:b}),d&&(c+="#t="+d),c}}}),urlParser.bind({provider:"youtube",alternatives:["youtu"],parse:function(a,b){"use strict";var c,d,e,f={params:b};if(c=a.match(/(?:(?:v|be|videos|embed)\/(?!videoseries)|v=)([\w\-]{11})/i),d=c?c[1]:void 0,b.v===d&&delete b.v,b.list===d?delete b.list:e=b.list,b.hasOwnProperty("start")&&(b.start=getTime(b.start)),b.hasOwnProperty("t")&&(b.start=getTime(b.t),delete b.t),d)f.mediaType="video",f.id=d,e&&(f.list=e);else{if(!e)return void 0;f.mediaType="playlist",f.list=e}return f},defaultFormat:"long",formats:{"short":function(a,b){"use strict";var c="https://youtu.be/"+a.id;return b.start&&(c+="#t="+b.start),c},embed:function(a,b){"use strict";var c="//youtube.com/embed";return"playlist"===a.mediaType?b.listType="playlist":(c+="/"+a.id,1==b.loop&&(b.playlist=a.id)),c+=combineParams({params:b})},"long":function(a,b){"use strict";var c="",d=b.start;return delete b.start,"playlist"===a.mediaType?(b.feature="share",c+="https://youtube.com/playlist"):(b.v=a.id,c+="https://youtube.com/watch"),c+=combineParams({params:b}),"playlist"!==a.mediaType&&d&&(c+="#t="+d),c},"default":"long"}}); | ||
function UrlParser(){"use strict";this.plugins={}}function cloneObject(a){"use strict";if(null===a||"object"!=typeof a)return a;var b=a.constructor();for(var c in a)a.hasOwnProperty(c)&&(b[c]=cloneObject(a[c]));return b}function getQueryParams(a){"use strict";if("string"!=typeof a)return{};a=a.split("+").join(" ");var b,c={},d=a.match(/(?:[\?](?:[^=]+)=(?:[^&#]*)(?:[&](?:[^=]+)=(?:[^&#]*))*(?:[#].*)?)|(?:[#].*)/);if(null===d)return{};b=d[0].substr(1).split(/[&#=]/);for(var e=0;e<b.length;e+=2)c[decodeURIComponent(b[e])]=decodeURIComponent(b[e+1]||"");return c}function combineParams(a){"use strict";if("object"!=typeof a)return"";a.params=a.params||{};var b="",c=0,d=Object.keys(a.params);if(0===d.length)return"";for(d.sort(),a.hasParams||(b+="?"+d[0]+"="+a.params[d[0]],c+=1);c<d.length;c+=1)b+="&"+d[c]+"="+a.params[d[c]];return b}function getTime(a){"use strict";var b,c=0,d={s:1,m:60,h:3600,d:86400,w:604800};if(!a.match(/^(\d+[smhdw]?)+$/))return 0;a=a.replace(/([smhdw])/g," $1 ").trim(),b=a.split(" ");for(var e=0;e<b.length;e+=2)c+=parseInt(b[e],10)*d[b[e+1]||"s"];return c}function CanalPlus(){"use strict";this.provider="canalplus",this.defaultFormat="embed",this.formats={embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function Coub(){"use strict";this.provider="coub",this.defaultFormat="long",this.formats={"long":this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function Dailymotion(){"use strict";this.provider="dailymotion",this.alternatives=["dai"],this.defaultFormat="long",this.formats={"short":this.createShortUrl,"long":this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function Twitch(){"use strict";this.provider="twitch",this.defaultFormat="long",this.formats={"long":this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video",STREAM:"stream",EMBEDVIDEO:"embed-video"}}function Vimeo(){"use strict";this.provider="vimeo",this.alternatives=["vimeopro"],this.defaultFormat="long",this.formats={"long":this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function YouTube(){"use strict";this.provider="youtube",this.alternatives=["youtu","ytimg"],this.defaultFormat="long",this.formats={"short":this.createShortUrl,"long":this.createLongUrl,embed:this.createEmbedUrl,shortImage:this.createShortImageUrl,longImage:this.createLongImageUrl},this.imageQualities={0:"0",1:"1",2:"2",3:"3",DEFAULT:"default",HQDEFAULT:"hqdefault",SDDEFAULT:"sddefault",MQDEFAULT:"mqdefault",MAXRESDEFAULT:"maxresdefault"},this.defaultImageQuality=this.imageQualities.HQDEFAULT,this.mediaTypes={VIDEO:"video",PLAYLIST:"playlist",SHARE:"share"}}function Youku(){"use strict";this.provider="youku",this.defaultFormat="embed",this.formats={embed:this.createEmbedUrl,"long":this.createLongUrl,flash:this.createFlashUrl,"static":this.createStaticUrl},this.mediaTypes={VIDEO:"video"}}UrlParser.prototype.parseProvider=function(a){"use strict";var b=a.match(/(?:(?:https?:)?\/\/)?(?:[^\.]+\.)?(\w+)\./i);return b?b[1]:void 0},UrlParser.prototype.removeEmptyParameters=function(a){"use strict";return a.params&&0===Object.keys(a.params).length&&delete a.params,a},UrlParser.prototype.parse=function(a){"use strict";var b,c=this,d=c.parseProvider(a),e=c.plugins[d];return d&&e&&e.parse?(b=e.parse.apply(e,[a,getQueryParams(a)]),b&&(b=c.removeEmptyParameters(b),b.provider=e.provider),b):void 0},UrlParser.prototype.bind=function(a){"use strict";if(this.plugins[a.provider]=a,a.alternatives)for(var b=0;b<a.alternatives.length;b+=1)this.plugins[a.alternatives[b]]=a},UrlParser.prototype.create=function(a){"use strict";var b=a.videoInfo,c=a.params,d=this.plugins[b.provider];return c="internal"===c?b.params:c||{},d&&(a.format=a.format||d.defaultFormat,d.formats.hasOwnProperty(a.format))?d.formats[a.format].apply(d,[b,cloneObject(c)]):void 0};var urlParser=new UrlParser;"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports=urlParser),CanalPlus.prototype.parseParameters=function(a){"use strict";return delete a.vid,a},CanalPlus.prototype.parse=function(a,b){"use strict";var c=this,d={mediaType:this.mediaTypes.VIDEO,id:b.vid};return d.params=c.parseParameters(b),d.id?d:void 0},CanalPlus.prototype.createEmbedUrl=function(a,b){"use strict";var c="http://player.canalplus.fr/embed/";return b.vid=a.id,c+=combineParams({params:b})},urlParser.bind(new CanalPlus),Coub.prototype.parseUrl=function(a){"use strict";var b=a.match(/(?:embed|view)\/([a-zA-Z\d]+)/i);return b?b[1]:void 0},Coub.prototype.parse=function(a,b){"use strict";var c={mediaType:this.mediaTypes.VIDEO,params:b,id:this.parseUrl(a)};return c.id?c:void 0},Coub.prototype.createUrl=function(a,b,c){"use strict";var d=a+b.id;return d+=combineParams({params:c})},Coub.prototype.createLongUrl=function(a,b){"use strict";return this.createUrl("https://coub.com/view/",a,b)},Coub.prototype.createEmbedUrl=function(a,b){"use strict";return this.createUrl("//coub.com/embed/",a,b)},urlParser.bind(new Coub),Dailymotion.prototype.parseParameters=function(a){"use strict";return this.parseTime(a)},Dailymotion.prototype.parseTime=function(a){"use strict";return a.start&&(a.start=getTime(a.start)),a},Dailymotion.prototype.parseUrl=function(a){"use strict";var b=a.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i);return b?b[1]:void 0},Dailymotion.prototype.parse=function(a,b){"use strict";var c=this,d={mediaType:this.mediaTypes.VIDEO,params:c.parseParameters(b),id:c.parseUrl(a)};return d.id?d:void 0},Dailymotion.prototype.createUrl=function(a,b,c){"use strict";return a+b.id+combineParams({params:c})},Dailymotion.prototype.createShortUrl=function(a){"use strict";return this.createUrl("https://dai.ly/",a,{})},Dailymotion.prototype.createLongUrl=function(a,b){"use strict";return this.createUrl("https://dailymotion.com/video/",a,b)},Dailymotion.prototype.createEmbedUrl=function(a,b){"use strict";return this.createUrl("//www.dailymotion.com/embed/video/",a,b)},urlParser.bind(new Dailymotion),Twitch.prototype.seperateId=function(a){"use strict";return{pre:a[0],id:a.substr(1)}},Twitch.prototype.parseChannel=function(a,b){"use strict";var c=b.channel||b.utm_content||a.channel;return delete b.utm_content,delete b.channel,c},Twitch.prototype.parseUrl=function(a,b,c){"use strict";var d;return d=a.match(/twitch\.tv\/(\w+)(?:\/(.)\/(\d+))?/i),b.channel=d?d[1]:void 0,d&&d[2]&&d[3]?b.id=d[2]+d[3]:c.video&&(b.id=c.video,delete c.video),b},Twitch.prototype.parseMediaType=function(a){"use strict";var b;return a.channel?b=a.id?this.mediaTypes.VIDEO:this.mediaTypes.STREAM:a.id&&(b=this.mediaTypes.EMBEDVIDEO,delete a.channel),b},Twitch.prototype.parseParameters=function(a){"use strict";return a.t&&(a.start=getTime(a.t),delete a.t),a},Twitch.prototype.parse=function(a,b){"use strict";var c=this,d={};return d=c.parseUrl(a,d,b),d.channel=c.parseChannel(d,b),d.mediaType=c.parseMediaType(d),d.params=c.parseParameters(b),d.channel||d.id?d:void 0},Twitch.prototype.createLongUrl=function(a,b){"use strict";var c="";if(a.mediaType===this.mediaTypes.STREAM)c="https://twitch.tv/"+a.channel;else if(a.mediaType===this.mediaTypes.VIDEO){var d=this.seperateId(a.id);c="https://twitch.tv/"+a.channel+"/"+d.pre+"/"+d.id,b.start&&(b.t=b.start+"s",delete b.start)}return c+=combineParams({params:b})},Twitch.prototype.createEmbedUrl=function(a,b){"use strict";var c="https://player.twitch.tv/";return a.mediaType===this.mediaTypes.STREAM?b.channel=a.channel:(a.mediaType===this.mediaTypes.VIDEO||a.mediaType===this.mediaTypes.EMBEDVIDEO)&&(b.video=a.id,b.start&&(b.t=b.start+"s",delete b.start)),c+=combineParams({params:b})},urlParser.bind(new Twitch),Vimeo.prototype.parseUrl=function(a){"use strict";var b=a.match(/(?:\/(?:channels\/[\w]+|(?:(?:album\/\d+|groups\/[\w]+)\/)?videos?))?\/(\d+)/i);return b?b[1]:void 0},Vimeo.prototype.parseParameters=function(a){"use strict";return this.parseTime(a)},Vimeo.prototype.parseTime=function(a){"use strict";return a.t&&(a.start=getTime(a.t),delete a.t),a},Vimeo.prototype.parse=function(a,b){"use strict";var c={mediaType:this.mediaTypes.VIDEO,params:this.parseParameters(b),id:this.parseUrl(a)};return c.id?c:void 0},Vimeo.prototype.createUrl=function(a,b,c){"use strict";var d=a+b.id,e=c.start;return delete c.start,d+=combineParams({params:c}),e&&(d+="#t="+e),d},Vimeo.prototype.createLongUrl=function(a,b){"use strict";return this.createUrl("https://vimeo.com/",a,b)},Vimeo.prototype.createEmbedUrl=function(a,b){"use strict";return this.createUrl("//player.vimeo.com/video/",a,b)},urlParser.bind(new Vimeo),YouTube.prototype.parseUrl=function(a){"use strict";var b=a.match(/(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w\-]{11})/i);return b?b[1]:void 0},YouTube.prototype.parseTime=function(a){"use strict";return a.start=getTime(a.start||a.t),delete a.t,a},YouTube.prototype.parseParameters=function(a,b){"use strict";return(a.start||a.t)&&(a.start=getTime(a.start||a.t),delete a.t),a.v===b.id&&delete a.v,a.list===b.id&&delete a.list,a},YouTube.prototype.parseMediaType=function(a){"use strict";if(a.params.list&&(a.list=a.params.list,delete a.params.list),a.id&&!a.params.ci)a.mediaType=this.mediaTypes.VIDEO;else if(a.list)delete a.id,a.mediaType=this.mediaTypes.PLAYLIST;else{if(!a.params.ci)return void 0;delete a.params.ci,a.mediaType=this.mediaTypes.SHARE}return a},YouTube.prototype.parse=function(a,b){"use strict";var c=this,d={params:b,id:c.parseUrl(a)};return d.params=c.parseParameters(b,d),d=c.parseMediaType(d)},YouTube.prototype.createShortUrl=function(a,b){"use strict";var c="https://youtu.be/"+a.id;return b.start&&(c+="#t="+b.start),c},YouTube.prototype.createLongUrl=function(a,b){"use strict";var c="",d=b.start;return delete b.start,a.mediaType===this.mediaTypes.PLAYLIST?(b.feature="share",c+="https://youtube.com/playlist"):a.mediaType===this.mediaTypes.VIDEO?(b.v=a.id,c+="https://youtube.com/watch"):a.mediaType===this.mediaTypes.SHARE&&(b.ci=a.id,c+="https://www.youtube.com/shared"),a.list&&(b.list=a.list),c+=combineParams({params:b}),a.mediaType!==this.mediaTypes.PLAYLIST&&d&&(c+="#t="+d),c},YouTube.prototype.createEmbedUrl=function(a,b){"use strict";var c="//youtube.com/embed";return a.mediaType===this.mediaTypes.PLAYLIST?b.listType="playlist":(c+="/"+a.id,"1"===b.loop&&(b.playlist=a.id)),a.list&&(b.list=a.list),c+=combineParams({params:b})},YouTube.prototype.createImageUrl=function(a,b,c){"use strict";var d=a+b.id+"/",e=c.imageQuality||this.defaultImageQuality;return d+e+".jpg"},YouTube.prototype.createShortImageUrl=function(a,b){"use strict";return this.createImageUrl("https://i.ytimg.com/vi/",a,b)},YouTube.prototype.createLongImageUrl=function(a,b){"use strict";return this.createImageUrl("https://img.youtube.com/vi/",a,b)},urlParser.bind(new YouTube),Youku.prototype.parseUrl=function(a){"use strict";var b=a.match(/(?:(?:embed|sid)\/|v_show\/id_|VideoIDS=)([a-zA-Z0-9]+)/);return b?b[1]:void 0},Youku.prototype.parseParameters=function(a){"use strict";return a.VideoIDS&&delete a.VideoIDS,a},Youku.prototype.parse=function(a,b){"use strict";var c=this,d={mediaType:this.mediaTypes.VIDEO,id:c.parseUrl(a),params:c.parseParameters(b)};return d.id?d:void 0},Youku.prototype.createUrl=function(a,b,c){"use strict";var d=a+b.id;return d+=combineParams({params:c})},Youku.prototype.createEmbedUrl=function(a,b){"use strict";return this.createUrl("http://player.youku.com/embed/",a,b)},Youku.prototype.createLongUrl=function(a,b){"use strict";return this.createUrl("http://v.youku.com/v_show/id_",a,b)},Youku.prototype.createStaticUrl=function(a,b){"use strict";return this.createUrl("http://static.youku.com/v1.0.0638/v/swf/loader.swf?VideoIDS=",a,b)},Youku.prototype.createFlashUrl=function(a,b){"use strict";var c="http://player.youku.com/player.php/sid/"+a.id+"/v.swf";return c+=combineParams({params:b})},urlParser.bind(new Youku); |
{ | ||
"name": "js-video-url-parser", | ||
"version": "0.1.6", | ||
"version": "0.2.0", | ||
"description": "A parser to extract provider, video id, starttime and others from YouTube, Vimeo, ... urls", | ||
@@ -15,3 +15,6 @@ "main": "dist/jsVideoUrlParser.js", | ||
"Dailymotion", | ||
"Twitch" | ||
"Twitch", | ||
"CanalPlus", | ||
"Youku", | ||
"Coub" | ||
], | ||
@@ -36,8 +39,8 @@ "author": { | ||
}, | ||
"files" : [ | ||
"dist/", | ||
"tests/", | ||
"README.md", | ||
"LICENSE" | ||
"files": [ | ||
"dist/", | ||
"tests/", | ||
"README.md", | ||
"LICENSE" | ||
] | ||
} |
593
README.md
@@ -11,2 +11,5 @@ jsVideoUrlParser [![Build Status](https://travis-ci.org/Zod-/jsVideoUrlParser.svg)](https://travis-ci.org/Zod-/jsVideoUrlParser) | ||
- Dailymotion | ||
- Canal+ | ||
- Youku | ||
- Coub | ||
@@ -57,16 +60,8 @@ #grunt | ||
provider: 'vimeo' } | ||
> urlParser.parse('http://www.twitch.tv/tsm_wildturtle') | ||
{ mediaType: 'stream', | ||
channel: 'tsm_wildturtle', | ||
provider: 'twitch' } | ||
> urlParser.parse('http://www.dailymotion.com/video/x1e2b95') | ||
{ mediaType: 'video', | ||
id: 'x1e2b95', | ||
provider: 'dailymotion' } | ||
``` | ||
Any url but the id parameter will be saved in the params object | ||
Any url parameters expect for ids will be saved in the params object. Some | ||
providers have special parameters for example the start parameter which dictates | ||
at how many seconds the video starts. Special parameters can be found in the | ||
different descriptions for the providers. | ||
```javascript | ||
@@ -81,3 +76,2 @@ > urlParser.parse('https://www.youtube.com/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82&t=1m40') | ||
start: 100, | ||
list: 'PL46F0A159EC02DF82', | ||
index: '25' | ||
@@ -88,87 +82,38 @@ } | ||
##URL Creation | ||
##Url Creation | ||
The VideoInfo objects can be turned back into a `'short'`, `'embed'` or `'long'` url where `'long'` is the default. | ||
Embedded links will be protocol relative. | ||
The videoInfo objects can be turned back into urls with the `.create` function. | ||
The required parameter for this is the videoInfo object itself. Optional ones are | ||
the format of the url and the url parameters that should be added. Each provider | ||
has it's own default format. | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.youtube.com/watch?feature=player_embedded&v=HRb7B9fPhfA'), | ||
format: 'short' | ||
videoInfo: { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video' | ||
}, | ||
format: 'long', | ||
params: { | ||
foo: 'bar' | ||
} | ||
}) | ||
'https://youtu.be/HRb7B9fPhfA' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.youtube.com/watch?feature=player_embedded&v=HRb7B9fPhfA') | ||
}) | ||
'https://www.youtube.com/watch?v=HRb7B9fPhfA' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.youtube.com/watch?feature=player_embedded&v=HRb7B9fPhfA'), | ||
format: 'embed' | ||
}) | ||
'//youtube.com/embed/HRb7B9fPhfA' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('https://vimeo.com/97276391') | ||
}) | ||
'https://vimeo.com/97276391' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('https://vimeo.com/97276391'), | ||
format: 'embed' | ||
}) | ||
'//player.vimeo.com/video/97276391' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.twitch.tv/tsm_wildturtle') | ||
}) | ||
'https://twitch.tv/tsm_wildturtle' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.twitch.tv/tsm_wildturtle'), | ||
format: 'embed' | ||
}) | ||
'//www.twitch.tv/tsm_wildturtle/embed' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.dailymotion.com/video/x1e2b95'), | ||
format: 'short' | ||
}) | ||
'https://dai.ly/x1e2b95' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.dailymotion.com/video/x1e2b95') | ||
}) | ||
'https://www.dailymotion.com/video/x1e2b95' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.dailymotion.com/video/x1e2b95'), | ||
format: 'embed' | ||
}) | ||
'//www.dailymotion.com/embed/video/x1e2b95' | ||
'https://www.youtube.com/watch?foo=bar&v=HRb7B9fPhfA' | ||
``` | ||
Parsing and creating can also be chained together to clean up an url for example. | ||
If you still want to reuse the generated parameters object you can use the keyword | ||
`'internal'` as params. | ||
Url parameters can be added by adding a params object | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('http://www.youtube.com/watch?v=yQaAGmHNn9s'), | ||
params:{ | ||
start: 100, | ||
list: 'PL46F0A159EC02DF82', | ||
index: '25', | ||
foo: 'bar' | ||
} | ||
videoInfo: urlParser.parse('https://youtube.com/watch?foo=bar&v=HRb7B9fPhfA') | ||
}) | ||
'https://youtube.com/watch?foo=bar&index=25&list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100' | ||
``` | ||
'https://youtube.com/watch?v=HRb7B9fPhfA' | ||
To the reuse the params in the videoInfo object without having to save it in a temp variable use the keyword `'internal'` as params | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('https://youtube.com/watch?foo=bar&index=25&list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100'), | ||
videoInfo: urlParser.parse('https://youtube.com/watch?foo=bar&v=HRb7B9fPhfA'), | ||
params: 'internal' | ||
}) | ||
'https://youtube.com/watch?foo=bar&index=25&list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100' | ||
> urlParser.create({ | ||
videoInfo: urlParser.parse('https://youtube.com/watch?foo=bar&index=25&list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100'), | ||
params: 'internal', | ||
format: 'embed' | ||
}) | ||
'//youtube.com/embed/yQaAGmHNn9s?foo=bar&index=25&list=PL46F0A159EC02DF82&start=100' | ||
'https://youtube.com/watch?foo=bar&v=HRb7B9fPhfA' | ||
``` | ||
@@ -180,3 +125,28 @@ | ||
It can extract the id from shortened, mobile and feed urls. | ||
####Supported media types: | ||
* `'video'`: Regular videos which can also be livestreams. | ||
* `'playlist'`: YouTube playlist. | ||
* `'share'`: Shared YouTube videos that link to a special website and are not actual videos themselves. | ||
####Supported url formats: | ||
* `'short'`: Shortened urls. | ||
* `'long'`(default): Regular urls. | ||
* `'embed'`: Embedded urls. | ||
* `'shortImage'`: Shortened thumbnail urls. | ||
* `'longImage'`: Regular thumbnail urls. | ||
####Creating urls with different media types: | ||
| mediaType/formats| short | long | embed | shortImage | longImage | | ||
| ------------- | :--: | :--: | :--: | :--: | :--: | | ||
| **video** | ✓ | ✓ | ✓ | ✓ | ✓ | | ||
| **playlist** | X | ✓ | ✓ | X | X | | ||
| **share** | X | ✓ | X | X | X | | ||
####Special parameters: | ||
* `'params.start'`: The number where the video should begin in seconds. | ||
* `'params.imageQuality'`: Custom parameter for generating different qualities of thumbnail urls. | ||
* `'0', '1', '2', '3', 'default', 'hqdefault'(default), 'mqdefault', 'sddefault', 'maxresdefault'` | ||
####Parsing Examples: | ||
```javascript | ||
@@ -187,19 +157,13 @@ > urlParser.parse('http://www.youtube.com/watch?v=HRb7B9fPhfA'); | ||
> urlParser.parse('https://gdata.youtube.com/feeds/api/videos/HRb7B9fPhfA/related'); | ||
> urlParser.parse('https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg'); | ||
> urlParser.parse('https://img.youtube.com/vi/HRb7B9fPhfA/hqdefault.jpg'); | ||
{ mediaType: 'video', | ||
id: 'HRb7B9fPhfA', | ||
provider: 'youtube' } | ||
``` | ||
Also supports the start time parameter and playlist urls. | ||
```javascript | ||
> urlParser.parse('http://www.youtube.com/embed/videoseries?list=PL46F0A159EC02DF82'); | ||
> urlParser.parse('http://www.youtube.com/playlist?list=PL46F0A159EC02DF82'); | ||
{ mediaType: 'playlist', | ||
list: 'PL46F0A159EC02DF82', | ||
provider: 'youtube', | ||
params: { | ||
list: 'PL46F0A159EC02DF82' | ||
} | ||
} | ||
list: 'PL46F0A159EC02DF82', | ||
provider: 'youtube'} | ||
@@ -210,19 +174,3 @@ > urlParser.parse('http://www.youtube.com/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82'); | ||
list: 'PL46F0A159EC02DF82', | ||
provider: 'youtube', | ||
params: { | ||
list: 'PL46F0A159EC02DF82' | ||
} | ||
} | ||
> urlParser.parse('http://www.youtube.com/watch?v=HRb7B9fPhfA#t=30s'); | ||
> urlParser.parse('http://www.youtube.com/watch?v=HRb7B9fPhfA&t=30s'); | ||
> urlParser.parse('http://youtu.be/HRb7B9fPhfA?t=30s'); | ||
> urlParser.parse('http://youtu.be/HRb7B9fPhfA#t=30s'); | ||
> urlParser.parse('https://m.youtube.com/details?v=HRb7B9fPhfA#t=30s'); | ||
{ mediaType: 'video', | ||
id: 'HRb7B9fPhfA', | ||
provider: 'youtube' | ||
params: { | ||
start: 30 | ||
} | ||
} | ||
@@ -236,4 +184,3 @@ | ||
params: { | ||
start: 100, | ||
list: 'PL46F0A159EC02DF82', | ||
start: 100 | ||
} | ||
@@ -243,5 +190,116 @@ } | ||
####Creation Examples: | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video' | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://www.youtube.com/watch?v=HRb7B9fPhfA' | ||
'short': 'https://youtu.be/HRb7B9fPhfA' | ||
'embed': '//youtube.com/embed/HRb7B9fPhfA' | ||
'shortImage': 'https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg' | ||
'longImage': 'https://img.youtube.com/vi/HRb7B9fPhfA/hqdefault.jpg' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video' | ||
}, | ||
params: { | ||
start: 90 | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://youtube.com/watch?v=HRb7B9fPhfA#t=90' | ||
'short': 'https://youtu.be/HRb7B9fPhfA#t=90' | ||
'embed': '//youtube.com/embed/HRb7B9fPhfA?start=90' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'video' | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://youtube.com/watch?list=PL46F0A159EC02DF82&v=HRb7B9fPhfA' | ||
'embed': '//youtube.com/embed/HRb7B9fPhfA?list=PL46F0A159EC02DF82' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'youtube', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'playlist' | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://youtube.com/playlist?feature=share&list=PL46F0A159EC02DF82' | ||
'embed': '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video' | ||
}, | ||
params:{ | ||
imageQuality: <quality> | ||
}, | ||
format: 'shortImage' | ||
}) | ||
'0': 'https://i.ytimg.com/vi/HRb7B9fPhfA/0.jpg' | ||
'1': 'https://i.ytimg.com/vi/HRb7B9fPhfA/1.jpg' | ||
'2': 'https://i.ytimg.com/vi/HRb7B9fPhfA/2.jpg' | ||
'3': 'https://i.ytimg.com/vi/HRb7B9fPhfA/3.jpg' | ||
'hqdefault': 'https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg' | ||
'sddefault': 'https://i.ytimg.com/vi/HRb7B9fPhfA/sddefault.jpg' | ||
'mqdefault': 'https://i.ytimg.com/vi/HRb7B9fPhfA/mqdefault.jpg' | ||
'maxresdefault': 'https://i.ytimg.com/vi/HRb7B9fPhfA/maxresdefault.jpg' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video' | ||
}, | ||
params:{ | ||
imageQuality: <quality> | ||
}, | ||
format: 'longImage' | ||
}) | ||
'0': 'https://img.youtube.com/vi/HRb7B9fPhfA/0.jpg' | ||
'1': 'https://img.youtube.com/vi/HRb7B9fPhfA/1.jpg' | ||
'2': 'https://img.youtube.com/vi/HRb7B9fPhfA/2.jpg' | ||
'3': 'https://img.youtube.com/vi/HRb7B9fPhfA/3.jpg' | ||
'hqdefault': 'https://img.youtube.com/vi/HRb7B9fPhfA/hqdefault.jpg' | ||
'sddefault': 'https://img.youtube.com/vi/HRb7B9fPhfA/sddefault.jpg' | ||
'mqdefault': 'https://img.youtube.com/vi/HRb7B9fPhfA/mqdefault.jpg' | ||
'maxresdefault': 'https://img.youtube.com/vi/HRb7B9fPhfA/maxresdefault.jpg' | ||
``` | ||
##Vimeo | ||
Supports urls from channels, albums, groups and frames. | ||
####Supported media types: | ||
* `'video'`: Regular videos | ||
####Supported url formats: | ||
* `'long'`(default): Regular urls. | ||
* `'embed'`: Embedded urls. | ||
####Creating urls with different media types: | ||
| mediaType/formats| long | embed | | ||
| ------------- | :--: | :--: | | ||
| **video** | ✓ | ✓ | | ||
####Special parameters: | ||
* `'params.start'`: The number where the video should begin in seconds. | ||
####Parsing Examples: | ||
```javascript | ||
@@ -268,26 +326,165 @@ > urlParser.parse('https://vimeo.com/97276391'); | ||
provider: 'vimeo' } | ||
> urlParser.parse('https://vimeo.com/97276391#t=1m30s'); | ||
{ id: '97276391', | ||
mediaType: 'video', | ||
provider: 'vimeo', | ||
params: { | ||
start: 90 | ||
} | ||
} | ||
``` | ||
####Creation Examples: | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'vimeo', | ||
id: '97276391', | ||
mediaType: 'video' | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://vimeo.com/97276391' | ||
'embed': '//player.vimeo.com/video/97276391' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'vimeo', | ||
id: '97276391', | ||
mediaType: 'video', | ||
params: { | ||
start: 90 | ||
} | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://vimeo.com/97276391#t=90' | ||
'embed': '//player.vimeo.com/video/97276391#t=90' | ||
``` | ||
##Twitch | ||
Supports embedded, stream and video urls | ||
####Supported media types: | ||
* `'stream'`: Streams which are just a direct url to a channel. | ||
* `'video'`: Regular videos. | ||
* `'embed-video'`: This is a seperate media type from video because these types | ||
of urls don't contain the channel name so they are incompatible with eachother | ||
####Supported url formats: | ||
* `'long'`(default): Regular urls. | ||
* `'embed'`: Embedded urls. | ||
####Creating urls with different media types: | ||
| mediaType/formats| long | embed | | ||
| ------------- | :--: | :--: | | ||
| **stream** | ✓ | ✓ | | ||
| **video** | ✓ | ✓ | | ||
| **embed-video** | X | ✓ | | ||
####Special parameters: | ||
* `'params.start'`: The number where the video should begin in seconds. | ||
```javascript | ||
> urlParser.parse('http://www.twitch.tv/tsm_wildturtle'); | ||
> urlParser.parse('http://www.twitch.tv/widgets/live_embed_player.swf?channel=tsm_wildturtle'); | ||
> urlParser.parse('http://twitch.tv/tsm_wildturtle/chat'); | ||
> urlParser.parse('http://www.twitch.tv/rains8'); | ||
> urlParser.parse('http://www.twitch.tv/widgets/live_embed_player.swf?channel=rains8'); | ||
> urlParser.parse('http://twitch.tv/rains8/chat'); | ||
{ mediaType: 'stream', | ||
channel: 'tsm_wildturtle', | ||
channel: 'rains8', | ||
provider: 'twitch' } | ||
> urlParser.parse('http://www.twitch.tv/tsm_wildturtle/c/2724914'); | ||
> urlParser.parse('http://www.twitch.tv/rains8/v/75292411'); | ||
{ mediaType: 'video', | ||
id: '2724914', | ||
idPrefix: 'c', | ||
channel: 'tsm_wildturtle', | ||
id: 'v75292411', | ||
channel: 'rains8', | ||
provider: 'twitch' } | ||
> urlParser.parse('http://www.twitch.tv/rains8/v/75292411?t=1m30s'); | ||
{ mediaType: 'video', | ||
id: 'v75292411', | ||
channel: 'rains8', | ||
provider: 'twitch', | ||
params: { | ||
start: 90 | ||
} | ||
} | ||
> urlParser.parse('https://player.twitch.tv/?video=v75292411'); | ||
{ mediaType: 'embed-video', | ||
id: 'v75292411', | ||
provider: 'twitch' } | ||
``` | ||
####Creation Examples: | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'twitch', | ||
channel: 'rains8', | ||
mediaType: 'stream' | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://twitch.tv/rains8' | ||
'embed': 'https://player.twitch.tv/?channel=rains8' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'twitch', | ||
channel: 'rains8', | ||
id: 'v75292411', | ||
mediaType: 'video' | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://twitch.tv/rains8/v/75292411' | ||
'embed': 'https://player.twitch.tv/?video=v75292411' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'twitch', | ||
channel: 'rains8', | ||
id: 'v75292411', | ||
mediaType: 'video', | ||
params: { | ||
start: 90 | ||
} | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://twitch.tv/rains8/v/75292411?t=90s' | ||
'embed': 'https://player.twitch.tv/?video=v75292411?=90s' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'twitch', | ||
id: 'v75292411', | ||
mediaType: 'embed-video' | ||
}, | ||
format: <format> | ||
}) | ||
'embed': 'https://player.twitch.tv/?video=v75292411' | ||
``` | ||
##Dailymotion | ||
Supports embedded and shortened urls. | ||
####Supported media types: | ||
* `'video'`: Regular videos. | ||
####Supported url formats: | ||
* `'short'`: Shortened urls. | ||
* `'long'`(default): Regular urls. | ||
* `'embed'`: Embedded urls. | ||
####Creating urls with different media types: | ||
| mediaType/formats| short | long | embed | | ||
| ------------- | :--: | :--: | :--: | | ||
| **video** | ✓ | ✓ | ✓ | | ||
####Special parameters: | ||
* `'params.start'`: The number where the video should begin in seconds. | ||
####Parsing Examples: | ||
```javascript | ||
@@ -313,1 +510,149 @@ > urlParser.parse('http://www.dailymotion.com/video/x1e2b95_bruce-lee-nin-kayip-kedisi_animals'); | ||
``` | ||
####Creation Examples: | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'dailymotion', | ||
id: 'x1e2b95', | ||
mediaType: 'video' | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://www.dailymotion.com/video/x1e2b95' | ||
'short': 'https://dai.ly/x1e2b95' | ||
'embed': '//www.dailymotion.com/embed/video/x1e2b95' | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'dailymotion', | ||
id: 'x1e2b95', | ||
mediaType: 'video', | ||
params: { | ||
start: 10 | ||
} | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://www.dailymotion.com/video/x1e2b95?start=10' | ||
'short': 'https://dai.ly/x1e2b95?start=10' | ||
'embed': '//www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
``` | ||
##Coub | ||
####Supported media types: | ||
* `'video'`: Regular videos. | ||
####Supported url formats: | ||
* `'long'`(default): Regular urls. | ||
* `'embed'`: Embedded urls. | ||
####Creating urls with different media types: | ||
| mediaType/formats| long | embed | | ||
| ------------- | :--: | :--: | | ||
| **video** | ✓ | ✓ | | ||
####Parsing Examples: | ||
```javascript | ||
> urlParser.parse('https://coub.com/view/by7sm'); | ||
> urlParser.parse('//coub.com/embed/by7sm'); | ||
{ mediaType: 'video', | ||
id: 'by7sm', | ||
provider: 'coub' } | ||
``` | ||
####Creation Examples: | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'coub', | ||
id: 'by7sm', | ||
mediaType: 'video' | ||
}, | ||
format: <format> | ||
}) | ||
'long': 'https://coub.com/view/by7sm' | ||
'embed': '//coub.com/embed/by7sm' | ||
``` | ||
##Youku | ||
####Supported media types: | ||
* `'video'`: Regular videos. | ||
####Supported url formats: | ||
* `'long'`(default): Regular urls. | ||
* `'static'`: Video player that fills out the whole website. | ||
* `'embed'`: Embedded urls. | ||
* `'flash'`: Flash embedded urls. | ||
####Creating urls with different media types: | ||
| mediaType/formats| long | static | embed | flash | | ||
| ------------- | :--: | :--: | :--: | :--: | | ||
| **video** | ✓ | ✓ | ✓ | ✓ | | ||
####Parsing Examples: | ||
```javascript | ||
> urlParser.parse('http://player.youku.com/embed/XMTQ3OTM4MzMxMg'); | ||
> urlParser.parse('http://player.youku.com/player.php/sid/XMTQ3OTM4MzMxMg/v.swf'); | ||
> urlParser.parse('http://v.youku.com/v_show/id_XMTQ3OTM4MzMxMg'); | ||
> urlParser.parse('http://static.youku.com/v1.0.0638/v/swf/loader.swf?VideoIDS=XMTQ3OTM4MzMxMg'); | ||
{ mediaType: 'video', | ||
id: 'XMTQ3OTM4MzMxMg', | ||
provider: 'youku' } | ||
``` | ||
####Creation Examples: | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'youku', | ||
id: 'XMTQ3OTM4MzMxMg', | ||
mediaType: 'video' | ||
}, | ||
format: <format> | ||
}) | ||
'embed': 'http://player.youku.com/embed/XMTQ3OTM4MzMxMg', | ||
'long': 'http://v.youku.com/v_show/id_XMTQ3OTM4MzMxMg', | ||
'flash': 'http://player.youku.com/player.php/sid/XMTQ3OTM4MzMxMg/v.swf', | ||
'static': 'http://static.youku.com/v1.0.0638/v/swf/loader.swf?VideoIDS=XMTQ3OTM4MzMxMg' | ||
``` | ||
##Canal+ | ||
####Supported media types: | ||
* `'video'`: Regular videos. | ||
####Supported url formats: | ||
* `'embed'`(default): Embedded urls. | ||
####Creating urls with different media types: | ||
| mediaType/formats| embed | | ||
| ------------- | :--: | | ||
| **video** | ✓ | | ||
####Parsing Examples: | ||
```javascript | ||
> urlParser.parse('http://player.canalplus.fr/embed/?param=cplus&vid=1365175'); | ||
> urlParser.parse('http://www.canalplus.fr/humour/pid1784-les-guignols.html?vid=1365175'); | ||
{ mediaType: 'video', | ||
id: '1365175', | ||
provider: 'canalplus' } | ||
``` | ||
####Creation Examples: | ||
```javascript | ||
> urlParser.create({ | ||
videoInfo: { | ||
provider: 'canalplus', | ||
id: '1365175', | ||
mediaType: 'video' | ||
}, | ||
format: <format> | ||
}) | ||
'embed': 'http://player.canalplus.fr/embed/?param=cplus&vid=1365175', | ||
``` |
/*jshint unused:false */ | ||
function assertUrlTest(assert, tests) { | ||
/*jshint unused:true */ | ||
"use strict"; | ||
'use strict'; | ||
tests.forEach(function (test) { | ||
@@ -9,4 +9,4 @@ test.urls.forEach(function (url) { | ||
}); | ||
for(var format in test.formats){ | ||
if(test.formats.hasOwnProperty(format)){ | ||
for (var format in test.formats) { | ||
if (test.formats.hasOwnProperty(format)) { | ||
assert.equal(urlParser.create({ | ||
@@ -13,0 +13,0 @@ videoInfo: test.videoInfo, |
@@ -1,3 +0,3 @@ | ||
QUnit.test("TimeString Parser", function (assert) { | ||
"use strict"; | ||
QUnit.test('TimeString Parser', function (assert) { | ||
'use strict'; | ||
var s = 1, | ||
@@ -36,4 +36,4 @@ m = 60 * s, | ||
QUnit.test("GetQueryParams Tests", function (assert) { | ||
"use strict"; | ||
QUnit.test('GetQueryParams Tests', function (assert) { | ||
'use strict'; | ||
assert.deepEqual(getQueryParams(undefined), {}, 'Undefined argument'); | ||
@@ -58,7 +58,8 @@ assert.deepEqual(getQueryParams([]), {}, 'Not a string argument'); | ||
}, '?foo=bar&faz=baz'); | ||
assert.deepEqual(getQueryParams('http://foo.bar/test?foo=bar&faz=baz#fiz=biz'), { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
}, '?foo=bar&faz=baz#fiz=biz'); | ||
assert.deepEqual( | ||
getQueryParams('http://foo.bar/test?foo=bar&faz=baz#fiz=biz'), { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
}, '?foo=bar&faz=baz#fiz=biz'); | ||
assert.deepEqual(getQueryParams('http://foo.bar/test?foo=bar&faz=baz#fiz'), { | ||
@@ -71,4 +72,4 @@ foo: 'bar', | ||
QUnit.test("CombineParams Tests", function (assert) { | ||
"use strict"; | ||
QUnit.test('CombineParams Tests', function (assert) { | ||
'use strict'; | ||
assert.equal(combineParams(undefined), '', 'Undefined argument'); | ||
@@ -81,3 +82,3 @@ assert.equal(combineParams({}), '', 'No params object'); | ||
} | ||
}), '?foo=bar', "{foo:'bar'}"); | ||
}), '?foo=bar', '{foo:\'bar\'}'); | ||
assert.equal(combineParams({ | ||
@@ -88,10 +89,11 @@ params: { | ||
} | ||
}), '?faz=baz&foo=bar', "{foo:'bar',faz:'baz'}"); | ||
}), '?faz=baz&foo=bar', '{foo:\'bar\',faz:\'baz\'}'); | ||
assert.equal(combineParams({ | ||
params: { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
} | ||
}), '?faz=baz&fiz=biz&foo=bar', "{foo: 'bar',faz: 'baz',fiz: 'biz'}"); | ||
params: { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
} | ||
}), '?faz=baz&fiz=biz&foo=bar', | ||
'{foo: \'bar\',faz: \'baz\',fiz: \'biz\'}'); | ||
@@ -103,3 +105,3 @@ assert.equal(combineParams({ | ||
} | ||
}), '&foo=bar', "{foo:'bar'}"); | ||
}), '&foo=bar', '{foo:\'bar\'}'); | ||
assert.equal(combineParams({ | ||
@@ -111,11 +113,12 @@ hasParams: true, | ||
} | ||
}), '&faz=baz&foo=bar', "{foo:'bar',faz:'baz'}"); | ||
}), '&faz=baz&foo=bar', '{foo:\'bar\',faz:\'baz\'}'); | ||
assert.equal(combineParams({ | ||
hasParams: true, | ||
params: { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
} | ||
}), '&faz=baz&fiz=biz&foo=bar', "{foo: 'bar',faz: 'baz',fiz: 'biz'}"); | ||
hasParams: true, | ||
params: { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
} | ||
}), '&faz=baz&fiz=biz&foo=bar', | ||
'{foo: \'bar\',faz: \'baz\',fiz: \'biz\'}'); | ||
}); |
@@ -1,31 +0,34 @@ | ||
QUnit.test("Dailymotion URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Dailymotion Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'dailymotion', | ||
'id': 'x1e2b95', | ||
'mediaType': 'video' | ||
provider: 'dailymotion', | ||
id: 'x1e2b95', | ||
mediaType: 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://dailymotion.com/video/x1e2b95', | ||
short: 'https://dai.ly/x1e2b95', | ||
embed: '//www.dailymotion.com/embed/video/x1e2b95' | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://dailymotion.com/video/x1e2b95', | ||
short: 'https://dai.ly/x1e2b95', | ||
embed: '//www.dailymotion.com/embed/video/x1e2b95' | ||
}, | ||
urls: ['http://www.dailymotion.com/video/x1e2b95_bruce-lee-nin-kayip-kedisi_animals', | ||
'http://www.dailymotion.com/video/x1e2b95', | ||
'http://dai.ly/x1e2b95', | ||
'http://www.dailymotion.com/embed/video/x1e2b95' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://dailymotion.com/video/x1e2b95?start=10', | ||
embed: '//www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
}, | ||
urls: ['http://www.dailymotion.com/video/x1e2b95?start=10', | ||
'http://www.dailymotion.com/video/x1e2b95_bruce-lee-nin-kayip-kedisi_animals?start=10', | ||
'http://www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
] | ||
}]; | ||
urls: [ | ||
'http://www.dailymotion.com/video/x1e2b95\ | ||
_bruce-lee-nin-kayip-kedisi_animals', | ||
'http://www.dailymotion.com/video/x1e2b95', | ||
'http://dai.ly/x1e2b95', | ||
'http://www.dailymotion.com/embed/video/x1e2b95' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://dailymotion.com/video/x1e2b95?start=10', | ||
embed: '//www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
}, | ||
urls: ['http://www.dailymotion.com/video/x1e2b95?start=10', | ||
'http://www.dailymotion.com/video/x1e2b95\ | ||
_bruce-lee-nin-kayip-kedisi_animals?start=10', | ||
'http://www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
] | ||
}]; | ||
tests[1].videoInfo.params = { | ||
@@ -32,0 +35,0 @@ start: 10 |
@@ -1,30 +0,81 @@ | ||
QUnit.test("Twitch Stream URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Twitch Stream Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'twitch', | ||
'channel': 'tsm_wildturtle', | ||
'mediaType': 'stream' | ||
provider: 'twitch', | ||
channel: 'rains8', | ||
mediaType: 'stream' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/rains8', | ||
embed: 'https://player.twitch.tv/?channel=rains8' | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/tsm_wildturtle', | ||
embed: '//www.twitch.tv/tsm_wildturtle/embed' | ||
}, | ||
urls: ['http://www.twitch.tv/tsm_wildturtle', | ||
'http://www.twitch.tv/widgets/live_embed_player.swf?channel=tsm_wildturtle', | ||
'http://twitch.tv/tsm_wildturtle/chat?popout=', | ||
'//www.twitch.tv/tsm_wildturtle/embed' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/tsm_wildturtle/c/2724914', | ||
}, | ||
urls: ['http://www.twitch.tv/tsm_wildturtle/c/2724914'] | ||
}]; | ||
tests[1].videoInfo.id = '2724914'; | ||
tests[1].videoInfo.idPrefix = 'c'; | ||
tests[1].videoInfo.mediaType = 'video'; | ||
urls: ['http://www.twitch.tv/rains8', | ||
'http://www.twitch.tv/widgets/live_embed_player.swf\ | ||
?channel=rains8', | ||
'http://twitch.tv/rains8/chat', | ||
'//www.twitch.tv/rains8/embed' | ||
] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test('Twitch Video Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'twitch', | ||
id: 'v75292411', | ||
channel: 'rains8', | ||
mediaType: 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/rains8/v/75292411', | ||
embed: 'https://player.twitch.tv/?video=v75292411' | ||
}, | ||
urls: ['http://www.twitch.tv/rains8/v/75292411'] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/rains8/v/75292411?t=90s', | ||
embed: 'https://player.twitch.tv/?t=90s&video=v75292411' | ||
}, | ||
urls: ['https://www.twitch.tv/rains8/v/75292411?t=1m30s'] | ||
}]; | ||
tests[1].videoInfo.params = { | ||
start: 90 | ||
}; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test('Twitch Embed Video Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'twitch', | ||
id: 'v75292411', | ||
mediaType: 'embed-video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: 'https://player.twitch.tv/?video=v75292411' | ||
}, | ||
urls: [ | ||
'https://player.twitch.tv/?video=v75292411' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: 'https://player.twitch.tv/?t=90s&video=v75292411' | ||
}, | ||
urls: [ | ||
'https://player.twitch.tv/?video=v75292411&t=1m30s' | ||
] | ||
}]; | ||
tests[1].videoInfo.params = { | ||
start: 90 | ||
}; | ||
assertUrlTest(assert, tests); | ||
}); |
@@ -1,56 +0,56 @@ | ||
QUnit.test("Vimeo URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Vimeo Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'vimeo', | ||
'id': '97276391', | ||
'mediaType': 'video' | ||
'provider': 'vimeo', | ||
'id': '97276391', | ||
'mediaType': 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/97276391', | ||
embed: '//player.vimeo.com/video/97276391' | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/97276391', | ||
embed: '//player.vimeo.com/video/97276391' | ||
}, | ||
urls: ['https://vimeo.com/97276391', | ||
'https://vimeo.com/channels/staffpicks/97276391', | ||
'//player.vimeo.com/video/97276391' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/96186586', | ||
embed: '//player.vimeo.com/video/96186586' | ||
}, | ||
urls: ['https://vimeo.com/album/2903155/video/96186586', | ||
'//player.vimeo.com/video/96186586' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/97688625', | ||
embed: '//player.vimeo.com/video/97688625' | ||
}, | ||
urls: ['https://vimeo.com/groups/shortfilms/videos/97688625', | ||
'//player.vimeo.com/video/97688625', | ||
'https://vimeo.com/groups/1minute/videos/97688625' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/24069938', | ||
embed: '//player.vimeo.com/video/24069938' | ||
}, | ||
urls: ['http://vimeopro.com/staff/frame/video/24069938', | ||
'//player.vimeo.com/video/24069938' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/36881035#t=208', | ||
embed: '//player.vimeo.com/video/36881035#t=208' | ||
}, | ||
urls: ['https://vimeo.com/36881035#t=3m28s', | ||
'//player.vimeo.com/video/36881035#t=3m28s' | ||
] | ||
}]; | ||
urls: ['https://vimeo.com/97276391', | ||
'https://vimeo.com/channels/staffpicks/97276391', | ||
'//player.vimeo.com/video/97276391' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/96186586', | ||
embed: '//player.vimeo.com/video/96186586' | ||
}, | ||
urls: ['https://vimeo.com/album/2903155/video/96186586', | ||
'//player.vimeo.com/video/96186586' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/97688625', | ||
embed: '//player.vimeo.com/video/97688625' | ||
}, | ||
urls: ['https://vimeo.com/groups/shortfilms/videos/97688625', | ||
'//player.vimeo.com/video/97688625', | ||
'https://vimeo.com/groups/1minute/videos/97688625' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/24069938', | ||
embed: '//player.vimeo.com/video/24069938' | ||
}, | ||
urls: ['http://vimeopro.com/staff/frame/video/24069938', | ||
'//player.vimeo.com/video/24069938' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/36881035#t=208', | ||
embed: '//player.vimeo.com/video/36881035#t=208' | ||
}, | ||
urls: ['https://vimeo.com/36881035#t=3m28s', | ||
'//player.vimeo.com/video/36881035#t=3m28s' | ||
] | ||
}]; | ||
@@ -57,0 +57,0 @@ tests[1].videoInfo.id = '96186586'; |
@@ -1,43 +0,52 @@ | ||
QUnit.test("Regular YouTube URLs", function (assert) { | ||
"use strict"; | ||
var yt1 = 'https://youtube.com'; | ||
var yt2 = 'http://www.youtube.com'; | ||
var yt3 = 'https://www.youtube.com'; | ||
var yt4 = '//youtube.com/embed'; | ||
var yt5 = 'https://img.youtube.com'; | ||
QUnit.test('Regular YouTube Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video', | ||
params: { | ||
start: 30 | ||
} | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video', | ||
params: { | ||
start: 30 | ||
} | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + '/watch?v=HRb7B9fPhfA#t=30', | ||
embed: yt4 + '/HRb7B9fPhfA?start=30', | ||
short: 'https://youtu.be/HRb7B9fPhfA#t=30' | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?v=HRb7B9fPhfA#t=30', | ||
embed: '//youtube.com/embed/HRb7B9fPhfA?start=30', | ||
short: 'https://youtu.be/HRb7B9fPhfA#t=30' | ||
}, | ||
urls: ['http://www.youtube.com/watch?v=HRb7B9fPhfA#t=30s', | ||
'http://www.youtube.com/watch?v=HRb7B9fPhfA&t=30s', | ||
'https://m.youtube.com/details?v=HRb7B9fPhfA#t=30s', | ||
'http://youtu.be/HRb7B9fPhfA?t=30s', | ||
'http://youtu.be/HRb7B9fPhfA#t=30s', | ||
'//youtube.com/embed/HRb7B9fPhfA?start=30', | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?v=HRb7B9fPhfA', | ||
embed: '//youtube.com/embed/HRb7B9fPhfA', | ||
short: 'https://youtu.be/HRb7B9fPhfA' | ||
}, | ||
urls: ['http://www.youtube.com/watch?v=HRb7B9fPhfA', | ||
'http://youtu.be/HRb7B9fPhfA', | ||
'https://m.youtube.com/details?v=HRb7B9fPhfA' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: '//youtube.com/embed/HRb7B9fPhfA?loop=1&playlist=HRb7B9fPhfA&start=30' | ||
}, | ||
urls: ['//youtube.com/embed/HRb7B9fPhfA?loop=1&list=HRb7B9fPhfA&start=30'] | ||
}]; | ||
urls: [yt2 + '/watch?v=HRb7B9fPhfA#t=30s', | ||
yt2 + '/watch?v=HRb7B9fPhfA&t=30s', | ||
'https://m.youtube.com/details?v=HRb7B9fPhfA#t=30s', | ||
'http://youtu.be/HRb7B9fPhfA?t=30s', | ||
'http://youtu.be/HRb7B9fPhfA#t=30s', | ||
yt4 + '/HRb7B9fPhfA?start=30', | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + '/watch?v=HRb7B9fPhfA', | ||
embed: yt4 + '/HRb7B9fPhfA', | ||
short: 'https://youtu.be/HRb7B9fPhfA', | ||
shortImage: 'https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg', | ||
longImage: yt5 + '/vi/HRb7B9fPhfA/hqdefault.jpg' | ||
}, | ||
urls: [yt2 + '/watch?v=HRb7B9fPhfA', | ||
'http://youtu.be/HRb7B9fPhfA', | ||
'https://m.youtube.com/details?v=HRb7B9fPhfA' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: yt4 + '/HRb7B9fPhfA?loop=1&playlist=HRb7B9fPhfA&start=30' | ||
}, | ||
urls: [ | ||
yt4 + '/HRb7B9fPhfA?loop=1&list=HRb7B9fPhfA&start=30' | ||
] | ||
}]; | ||
delete tests[1].videoInfo.params; | ||
@@ -48,88 +57,97 @@ tests[2].videoInfo.params.loop = '1'; | ||
}); | ||
QUnit.test("Playlist YouTube URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Playlist YouTube Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'youtube', | ||
id: 'yQaAGmHNn9s', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'video', | ||
params: { | ||
start: 100 | ||
} | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + '/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100', | ||
embed: yt4 + '/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100', | ||
}, | ||
urls: [ | ||
yt2 + '/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82#t=1m40', | ||
yt2 + '/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82&t=1m40', | ||
yt4 + '/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + '/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s', | ||
embed: yt4 + '/yQaAGmHNn9s?list=PL46F0A159EC02DF82', | ||
}, | ||
urls: [ | ||
yt2 + '/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82', | ||
yt4 + '/yQaAGmHNn9s?list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + | ||
'/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A', | ||
embed: yt4 + '/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82', | ||
}, | ||
urls: [ | ||
yt3 + '/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25', | ||
yt3 + '/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82', | ||
yt4 + '/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + | ||
'/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A#t=100', | ||
embed: yt4 + | ||
'/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100', | ||
}, | ||
urls: [ | ||
yt3 + | ||
'/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25#t=1m40', | ||
yt3 + | ||
'/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25&t=1m40', | ||
yt3 + | ||
'/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82&t=1m40', | ||
yt3 + | ||
'/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82#t=1m40', | ||
yt4 + '/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100' | ||
] | ||
}, { | ||
videoInfo: { | ||
provider: 'youtube', | ||
id: 'yQaAGmHNn9s', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'video', | ||
mediaType: 'playlist' | ||
}, | ||
formats: { | ||
long: yt1 + '/playlist?feature=share&list=PL46F0A159EC02DF82', | ||
embed: '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist', | ||
}, | ||
urls: [ | ||
yt2 + '/embed/videoseries?list=PL46F0A159EC02DF82', | ||
yt2 + '/playlist?list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: { | ||
provider: 'youtube', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'playlist', | ||
params: { | ||
start: 100, | ||
list: 'PL46F0A159EC02DF82', | ||
listType: 'playlist' | ||
} | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100', | ||
embed: '//youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100', | ||
}, | ||
urls: ['http://www.youtube.com/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82#t=1m40', | ||
'http://www.youtube.com/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82&t=1m40', | ||
'//youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s', | ||
embed: '//youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82', | ||
}, | ||
urls: ['http://www.youtube.com/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82', | ||
'//youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A', | ||
embed: '//youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82', | ||
}, | ||
urls: ['https://www.youtube.com/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25', | ||
'https://www.youtube.com/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82', | ||
'//youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A#t=100', | ||
embed: '//youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100', | ||
}, | ||
urls: ['https://www.youtube.com/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25#t=1m40', | ||
'https://www.youtube.com/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25&t=1m40', | ||
'https://www.youtube.com/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82&t=1m40', | ||
'https://www.youtube.com/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82#t=1m40', | ||
'//youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100' | ||
] | ||
}, { | ||
videoInfo: { | ||
provider: 'youtube', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'playlist', | ||
params: { | ||
list: 'PL46F0A159EC02DF82' | ||
} | ||
}, | ||
formats: { | ||
long: 'https://youtube.com/playlist?feature=share&list=PL46F0A159EC02DF82', | ||
embed: '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist', | ||
}, | ||
urls: ['http://www.youtube.com/embed/videoseries?list=PL46F0A159EC02DF82', | ||
'http://www.youtube.com/playlist?list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: { | ||
provider: 'youtube', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'playlist', | ||
params: { | ||
list: 'PL46F0A159EC02DF82', | ||
listType: 'playlist' | ||
} | ||
}, | ||
formats: { | ||
embed: '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist', | ||
}, | ||
urls: ['//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist'] | ||
}]; | ||
formats: { | ||
embed: '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist', | ||
}, | ||
urls: [ | ||
'//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist' | ||
] | ||
}]; | ||
delete tests[1].videoInfo.params.start; | ||
delete tests[1].videoInfo.params; | ||
delete tests[2].videoInfo.params.start; | ||
@@ -141,4 +159,4 @@ tests[2].videoInfo.params.index = tests[3].videoInfo.params.index = '25'; | ||
QUnit.test("Feed YouTube URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Feed YouTube Urls', function (assert) { | ||
'use strict'; | ||
var tests = [{ | ||
@@ -151,9 +169,10 @@ videoInfo: { | ||
formats: { | ||
long: 'https://youtube.com/watch?v=HRb7B9fPhfA', | ||
long: yt1 + '/watch?v=HRb7B9fPhfA', | ||
short: 'https://youtu.be/HRb7B9fPhfA', | ||
embed: '//youtube.com/embed/HRb7B9fPhfA', | ||
embed: yt4 + '/HRb7B9fPhfA', | ||
}, | ||
urls: ['https://gdata.youtube.com/feeds/api/videos/HRb7B9fPhfA/related', | ||
urls: [ | ||
'https://gdata.youtube.com/feeds/api/videos/HRb7B9fPhfA/related', | ||
'https://gdata.youtube.com/feeds/api/videos/HRb7B9fPhfA', | ||
'https://www.youtube.com/v/HRb7B9fPhfA' | ||
yt3 + '/v/HRb7B9fPhfA' | ||
] | ||
@@ -163,1 +182,54 @@ }]; | ||
}); | ||
QUnit.test('Image YouTube Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
shortImage: 'https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg', | ||
longImage: yt5 + '/vi/HRb7B9fPhfA/hqdefault.jpg' | ||
}, | ||
urls: ['https://i.ytimg.com/vi/HRb7B9fPhfA/0.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/1.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/2.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/3.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/mqdefault.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/sddefault.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/maxresdefault.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/0.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/1.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/2.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/3.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/hqdefault.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/mqdefault.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/sddefault.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/maxresdefault.jpg', | ||
] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test('Share YouTube Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'youtube', | ||
id: 'E14kBrDEvYo', | ||
mediaType: 'share' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://www.youtube.com/shared?ci=E14kBrDEvYo' | ||
}, | ||
urls: ['https://www.youtube.com/shared?ci=E14kBrDEvYo'] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); |
@@ -1,31 +0,39 @@ | ||
QUnit.test("urlParser Tests", function (assert) { | ||
"use strict"; | ||
var parser = new URLParser(); | ||
QUnit.test('urlParser Tests', function (assert) { | ||
'use strict'; | ||
var parser = new UrlParser(); | ||
parser.bind({ | ||
provider: 'foo', | ||
alternatives: ['bar'], | ||
parse: function (url) { | ||
return { | ||
url: url | ||
}; | ||
}, | ||
defaultFormat: 'long', | ||
formats: { | ||
long: function (vi, params) { | ||
return { | ||
videoInfo: vi, | ||
params: params | ||
}; | ||
} | ||
} | ||
}); | ||
function Plugin() { | ||
this.provider = 'foo'; | ||
this.alternatives = ['bar']; | ||
this.defaultFormat = 'long'; | ||
this.formats = { | ||
long: this.createLongUrl | ||
}; | ||
} | ||
Plugin.prototype.parse = function (url) { | ||
return { | ||
url: url | ||
}; | ||
}; | ||
Plugin.prototype.createLongUrl = function (vi, params) { | ||
return { | ||
videoInfo: vi, | ||
params: params | ||
}; | ||
}; | ||
parser.bind(new Plugin()); | ||
assert.notStrictEqual(parser.plugins.foo, undefined, 'Binding provider'); | ||
assert.notStrictEqual(parser.plugins.bar, undefined, 'Binding alternative'); | ||
assert.notStrictEqual(parser.plugins.bar, undefined, | ||
'Binding alternative'); | ||
assert.strictEqual(parser.parse('abc.def'), undefined, 'Undefined parse'); | ||
assert.strictEqual(parser.parse('http://bar.def').provider, 'foo', 'Alternative parse'); | ||
assert.strictEqual(parser.parse('https://abc.foo.def/ghi').provider, 'foo', 'Parse'); | ||
assert.strictEqual(parser.parse('//abc.foo.def/ghi').provider, 'foo', 'Parse'); | ||
assert.strictEqual(parser.parse('http://bar.def').provider, 'foo', | ||
'Alternative parse'); | ||
assert.strictEqual(parser.parse('https://abc.foo.def/ghi').provider, | ||
'foo', 'Parse'); | ||
assert.strictEqual(parser.parse('//abc.foo.def/ghi').provider, 'foo', | ||
'Parse'); | ||
@@ -58,11 +66,16 @@ var createObj1 = { | ||
}; | ||
assert.deepEqual(parser.create(createObj1).videoInfo, createObj1.videoInfo, 'Create'); | ||
assert.strictEqual(parser.create(createObj2), undefined, 'Create not existing format'); | ||
assert.strictEqual(parser.create(createObj3), undefined, 'Create not existing provider'); | ||
assert.deepEqual(parser.create(createObj4).params, createObj4.videoInfo.params, 'Create with internal params'); | ||
assert.deepEqual(parser.create(createObj1).videoInfo, createObj1.videoInfo, | ||
'Create'); | ||
assert.strictEqual(parser.create(createObj2), undefined, | ||
'Create not existing format'); | ||
assert.strictEqual(parser.create(createObj3), undefined, | ||
'Create not existing provider'); | ||
assert.deepEqual(parser.create(createObj4).params, | ||
createObj4.videoInfo.params, 'Create with internal params'); | ||
parser.bind({ | ||
provider: 'abc', | ||
formats: {} | ||
}); | ||
function Plugin2() { | ||
this.provider = 'abc'; | ||
this.formats = {}; | ||
} | ||
parser.bind(new Plugin2()); | ||
@@ -74,5 +87,6 @@ assert.strictEqual(parser.parse('http://abc.com'), undefined, 'No .parse'); | ||
if (urlParser.plugins.hasOwnProperty(plugin)) { | ||
assert.notStrictEqual(urlParser.plugins[plugin].defaultFormat, undefined, 'Defaultformat not undefined ' + plugin); | ||
assert.notStrictEqual(urlParser.plugins[plugin].defaultFormat, | ||
undefined, 'Defaultformat not undefined ' + plugin); | ||
} | ||
} | ||
}); |
/*jshint unused:false */ | ||
function assertUrlTest(assert, tests) { | ||
/*jshint unused:true */ | ||
"use strict"; | ||
'use strict'; | ||
tests.forEach(function (test) { | ||
@@ -9,4 +9,4 @@ test.urls.forEach(function (url) { | ||
}); | ||
for(var format in test.formats){ | ||
if(test.formats.hasOwnProperty(format)){ | ||
for (var format in test.formats) { | ||
if (test.formats.hasOwnProperty(format)) { | ||
assert.equal(urlParser.create({ | ||
@@ -22,32 +22,40 @@ videoInfo: test.videoInfo, | ||
QUnit.test("urlParser Tests", function (assert) { | ||
"use strict"; | ||
var parser = new URLParser(); | ||
QUnit.test('urlParser Tests', function (assert) { | ||
'use strict'; | ||
var parser = new UrlParser(); | ||
parser.bind({ | ||
provider: 'foo', | ||
alternatives: ['bar'], | ||
parse: function (url) { | ||
return { | ||
url: url | ||
}; | ||
}, | ||
defaultFormat: 'long', | ||
formats: { | ||
long: function (vi, params) { | ||
return { | ||
videoInfo: vi, | ||
params: params | ||
}; | ||
} | ||
} | ||
}); | ||
function Plugin() { | ||
this.provider = 'foo'; | ||
this.alternatives = ['bar']; | ||
this.defaultFormat = 'long'; | ||
this.formats = { | ||
long: this.createLongUrl | ||
}; | ||
} | ||
Plugin.prototype.parse = function (url) { | ||
return { | ||
url: url | ||
}; | ||
}; | ||
Plugin.prototype.createLongUrl = function (vi, params) { | ||
return { | ||
videoInfo: vi, | ||
params: params | ||
}; | ||
}; | ||
parser.bind(new Plugin()); | ||
assert.notStrictEqual(parser.plugins.foo, undefined, 'Binding provider'); | ||
assert.notStrictEqual(parser.plugins.bar, undefined, 'Binding alternative'); | ||
assert.notStrictEqual(parser.plugins.bar, undefined, | ||
'Binding alternative'); | ||
assert.strictEqual(parser.parse('abc.def'), undefined, 'Undefined parse'); | ||
assert.strictEqual(parser.parse('http://bar.def').provider, 'foo', 'Alternative parse'); | ||
assert.strictEqual(parser.parse('https://abc.foo.def/ghi').provider, 'foo', 'Parse'); | ||
assert.strictEqual(parser.parse('//abc.foo.def/ghi').provider, 'foo', 'Parse'); | ||
assert.strictEqual(parser.parse('http://bar.def').provider, 'foo', | ||
'Alternative parse'); | ||
assert.strictEqual(parser.parse('https://abc.foo.def/ghi').provider, | ||
'foo', 'Parse'); | ||
assert.strictEqual(parser.parse('//abc.foo.def/ghi').provider, 'foo', | ||
'Parse'); | ||
@@ -80,11 +88,16 @@ var createObj1 = { | ||
}; | ||
assert.deepEqual(parser.create(createObj1).videoInfo, createObj1.videoInfo, 'Create'); | ||
assert.strictEqual(parser.create(createObj2), undefined, 'Create not existing format'); | ||
assert.strictEqual(parser.create(createObj3), undefined, 'Create not existing provider'); | ||
assert.deepEqual(parser.create(createObj4).params, createObj4.videoInfo.params, 'Create with internal params'); | ||
assert.deepEqual(parser.create(createObj1).videoInfo, createObj1.videoInfo, | ||
'Create'); | ||
assert.strictEqual(parser.create(createObj2), undefined, | ||
'Create not existing format'); | ||
assert.strictEqual(parser.create(createObj3), undefined, | ||
'Create not existing provider'); | ||
assert.deepEqual(parser.create(createObj4).params, | ||
createObj4.videoInfo.params, 'Create with internal params'); | ||
parser.bind({ | ||
provider: 'abc', | ||
formats: {} | ||
}); | ||
function Plugin2() { | ||
this.provider = 'abc'; | ||
this.formats = {}; | ||
} | ||
parser.bind(new Plugin2()); | ||
@@ -96,3 +109,4 @@ assert.strictEqual(parser.parse('http://abc.com'), undefined, 'No .parse'); | ||
if (urlParser.plugins.hasOwnProperty(plugin)) { | ||
assert.notStrictEqual(urlParser.plugins[plugin].defaultFormat, undefined, 'Defaultformat not undefined ' + plugin); | ||
assert.notStrictEqual(urlParser.plugins[plugin].defaultFormat, | ||
undefined, 'Defaultformat not undefined ' + plugin); | ||
} | ||
@@ -102,4 +116,4 @@ } | ||
QUnit.test("TimeString Parser", function (assert) { | ||
"use strict"; | ||
QUnit.test('TimeString Parser', function (assert) { | ||
'use strict'; | ||
var s = 1, | ||
@@ -138,4 +152,4 @@ m = 60 * s, | ||
QUnit.test("GetQueryParams Tests", function (assert) { | ||
"use strict"; | ||
QUnit.test('GetQueryParams Tests', function (assert) { | ||
'use strict'; | ||
assert.deepEqual(getQueryParams(undefined), {}, 'Undefined argument'); | ||
@@ -160,7 +174,8 @@ assert.deepEqual(getQueryParams([]), {}, 'Not a string argument'); | ||
}, '?foo=bar&faz=baz'); | ||
assert.deepEqual(getQueryParams('http://foo.bar/test?foo=bar&faz=baz#fiz=biz'), { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
}, '?foo=bar&faz=baz#fiz=biz'); | ||
assert.deepEqual( | ||
getQueryParams('http://foo.bar/test?foo=bar&faz=baz#fiz=biz'), { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
}, '?foo=bar&faz=baz#fiz=biz'); | ||
assert.deepEqual(getQueryParams('http://foo.bar/test?foo=bar&faz=baz#fiz'), { | ||
@@ -173,4 +188,4 @@ foo: 'bar', | ||
QUnit.test("CombineParams Tests", function (assert) { | ||
"use strict"; | ||
QUnit.test('CombineParams Tests', function (assert) { | ||
'use strict'; | ||
assert.equal(combineParams(undefined), '', 'Undefined argument'); | ||
@@ -183,3 +198,3 @@ assert.equal(combineParams({}), '', 'No params object'); | ||
} | ||
}), '?foo=bar', "{foo:'bar'}"); | ||
}), '?foo=bar', '{foo:\'bar\'}'); | ||
assert.equal(combineParams({ | ||
@@ -190,10 +205,11 @@ params: { | ||
} | ||
}), '?faz=baz&foo=bar', "{foo:'bar',faz:'baz'}"); | ||
}), '?faz=baz&foo=bar', '{foo:\'bar\',faz:\'baz\'}'); | ||
assert.equal(combineParams({ | ||
params: { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
} | ||
}), '?faz=baz&fiz=biz&foo=bar', "{foo: 'bar',faz: 'baz',fiz: 'biz'}"); | ||
params: { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
} | ||
}), '?faz=baz&fiz=biz&foo=bar', | ||
'{foo: \'bar\',faz: \'baz\',fiz: \'biz\'}'); | ||
@@ -205,3 +221,3 @@ assert.equal(combineParams({ | ||
} | ||
}), '&foo=bar', "{foo:'bar'}"); | ||
}), '&foo=bar', '{foo:\'bar\'}'); | ||
assert.equal(combineParams({ | ||
@@ -213,43 +229,89 @@ hasParams: true, | ||
} | ||
}), '&faz=baz&foo=bar', "{foo:'bar',faz:'baz'}"); | ||
}), '&faz=baz&foo=bar', '{foo:\'bar\',faz:\'baz\'}'); | ||
assert.equal(combineParams({ | ||
hasParams: true, | ||
params: { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
} | ||
}), '&faz=baz&fiz=biz&foo=bar', "{foo: 'bar',faz: 'baz',fiz: 'biz'}"); | ||
hasParams: true, | ||
params: { | ||
foo: 'bar', | ||
faz: 'baz', | ||
fiz: 'biz' | ||
} | ||
}), '&faz=baz&fiz=biz&foo=bar', | ||
'{foo: \'bar\',faz: \'baz\',fiz: \'biz\'}'); | ||
}); | ||
QUnit.test("Dailymotion URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('CanalPlus Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'dailymotion', | ||
'id': 'x1e2b95', | ||
'mediaType': 'video' | ||
provider: 'canalplus', | ||
id: '1365175', | ||
mediaType: 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: 'http://player.canalplus.fr/embed/?vid=1365175' | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://dailymotion.com/video/x1e2b95', | ||
short: 'https://dai.ly/x1e2b95', | ||
embed: '//www.dailymotion.com/embed/video/x1e2b95' | ||
}, | ||
urls: ['http://www.dailymotion.com/video/x1e2b95_bruce-lee-nin-kayip-kedisi_animals', | ||
'http://www.dailymotion.com/video/x1e2b95', | ||
'http://dai.ly/x1e2b95', | ||
'http://www.dailymotion.com/embed/video/x1e2b95' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://dailymotion.com/video/x1e2b95?start=10', | ||
embed: '//www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
}, | ||
urls: ['http://www.dailymotion.com/video/x1e2b95?start=10', | ||
'http://www.dailymotion.com/video/x1e2b95_bruce-lee-nin-kayip-kedisi_animals?start=10', | ||
'http://www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
] | ||
}]; | ||
urls: [ | ||
'http://player.canalplus.fr/embed/?vid=1365175', | ||
'http://www.canalplus.fr/humour/pid1784-les-guignols.html?vid=1365175' | ||
] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test('Coub Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'coub', | ||
'id': 'by7sm', | ||
'mediaType': 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: '//coub.com/embed/by7sm', | ||
long: 'https://coub.com/view/by7sm', | ||
}, | ||
urls: [ | ||
'//coub.com/embed/by7sm', | ||
'https://coub.com/view/by7sm' | ||
] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test('Dailymotion Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'dailymotion', | ||
id: 'x1e2b95', | ||
mediaType: 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://dailymotion.com/video/x1e2b95', | ||
short: 'https://dai.ly/x1e2b95', | ||
embed: '//www.dailymotion.com/embed/video/x1e2b95' | ||
}, | ||
urls: [ | ||
'http://www.dailymotion.com/video/x1e2b95\ | ||
_bruce-lee-nin-kayip-kedisi_animals', | ||
'http://www.dailymotion.com/video/x1e2b95', | ||
'http://dai.ly/x1e2b95', | ||
'http://www.dailymotion.com/embed/video/x1e2b95' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://dailymotion.com/video/x1e2b95?start=10', | ||
embed: '//www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
}, | ||
urls: ['http://www.dailymotion.com/video/x1e2b95?start=10', | ||
'http://www.dailymotion.com/video/x1e2b95\ | ||
_bruce-lee-nin-kayip-kedisi_animals?start=10', | ||
'http://www.dailymotion.com/embed/video/x1e2b95?start=10' | ||
] | ||
}]; | ||
tests[1].videoInfo.params = { | ||
@@ -262,89 +324,140 @@ start: 10 | ||
QUnit.test("Twitch Stream URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Twitch Stream Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'twitch', | ||
'channel': 'tsm_wildturtle', | ||
'mediaType': 'stream' | ||
provider: 'twitch', | ||
channel: 'rains8', | ||
mediaType: 'stream' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/rains8', | ||
embed: 'https://player.twitch.tv/?channel=rains8' | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/tsm_wildturtle', | ||
embed: '//www.twitch.tv/tsm_wildturtle/embed' | ||
}, | ||
urls: ['http://www.twitch.tv/tsm_wildturtle', | ||
'http://www.twitch.tv/widgets/live_embed_player.swf?channel=tsm_wildturtle', | ||
'http://twitch.tv/tsm_wildturtle/chat?popout=', | ||
'//www.twitch.tv/tsm_wildturtle/embed' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/tsm_wildturtle/c/2724914', | ||
}, | ||
urls: ['http://www.twitch.tv/tsm_wildturtle/c/2724914'] | ||
}]; | ||
tests[1].videoInfo.id = '2724914'; | ||
tests[1].videoInfo.idPrefix = 'c'; | ||
tests[1].videoInfo.mediaType = 'video'; | ||
urls: ['http://www.twitch.tv/rains8', | ||
'http://www.twitch.tv/widgets/live_embed_player.swf\ | ||
?channel=rains8', | ||
'http://twitch.tv/rains8/chat', | ||
'//www.twitch.tv/rains8/embed' | ||
] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test("Vimeo URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Twitch Video Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'vimeo', | ||
'id': '97276391', | ||
'mediaType': 'video' | ||
provider: 'twitch', | ||
id: 'v75292411', | ||
channel: 'rains8', | ||
mediaType: 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/rains8/v/75292411', | ||
embed: 'https://player.twitch.tv/?video=v75292411' | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/97276391', | ||
embed: '//player.vimeo.com/video/97276391' | ||
}, | ||
urls: ['https://vimeo.com/97276391', | ||
'https://vimeo.com/channels/staffpicks/97276391', | ||
'//player.vimeo.com/video/97276391' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/96186586', | ||
embed: '//player.vimeo.com/video/96186586' | ||
}, | ||
urls: ['https://vimeo.com/album/2903155/video/96186586', | ||
'//player.vimeo.com/video/96186586' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/97688625', | ||
embed: '//player.vimeo.com/video/97688625' | ||
}, | ||
urls: ['https://vimeo.com/groups/shortfilms/videos/97688625', | ||
'//player.vimeo.com/video/97688625', | ||
'https://vimeo.com/groups/1minute/videos/97688625' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/24069938', | ||
embed: '//player.vimeo.com/video/24069938' | ||
}, | ||
urls: ['http://vimeopro.com/staff/frame/video/24069938', | ||
'//player.vimeo.com/video/24069938' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/36881035#t=208', | ||
embed: '//player.vimeo.com/video/36881035#t=208' | ||
}, | ||
urls: ['https://vimeo.com/36881035#t=3m28s', | ||
'//player.vimeo.com/video/36881035#t=3m28s' | ||
] | ||
}]; | ||
urls: ['http://www.twitch.tv/rains8/v/75292411'] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://twitch.tv/rains8/v/75292411?t=90s', | ||
embed: 'https://player.twitch.tv/?t=90s&video=v75292411' | ||
}, | ||
urls: ['https://www.twitch.tv/rains8/v/75292411?t=1m30s'] | ||
}]; | ||
tests[1].videoInfo.params = { | ||
start: 90 | ||
}; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test('Twitch Embed Video Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'twitch', | ||
id: 'v75292411', | ||
mediaType: 'embed-video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: 'https://player.twitch.tv/?video=v75292411' | ||
}, | ||
urls: [ | ||
'https://player.twitch.tv/?video=v75292411' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: 'https://player.twitch.tv/?t=90s&video=v75292411' | ||
}, | ||
urls: [ | ||
'https://player.twitch.tv/?video=v75292411&t=1m30s' | ||
] | ||
}]; | ||
tests[1].videoInfo.params = { | ||
start: 90 | ||
}; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test('Vimeo Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'vimeo', | ||
'id': '97276391', | ||
'mediaType': 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/97276391', | ||
embed: '//player.vimeo.com/video/97276391' | ||
}, | ||
urls: ['https://vimeo.com/97276391', | ||
'https://vimeo.com/channels/staffpicks/97276391', | ||
'//player.vimeo.com/video/97276391' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/96186586', | ||
embed: '//player.vimeo.com/video/96186586' | ||
}, | ||
urls: ['https://vimeo.com/album/2903155/video/96186586', | ||
'//player.vimeo.com/video/96186586' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/97688625', | ||
embed: '//player.vimeo.com/video/97688625' | ||
}, | ||
urls: ['https://vimeo.com/groups/shortfilms/videos/97688625', | ||
'//player.vimeo.com/video/97688625', | ||
'https://vimeo.com/groups/1minute/videos/97688625' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/24069938', | ||
embed: '//player.vimeo.com/video/24069938' | ||
}, | ||
urls: ['http://vimeopro.com/staff/frame/video/24069938', | ||
'//player.vimeo.com/video/24069938' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://vimeo.com/36881035#t=208', | ||
embed: '//player.vimeo.com/video/36881035#t=208' | ||
}, | ||
urls: ['https://vimeo.com/36881035#t=3m28s', | ||
'//player.vimeo.com/video/36881035#t=3m28s' | ||
] | ||
}]; | ||
tests[1].videoInfo.id = '96186586'; | ||
@@ -360,44 +473,53 @@ tests[2].videoInfo.id = '97688625'; | ||
QUnit.test("Regular YouTube URLs", function (assert) { | ||
"use strict"; | ||
var yt1 = 'https://youtube.com'; | ||
var yt2 = 'http://www.youtube.com'; | ||
var yt3 = 'https://www.youtube.com'; | ||
var yt4 = '//youtube.com/embed'; | ||
var yt5 = 'https://img.youtube.com'; | ||
QUnit.test('Regular YouTube Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video', | ||
params: { | ||
start: 30 | ||
} | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video', | ||
params: { | ||
start: 30 | ||
} | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + '/watch?v=HRb7B9fPhfA#t=30', | ||
embed: yt4 + '/HRb7B9fPhfA?start=30', | ||
short: 'https://youtu.be/HRb7B9fPhfA#t=30' | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?v=HRb7B9fPhfA#t=30', | ||
embed: '//youtube.com/embed/HRb7B9fPhfA?start=30', | ||
short: 'https://youtu.be/HRb7B9fPhfA#t=30' | ||
}, | ||
urls: ['http://www.youtube.com/watch?v=HRb7B9fPhfA#t=30s', | ||
'http://www.youtube.com/watch?v=HRb7B9fPhfA&t=30s', | ||
'https://m.youtube.com/details?v=HRb7B9fPhfA#t=30s', | ||
'http://youtu.be/HRb7B9fPhfA?t=30s', | ||
'http://youtu.be/HRb7B9fPhfA#t=30s', | ||
'//youtube.com/embed/HRb7B9fPhfA?start=30', | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?v=HRb7B9fPhfA', | ||
embed: '//youtube.com/embed/HRb7B9fPhfA', | ||
short: 'https://youtu.be/HRb7B9fPhfA' | ||
}, | ||
urls: ['http://www.youtube.com/watch?v=HRb7B9fPhfA', | ||
'http://youtu.be/HRb7B9fPhfA', | ||
'https://m.youtube.com/details?v=HRb7B9fPhfA' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: '//youtube.com/embed/HRb7B9fPhfA?loop=1&playlist=HRb7B9fPhfA&start=30' | ||
}, | ||
urls: ['//youtube.com/embed/HRb7B9fPhfA?loop=1&list=HRb7B9fPhfA&start=30'] | ||
}]; | ||
urls: [yt2 + '/watch?v=HRb7B9fPhfA#t=30s', | ||
yt2 + '/watch?v=HRb7B9fPhfA&t=30s', | ||
'https://m.youtube.com/details?v=HRb7B9fPhfA#t=30s', | ||
'http://youtu.be/HRb7B9fPhfA?t=30s', | ||
'http://youtu.be/HRb7B9fPhfA#t=30s', | ||
yt4 + '/HRb7B9fPhfA?start=30', | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + '/watch?v=HRb7B9fPhfA', | ||
embed: yt4 + '/HRb7B9fPhfA', | ||
short: 'https://youtu.be/HRb7B9fPhfA', | ||
shortImage: 'https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg', | ||
longImage: yt5 + '/vi/HRb7B9fPhfA/hqdefault.jpg' | ||
}, | ||
urls: [yt2 + '/watch?v=HRb7B9fPhfA', | ||
'http://youtu.be/HRb7B9fPhfA', | ||
'https://m.youtube.com/details?v=HRb7B9fPhfA' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: yt4 + '/HRb7B9fPhfA?loop=1&playlist=HRb7B9fPhfA&start=30' | ||
}, | ||
urls: [ | ||
yt4 + '/HRb7B9fPhfA?loop=1&list=HRb7B9fPhfA&start=30' | ||
] | ||
}]; | ||
delete tests[1].videoInfo.params; | ||
@@ -408,88 +530,97 @@ tests[2].videoInfo.params.loop = '1'; | ||
}); | ||
QUnit.test("Playlist YouTube URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Playlist YouTube Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'youtube', | ||
id: 'yQaAGmHNn9s', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'video', | ||
params: { | ||
start: 100 | ||
} | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + '/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100', | ||
embed: yt4 + '/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100', | ||
}, | ||
urls: [ | ||
yt2 + '/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82#t=1m40', | ||
yt2 + '/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82&t=1m40', | ||
yt4 + '/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + '/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s', | ||
embed: yt4 + '/yQaAGmHNn9s?list=PL46F0A159EC02DF82', | ||
}, | ||
urls: [ | ||
yt2 + '/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82', | ||
yt4 + '/yQaAGmHNn9s?list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + | ||
'/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A', | ||
embed: yt4 + '/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82', | ||
}, | ||
urls: [ | ||
yt3 + '/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25', | ||
yt3 + '/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82', | ||
yt4 + '/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: yt1 + | ||
'/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A#t=100', | ||
embed: yt4 + | ||
'/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100', | ||
}, | ||
urls: [ | ||
yt3 + | ||
'/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25#t=1m40', | ||
yt3 + | ||
'/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25&t=1m40', | ||
yt3 + | ||
'/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82&t=1m40', | ||
yt3 + | ||
'/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82#t=1m40', | ||
yt4 + '/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100' | ||
] | ||
}, { | ||
videoInfo: { | ||
provider: 'youtube', | ||
id: 'yQaAGmHNn9s', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'video', | ||
mediaType: 'playlist' | ||
}, | ||
formats: { | ||
long: yt1 + '/playlist?feature=share&list=PL46F0A159EC02DF82', | ||
embed: '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist', | ||
}, | ||
urls: [ | ||
yt2 + '/embed/videoseries?list=PL46F0A159EC02DF82', | ||
yt2 + '/playlist?list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: { | ||
provider: 'youtube', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'playlist', | ||
params: { | ||
start: 100, | ||
list: 'PL46F0A159EC02DF82', | ||
listType: 'playlist' | ||
} | ||
}, | ||
tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s#t=100', | ||
embed: '//youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100', | ||
}, | ||
urls: ['http://www.youtube.com/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82#t=1m40', | ||
'http://www.youtube.com/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82&t=1m40', | ||
'//youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82&start=100' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?list=PL46F0A159EC02DF82&v=yQaAGmHNn9s', | ||
embed: '//youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82', | ||
}, | ||
urls: ['http://www.youtube.com/watch?v=yQaAGmHNn9s&list=PL46F0A159EC02DF82', | ||
'//youtube.com/embed/yQaAGmHNn9s?list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A', | ||
embed: '//youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82', | ||
}, | ||
urls: ['https://www.youtube.com/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25', | ||
'https://www.youtube.com/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82', | ||
'//youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://youtube.com/watch?index=25&list=PL46F0A159EC02DF82&v=6xLcSTDeB7A#t=100', | ||
embed: '//youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100', | ||
}, | ||
urls: ['https://www.youtube.com/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25#t=1m40', | ||
'https://www.youtube.com/watch?v=6xLcSTDeB7A&list=PL46F0A159EC02DF82&index=25&t=1m40', | ||
'https://www.youtube.com/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82&t=1m40', | ||
'https://www.youtube.com/watch?v=6xLcSTDeB7A&index=25&list=PL46F0A159EC02DF82#t=1m40', | ||
'//youtube.com/embed/6xLcSTDeB7A?index=25&list=PL46F0A159EC02DF82&start=100' | ||
] | ||
}, { | ||
videoInfo: { | ||
provider: 'youtube', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'playlist', | ||
params: { | ||
list: 'PL46F0A159EC02DF82' | ||
} | ||
}, | ||
formats: { | ||
long: 'https://youtube.com/playlist?feature=share&list=PL46F0A159EC02DF82', | ||
embed: '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist', | ||
}, | ||
urls: ['http://www.youtube.com/embed/videoseries?list=PL46F0A159EC02DF82', | ||
'http://www.youtube.com/playlist?list=PL46F0A159EC02DF82' | ||
] | ||
}, { | ||
videoInfo: { | ||
provider: 'youtube', | ||
list: 'PL46F0A159EC02DF82', | ||
mediaType: 'playlist', | ||
params: { | ||
list: 'PL46F0A159EC02DF82', | ||
listType: 'playlist' | ||
} | ||
}, | ||
formats: { | ||
embed: '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist', | ||
}, | ||
urls: ['//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist'] | ||
}]; | ||
formats: { | ||
embed: '//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist', | ||
}, | ||
urls: [ | ||
'//youtube.com/embed?list=PL46F0A159EC02DF82&listType=playlist' | ||
] | ||
}]; | ||
delete tests[1].videoInfo.params.start; | ||
delete tests[1].videoInfo.params; | ||
delete tests[2].videoInfo.params.start; | ||
@@ -501,4 +632,4 @@ tests[2].videoInfo.params.index = tests[3].videoInfo.params.index = '25'; | ||
QUnit.test("Feed YouTube URLs", function (assert) { | ||
"use strict"; | ||
QUnit.test('Feed YouTube Urls', function (assert) { | ||
'use strict'; | ||
var tests = [{ | ||
@@ -511,9 +642,10 @@ videoInfo: { | ||
formats: { | ||
long: 'https://youtube.com/watch?v=HRb7B9fPhfA', | ||
long: yt1 + '/watch?v=HRb7B9fPhfA', | ||
short: 'https://youtu.be/HRb7B9fPhfA', | ||
embed: '//youtube.com/embed/HRb7B9fPhfA', | ||
embed: yt4 + '/HRb7B9fPhfA', | ||
}, | ||
urls: ['https://gdata.youtube.com/feeds/api/videos/HRb7B9fPhfA/related', | ||
urls: [ | ||
'https://gdata.youtube.com/feeds/api/videos/HRb7B9fPhfA/related', | ||
'https://gdata.youtube.com/feeds/api/videos/HRb7B9fPhfA', | ||
'https://www.youtube.com/v/HRb7B9fPhfA' | ||
yt3 + '/v/HRb7B9fPhfA' | ||
] | ||
@@ -523,1 +655,81 @@ }]; | ||
}); | ||
QUnit.test('Image YouTube Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'youtube', | ||
id: 'HRb7B9fPhfA', | ||
mediaType: 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
shortImage: 'https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg', | ||
longImage: yt5 + '/vi/HRb7B9fPhfA/hqdefault.jpg' | ||
}, | ||
urls: ['https://i.ytimg.com/vi/HRb7B9fPhfA/0.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/1.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/2.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/3.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/hqdefault.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/mqdefault.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/sddefault.jpg', | ||
'https://i.ytimg.com/vi/HRb7B9fPhfA/maxresdefault.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/0.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/1.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/2.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/3.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/hqdefault.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/mqdefault.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/sddefault.jpg', | ||
'https://img.youtube.com/vi/HRb7B9fPhfA/maxresdefault.jpg', | ||
] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); | ||
QUnit.test('Share YouTube Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
provider: 'youtube', | ||
id: 'E14kBrDEvYo', | ||
mediaType: 'share' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
long: 'https://www.youtube.com/shared?ci=E14kBrDEvYo' | ||
}, | ||
urls: ['https://www.youtube.com/shared?ci=E14kBrDEvYo'] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); | ||
var vk1 = 'http://static.youku.com/v1.0.0638/v/swf/'; | ||
QUnit.test('Youku Urls', function (assert) { | ||
'use strict'; | ||
var vi = { | ||
'provider': 'youku', | ||
'id': 'XMTQ3OTM4MzMxMg', | ||
'mediaType': 'video' | ||
}; | ||
var tests = [{ | ||
videoInfo: cloneObject(vi), | ||
formats: { | ||
embed: 'http://player.youku.com/embed/XMTQ3OTM4MzMxMg', | ||
long: 'http://v.youku.com/v_show/id_XMTQ3OTM4MzMxMg', | ||
flash: 'http://player.youku.com/player.php/sid/XMTQ3OTM4MzMxMg/v.swf', | ||
static: vk1 + 'loader.swf?VideoIDS=XMTQ3OTM4MzMxMg' | ||
}, | ||
urls: [ | ||
'http://player.youku.com/embed/XMTQ3OTM4MzMxMg', | ||
'http://player.youku.com/player.php/sid/XMTQ3OTM4MzMxMg==/v.swf', | ||
'http://v.youku.com/v_show/id_XMTQ3OTM4MzMxMg', | ||
vk1 + 'loader.swf?VideoIDS=XMTQ3OTM4MzMxMg%3D%3D' | ||
] | ||
}]; | ||
assertUrlTest(assert, tests); | ||
}); |
176297
19
4287
648