@ormoshe/js-video-url-parser 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/jsVideoUrlParser.js +1571 -0
- package/dist/jsVideoUrlParser.min.js +1 -0
- package/lib/base.d.ts +2 -0
- package/lib/base.js +3 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +18 -0
- package/lib/provider/allocine.d.ts +13 -0
- package/lib/provider/allocine.js +36 -0
- package/lib/provider/base-provider.d.ts +13 -0
- package/lib/provider/canalplus.d.ts +13 -0
- package/lib/provider/canalplus.js +46 -0
- package/lib/provider/coub.d.ts +13 -0
- package/lib/provider/coub.js +54 -0
- package/lib/provider/dailymotion.d.ts +14 -0
- package/lib/provider/dailymotion.js +70 -0
- package/lib/provider/facebook.d.ts +14 -0
- package/lib/provider/facebook.js +78 -0
- package/lib/provider/loom.d.ts +13 -0
- package/lib/provider/loom.js +51 -0
- package/lib/provider/soundcloud.d.ts +16 -0
- package/lib/provider/soundcloud.js +125 -0
- package/lib/provider/teachertube.d.ts +14 -0
- package/lib/provider/teachertube.js +110 -0
- package/lib/provider/ted.d.ts +14 -0
- package/lib/provider/ted.js +96 -0
- package/lib/provider/tiktok.d.ts +14 -0
- package/lib/provider/tiktok.js +50 -0
- package/lib/provider/twitch.d.ts +15 -0
- package/lib/provider/twitch.js +150 -0
- package/lib/provider/vimeo.d.ts +14 -0
- package/lib/provider/vimeo.js +89 -0
- package/lib/provider/voomly.d.ts +14 -0
- package/lib/provider/voomly.js +46 -0
- package/lib/provider/wistia.d.ts +15 -0
- package/lib/provider/wistia.js +112 -0
- package/lib/provider/youku.d.ts +13 -0
- package/lib/provider/youku.js +83 -0
- package/lib/provider/youtube.d.ts +15 -0
- package/lib/provider/youtube.js +205 -0
- package/lib/testUrls.js +11 -0
- package/lib/urlParser.d.ts +23 -0
- package/lib/urlParser.js +81 -0
- package/lib/util.js +104 -0
- package/package.json +59 -0
|
@@ -0,0 +1,1571 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
|
4
|
+
(global = global || self, global.urlParser = factory());
|
|
5
|
+
}(this, (function () { 'use strict';
|
|
6
|
+
|
|
7
|
+
function _typeof(obj) {
|
|
8
|
+
"@babel/helpers - typeof";
|
|
9
|
+
|
|
10
|
+
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
|
11
|
+
_typeof = function (obj) {
|
|
12
|
+
return typeof obj;
|
|
13
|
+
};
|
|
14
|
+
} else {
|
|
15
|
+
_typeof = function (obj) {
|
|
16
|
+
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return _typeof(obj);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
var getQueryParams = function getQueryParams(qs) {
|
|
24
|
+
if (typeof qs !== 'string') {
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
qs = qs.split('+').join(' ');
|
|
29
|
+
var params = {};
|
|
30
|
+
var match = qs.match(/(?:[?](?:[^=]+)=(?:[^&#]*)(?:[&](?:[^=]+)=(?:[^&#]*))*(?:[#].*)?)|(?:[#].*)/);
|
|
31
|
+
var split;
|
|
32
|
+
|
|
33
|
+
if (match === null) {
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
split = match[0].substr(1).split(/[&#=]/);
|
|
38
|
+
|
|
39
|
+
for (var i = 0; i < split.length; i += 2) {
|
|
40
|
+
params[decodeURIComponent(split[i])] = decodeURIComponent(split[i + 1] || '');
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return params;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
var combineParams = function combineParams(params, hasParams) {
|
|
47
|
+
if (_typeof(params) !== 'object') {
|
|
48
|
+
return '';
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
var combined = '';
|
|
52
|
+
var i = 0;
|
|
53
|
+
var keys = Object.keys(params);
|
|
54
|
+
|
|
55
|
+
if (keys.length === 0) {
|
|
56
|
+
return '';
|
|
57
|
+
} //always have parameters in the same order
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
keys.sort();
|
|
61
|
+
|
|
62
|
+
if (!hasParams) {
|
|
63
|
+
combined += '?' + keys[0] + '=' + params[keys[0]];
|
|
64
|
+
i += 1;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
for (; i < keys.length; i += 1) {
|
|
68
|
+
combined += '&' + keys[i] + '=' + params[keys[i]];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return combined;
|
|
72
|
+
}; //parses strings like 1h30m20s to seconds
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
function getLetterTime(timeString) {
|
|
76
|
+
var totalSeconds = 0;
|
|
77
|
+
var timeValues = {
|
|
78
|
+
's': 1,
|
|
79
|
+
'm': 1 * 60,
|
|
80
|
+
'h': 1 * 60 * 60,
|
|
81
|
+
'd': 1 * 60 * 60 * 24,
|
|
82
|
+
'w': 1 * 60 * 60 * 24 * 7
|
|
83
|
+
};
|
|
84
|
+
var timePairs; //expand to "1 h 30 m 20 s" and split
|
|
85
|
+
|
|
86
|
+
timeString = timeString.replace(/([smhdw])/g, ' $1 ').trim();
|
|
87
|
+
timePairs = timeString.split(' ');
|
|
88
|
+
|
|
89
|
+
for (var i = 0; i < timePairs.length; i += 2) {
|
|
90
|
+
totalSeconds += parseInt(timePairs[i], 10) * timeValues[timePairs[i + 1] || 's'];
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return totalSeconds;
|
|
94
|
+
} //parses strings like 1:30:20 to seconds
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
function getColonTime(timeString) {
|
|
98
|
+
var totalSeconds = 0;
|
|
99
|
+
var timeValues = [1, 1 * 60, 1 * 60 * 60, 1 * 60 * 60 * 24, 1 * 60 * 60 * 24 * 7];
|
|
100
|
+
var timePairs = timeString.split(':');
|
|
101
|
+
|
|
102
|
+
for (var i = 0; i < timePairs.length; i++) {
|
|
103
|
+
totalSeconds += parseInt(timePairs[i], 10) * timeValues[timePairs.length - i - 1];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return totalSeconds;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var getTime = function getTime(timeString) {
|
|
110
|
+
if (typeof timeString === 'undefined') {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (timeString.match(/^(\d+[smhdw]?)+$/)) {
|
|
115
|
+
return getLetterTime(timeString);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (timeString.match(/^(\d+:?)+$/)) {
|
|
119
|
+
return getColonTime(timeString);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return 0;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
var util = {
|
|
126
|
+
getQueryParams: getQueryParams,
|
|
127
|
+
combineParams: combineParams,
|
|
128
|
+
getTime: getTime
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
var getQueryParams$1 = util.getQueryParams;
|
|
132
|
+
|
|
133
|
+
function UrlParser() {
|
|
134
|
+
for (var _i = 0, _arr = ['parseProvider', 'parse', 'bind', 'create']; _i < _arr.length; _i++) {
|
|
135
|
+
var key = _arr[_i];
|
|
136
|
+
this[key] = this[key].bind(this);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
this.plugins = {};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
var urlParser = UrlParser;
|
|
143
|
+
|
|
144
|
+
UrlParser.prototype.parseProvider = function (url) {
|
|
145
|
+
var match = url.match(/(?:(?:https?:)?\/\/)?(?:[^.]+\.)?(\w+)\./i);
|
|
146
|
+
return match ? match[1] : undefined;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
UrlParser.prototype.parse = function (url) {
|
|
150
|
+
if (typeof url === 'undefined') {
|
|
151
|
+
return undefined;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
var provider = this.parseProvider(url);
|
|
155
|
+
var result;
|
|
156
|
+
var plugin = this.plugins[provider];
|
|
157
|
+
|
|
158
|
+
if (!provider || !plugin || !plugin.parse) {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
result = plugin.parse.call(plugin, url, getQueryParams$1(url));
|
|
163
|
+
|
|
164
|
+
if (result) {
|
|
165
|
+
result = removeEmptyParameters(result);
|
|
166
|
+
result.provider = plugin.provider;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
return result;
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
UrlParser.prototype.bind = function (plugin) {
|
|
173
|
+
this.plugins[plugin.provider] = plugin;
|
|
174
|
+
|
|
175
|
+
if (plugin.alternatives) {
|
|
176
|
+
for (var i = 0; i < plugin.alternatives.length; i += 1) {
|
|
177
|
+
this.plugins[plugin.alternatives[i]] = plugin;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
UrlParser.prototype.create = function (op) {
|
|
183
|
+
if (_typeof(op) !== 'object' || _typeof(op.videoInfo) !== 'object') {
|
|
184
|
+
return undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var vi = op.videoInfo;
|
|
188
|
+
var params = op.params;
|
|
189
|
+
var plugin = this.plugins[vi.provider];
|
|
190
|
+
params = params === 'internal' ? vi.params : params || {};
|
|
191
|
+
|
|
192
|
+
if (plugin) {
|
|
193
|
+
op.format = op.format || plugin.defaultFormat; // eslint-disable-next-line no-prototype-builtins
|
|
194
|
+
|
|
195
|
+
if (plugin.formats.hasOwnProperty(op.format)) {
|
|
196
|
+
return plugin.formats[op.format].apply(plugin, [vi, Object.assign({}, params)]);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return undefined;
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
function removeEmptyParameters(result) {
|
|
204
|
+
if (result.params && Object.keys(result.params).length === 0) {
|
|
205
|
+
delete result.params;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return result;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
var parser = new urlParser();
|
|
212
|
+
var base = parser;
|
|
213
|
+
|
|
214
|
+
function Allocine() {
|
|
215
|
+
this.provider = 'allocine';
|
|
216
|
+
this.alternatives = [];
|
|
217
|
+
this.defaultFormat = 'embed';
|
|
218
|
+
this.formats = {
|
|
219
|
+
embed: this.createEmbedUrl
|
|
220
|
+
};
|
|
221
|
+
this.mediaTypes = {
|
|
222
|
+
VIDEO: 'video'
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
Allocine.prototype.parseUrl = function (url) {
|
|
227
|
+
var match = url.match(/(?:\/video\/player_gen_cmedia=)([A-Za-z0-9]+)/i);
|
|
228
|
+
return match ? match[1] : undefined;
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
Allocine.prototype.parse = function (url) {
|
|
232
|
+
var result = {
|
|
233
|
+
mediaType: this.mediaTypes.VIDEO,
|
|
234
|
+
id: this.parseUrl(url)
|
|
235
|
+
};
|
|
236
|
+
return result.id ? result : undefined;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
Allocine.prototype.createEmbedUrl = function (vi) {
|
|
240
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
return 'https://player.allocine.fr/' + vi.id + '.html';
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
base.bind(new Allocine());
|
|
248
|
+
|
|
249
|
+
var combineParams$1 = util.combineParams;
|
|
250
|
+
|
|
251
|
+
function CanalPlus() {
|
|
252
|
+
this.provider = 'canalplus';
|
|
253
|
+
this.defaultFormat = 'embed';
|
|
254
|
+
this.formats = {
|
|
255
|
+
embed: this.createEmbedUrl
|
|
256
|
+
};
|
|
257
|
+
this.mediaTypes = {
|
|
258
|
+
VIDEO: 'video'
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
CanalPlus.prototype.parseParameters = function (params) {
|
|
263
|
+
delete params.vid;
|
|
264
|
+
return params;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
CanalPlus.prototype.parse = function (url, params) {
|
|
268
|
+
var _this = this;
|
|
269
|
+
|
|
270
|
+
var result = {
|
|
271
|
+
mediaType: this.mediaTypes.VIDEO,
|
|
272
|
+
id: params.vid
|
|
273
|
+
};
|
|
274
|
+
result.params = _this.parseParameters(params);
|
|
275
|
+
|
|
276
|
+
if (!result.id) {
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return result;
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
CanalPlus.prototype.createEmbedUrl = function (vi, params) {
|
|
284
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
var url = 'http://player.canalplus.fr/embed/';
|
|
289
|
+
params.vid = vi.id;
|
|
290
|
+
url += combineParams$1(params);
|
|
291
|
+
return url;
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
base.bind(new CanalPlus());
|
|
295
|
+
|
|
296
|
+
var combineParams$2 = util.combineParams;
|
|
297
|
+
|
|
298
|
+
function Coub() {
|
|
299
|
+
this.provider = 'coub';
|
|
300
|
+
this.defaultFormat = 'long';
|
|
301
|
+
this.formats = {
|
|
302
|
+
"long": this.createLongUrl,
|
|
303
|
+
embed: this.createEmbedUrl
|
|
304
|
+
};
|
|
305
|
+
this.mediaTypes = {
|
|
306
|
+
VIDEO: 'video'
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
Coub.prototype.parseUrl = function (url) {
|
|
311
|
+
var match = url.match(/(?:embed|view)\/([a-zA-Z\d]+)/i);
|
|
312
|
+
return match ? match[1] : undefined;
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
Coub.prototype.parse = function (url, params) {
|
|
316
|
+
var result = {
|
|
317
|
+
mediaType: this.mediaTypes.VIDEO,
|
|
318
|
+
params: params,
|
|
319
|
+
id: this.parseUrl(url)
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
if (!result.id) {
|
|
323
|
+
return undefined;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
return result;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
Coub.prototype.createUrl = function (baseUrl, vi, params) {
|
|
330
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
331
|
+
return undefined;
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
var url = baseUrl + vi.id;
|
|
335
|
+
url += combineParams$2(params);
|
|
336
|
+
return url;
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
Coub.prototype.createLongUrl = function (vi, params) {
|
|
340
|
+
return this.createUrl('https://coub.com/view/', vi, params);
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
Coub.prototype.createEmbedUrl = function (vi, params) {
|
|
344
|
+
return this.createUrl('//coub.com/embed/', vi, params);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
base.bind(new Coub());
|
|
348
|
+
|
|
349
|
+
var combineParams$3 = util.combineParams,
|
|
350
|
+
getTime$1 = util.getTime;
|
|
351
|
+
|
|
352
|
+
function Dailymotion() {
|
|
353
|
+
this.provider = 'dailymotion';
|
|
354
|
+
this.alternatives = ['dai'];
|
|
355
|
+
this.defaultFormat = 'long';
|
|
356
|
+
this.formats = {
|
|
357
|
+
"short": this.createShortUrl,
|
|
358
|
+
"long": this.createLongUrl,
|
|
359
|
+
embed: this.createEmbedUrl,
|
|
360
|
+
image: this.createImageUrl
|
|
361
|
+
};
|
|
362
|
+
this.mediaTypes = {
|
|
363
|
+
VIDEO: 'video'
|
|
364
|
+
};
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
Dailymotion.prototype.parseParameters = function (params) {
|
|
368
|
+
return this.parseTime(params);
|
|
369
|
+
};
|
|
370
|
+
|
|
371
|
+
Dailymotion.prototype.parseTime = function (params) {
|
|
372
|
+
if (params.start) {
|
|
373
|
+
params.start = getTime$1(params.start);
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
return params;
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
Dailymotion.prototype.parseUrl = function (url) {
|
|
380
|
+
var match = url.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i);
|
|
381
|
+
return match ? match[1] : undefined;
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
Dailymotion.prototype.parse = function (url, params) {
|
|
385
|
+
var _this = this;
|
|
386
|
+
|
|
387
|
+
var result = {
|
|
388
|
+
mediaType: this.mediaTypes.VIDEO,
|
|
389
|
+
params: _this.parseParameters(params),
|
|
390
|
+
id: _this.parseUrl(url)
|
|
391
|
+
};
|
|
392
|
+
return result.id ? result : undefined;
|
|
393
|
+
};
|
|
394
|
+
|
|
395
|
+
Dailymotion.prototype.createUrl = function (base, vi, params) {
|
|
396
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
return base + vi.id + combineParams$3(params);
|
|
401
|
+
};
|
|
402
|
+
|
|
403
|
+
Dailymotion.prototype.createShortUrl = function (vi, params) {
|
|
404
|
+
return this.createUrl('https://dai.ly/', vi, params);
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
Dailymotion.prototype.createLongUrl = function (vi, params) {
|
|
408
|
+
return this.createUrl('https://dailymotion.com/video/', vi, params);
|
|
409
|
+
};
|
|
410
|
+
|
|
411
|
+
Dailymotion.prototype.createEmbedUrl = function (vi, params) {
|
|
412
|
+
return this.createUrl('https://www.dailymotion.com/embed/video/', vi, params);
|
|
413
|
+
};
|
|
414
|
+
|
|
415
|
+
Dailymotion.prototype.createImageUrl = function (vi, params) {
|
|
416
|
+
delete params.start;
|
|
417
|
+
return this.createUrl('https://www.dailymotion.com/thumbnail/video/', vi, params);
|
|
418
|
+
};
|
|
419
|
+
|
|
420
|
+
base.bind(new Dailymotion());
|
|
421
|
+
|
|
422
|
+
var combineParams$4 = util.combineParams;
|
|
423
|
+
|
|
424
|
+
function Loom() {
|
|
425
|
+
this.provider = 'loom';
|
|
426
|
+
this.defaultFormat = 'long';
|
|
427
|
+
this.formats = {
|
|
428
|
+
"long": this.createLongUrl,
|
|
429
|
+
embed: this.createEmbedUrl
|
|
430
|
+
};
|
|
431
|
+
this.mediaTypes = {
|
|
432
|
+
VIDEO: 'video'
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
Loom.prototype.parseUrl = function (url) {
|
|
437
|
+
var match = url.match(/(?:share|embed)\/([a-zA-Z\d]+)/i);
|
|
438
|
+
return match ? match[1] : undefined;
|
|
439
|
+
};
|
|
440
|
+
|
|
441
|
+
Loom.prototype.parse = function (url, params) {
|
|
442
|
+
var result = {
|
|
443
|
+
mediaType: this.mediaTypes.VIDEO,
|
|
444
|
+
params: params,
|
|
445
|
+
id: this.parseUrl(url)
|
|
446
|
+
};
|
|
447
|
+
return result.id ? result : undefined;
|
|
448
|
+
};
|
|
449
|
+
|
|
450
|
+
Loom.prototype.createUrl = function (baseUrl, vi, params) {
|
|
451
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
452
|
+
return undefined;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
var url = baseUrl + vi.id;
|
|
456
|
+
url += combineParams$4(params);
|
|
457
|
+
return url;
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
Loom.prototype.createLongUrl = function (vi, params) {
|
|
461
|
+
return this.createUrl('https://loom.com/share/', vi, params);
|
|
462
|
+
};
|
|
463
|
+
|
|
464
|
+
Loom.prototype.createEmbedUrl = function (vi, params) {
|
|
465
|
+
return this.createUrl('//loom.com/embed/', vi, params);
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
base.bind(new Loom());
|
|
469
|
+
|
|
470
|
+
var combineParams$5 = util.combineParams,
|
|
471
|
+
getTime$2 = util.getTime;
|
|
472
|
+
|
|
473
|
+
function Twitch() {
|
|
474
|
+
this.provider = 'twitch';
|
|
475
|
+
this.defaultFormat = 'long';
|
|
476
|
+
this.formats = {
|
|
477
|
+
"long": this.createLongUrl,
|
|
478
|
+
embed: this.createEmbedUrl
|
|
479
|
+
};
|
|
480
|
+
this.mediaTypes = {
|
|
481
|
+
VIDEO: 'video',
|
|
482
|
+
STREAM: 'stream',
|
|
483
|
+
CLIP: 'clip'
|
|
484
|
+
};
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
Twitch.prototype.seperateId = function (id) {
|
|
488
|
+
return {
|
|
489
|
+
pre: id[0],
|
|
490
|
+
id: id.substr(1)
|
|
491
|
+
};
|
|
492
|
+
};
|
|
493
|
+
|
|
494
|
+
Twitch.prototype.parseChannel = function (result, params) {
|
|
495
|
+
var channel = params.channel || params.utm_content || result.channel;
|
|
496
|
+
delete params.utm_content;
|
|
497
|
+
delete params.channel;
|
|
498
|
+
return channel;
|
|
499
|
+
};
|
|
500
|
+
|
|
501
|
+
Twitch.prototype.parseUrl = function (url, result, params) {
|
|
502
|
+
var match;
|
|
503
|
+
match = url.match(/(clips\.)?twitch\.tv\/(?:(?:videos\/(\d+))|(\w+(?:-[\w\d-]+)?)(?:\/clip\/(\w+))?)/i);
|
|
504
|
+
|
|
505
|
+
if (match && match[2]) {
|
|
506
|
+
//video
|
|
507
|
+
result.id = 'v' + match[2];
|
|
508
|
+
} else if (params.video) {
|
|
509
|
+
//video embed
|
|
510
|
+
result.id = params.video;
|
|
511
|
+
delete params.video;
|
|
512
|
+
} else if (params.clip) {
|
|
513
|
+
//clips embed
|
|
514
|
+
result.id = params.clip;
|
|
515
|
+
result.isClip = true;
|
|
516
|
+
delete params.clip;
|
|
517
|
+
} else if (match && match[1] && match[3]) {
|
|
518
|
+
//clips.twitch.tv/id
|
|
519
|
+
result.id = match[3];
|
|
520
|
+
result.isClip = true;
|
|
521
|
+
} else if (match && match[3] && match[4]) {
|
|
522
|
+
//twitch.tv/channel/clip/id
|
|
523
|
+
result.channel = match[3];
|
|
524
|
+
result.id = match[4];
|
|
525
|
+
result.isClip = true;
|
|
526
|
+
} else if (match && match[3]) {
|
|
527
|
+
result.channel = match[3];
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
return result;
|
|
531
|
+
};
|
|
532
|
+
|
|
533
|
+
Twitch.prototype.parseMediaType = function (result) {
|
|
534
|
+
var mediaType;
|
|
535
|
+
|
|
536
|
+
if (result.id) {
|
|
537
|
+
if (result.isClip) {
|
|
538
|
+
mediaType = this.mediaTypes.CLIP;
|
|
539
|
+
delete result.isClip;
|
|
540
|
+
} else {
|
|
541
|
+
mediaType = this.mediaTypes.VIDEO;
|
|
542
|
+
}
|
|
543
|
+
} else if (result.channel) {
|
|
544
|
+
mediaType = this.mediaTypes.STREAM;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return mediaType;
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
Twitch.prototype.parseParameters = function (params) {
|
|
551
|
+
if (params.t) {
|
|
552
|
+
params.start = getTime$2(params.t);
|
|
553
|
+
delete params.t;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
return params;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
Twitch.prototype.parse = function (url, params) {
|
|
560
|
+
var _this = this;
|
|
561
|
+
|
|
562
|
+
var result = {};
|
|
563
|
+
result = _this.parseUrl(url, result, params);
|
|
564
|
+
result.channel = _this.parseChannel(result, params);
|
|
565
|
+
result.mediaType = _this.parseMediaType(result);
|
|
566
|
+
result.params = _this.parseParameters(params);
|
|
567
|
+
return result.channel || result.id ? result : undefined;
|
|
568
|
+
};
|
|
569
|
+
|
|
570
|
+
Twitch.prototype.createLongUrl = function (vi, params) {
|
|
571
|
+
var url = '';
|
|
572
|
+
|
|
573
|
+
if (vi.mediaType === this.mediaTypes.STREAM && vi.channel) {
|
|
574
|
+
url = 'https://twitch.tv/' + vi.channel;
|
|
575
|
+
} else if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
|
|
576
|
+
var sep = this.seperateId(vi.id);
|
|
577
|
+
url = 'https://twitch.tv/videos/' + sep.id;
|
|
578
|
+
|
|
579
|
+
if (params.start) {
|
|
580
|
+
params.t = params.start + 's';
|
|
581
|
+
delete params.start;
|
|
582
|
+
}
|
|
583
|
+
} else if (vi.mediaType === this.mediaTypes.CLIP && vi.id) {
|
|
584
|
+
if (vi.channel) {
|
|
585
|
+
url = 'https://www.twitch.tv/' + vi.channel + '/clip/' + vi.id;
|
|
586
|
+
} else {
|
|
587
|
+
url = 'https://clips.twitch.tv/' + vi.id;
|
|
588
|
+
}
|
|
589
|
+
} else {
|
|
590
|
+
return undefined;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
url += combineParams$5(params);
|
|
594
|
+
return url;
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
Twitch.prototype.createEmbedUrl = function (vi, params) {
|
|
598
|
+
var url = 'https://player.twitch.tv/';
|
|
599
|
+
|
|
600
|
+
if (vi.mediaType === this.mediaTypes.STREAM && vi.channel) {
|
|
601
|
+
params.channel = vi.channel;
|
|
602
|
+
} else if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
|
|
603
|
+
params.video = vi.id;
|
|
604
|
+
|
|
605
|
+
if (params.start) {
|
|
606
|
+
params.t = params.start + 's';
|
|
607
|
+
delete params.start;
|
|
608
|
+
}
|
|
609
|
+
} else if (vi.mediaType === this.mediaTypes.CLIP && vi.id) {
|
|
610
|
+
url = 'https://clips.twitch.tv/embed';
|
|
611
|
+
params.clip = vi.id;
|
|
612
|
+
} else {
|
|
613
|
+
return undefined;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
url += combineParams$5(params);
|
|
617
|
+
return url;
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
base.bind(new Twitch());
|
|
621
|
+
|
|
622
|
+
var combineParams$6 = util.combineParams,
|
|
623
|
+
getTime$3 = util.getTime;
|
|
624
|
+
|
|
625
|
+
function Vimeo() {
|
|
626
|
+
this.provider = 'vimeo';
|
|
627
|
+
this.alternatives = ['vimeopro'];
|
|
628
|
+
this.defaultFormat = 'long';
|
|
629
|
+
this.formats = {
|
|
630
|
+
"long": this.createLongUrl,
|
|
631
|
+
embed: this.createEmbedUrl
|
|
632
|
+
};
|
|
633
|
+
this.mediaTypes = {
|
|
634
|
+
VIDEO: 'video'
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
Vimeo.prototype.parseUrl = function (url) {
|
|
639
|
+
var match = url.match(/(?:\/showcase\/\d+)?(?:\/(?:channels\/[\w]+|(?:(?:album\/\d+|groups\/[\w]+)\/)?videos?))?\/(\d+)/i);
|
|
640
|
+
return match ? match[1] : undefined;
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
Vimeo.prototype.parseHash = function (url) {
|
|
644
|
+
var match = url.match(/\/\d+\/(\w+)$/i);
|
|
645
|
+
return match ? match[1] : undefined;
|
|
646
|
+
};
|
|
647
|
+
|
|
648
|
+
Vimeo.prototype.parseParameters = function (params) {
|
|
649
|
+
if (params.t) {
|
|
650
|
+
params.start = getTime$3(params.t);
|
|
651
|
+
delete params.t;
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
if (params.h) {
|
|
655
|
+
params.hash = params.h;
|
|
656
|
+
delete params.h;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
return params;
|
|
660
|
+
};
|
|
661
|
+
|
|
662
|
+
Vimeo.prototype.parse = function (url, params) {
|
|
663
|
+
var result = {
|
|
664
|
+
mediaType: this.mediaTypes.VIDEO,
|
|
665
|
+
params: this.parseParameters(params),
|
|
666
|
+
id: this.parseUrl(url)
|
|
667
|
+
};
|
|
668
|
+
var hash = this.parseHash(url, params);
|
|
669
|
+
|
|
670
|
+
if (hash) {
|
|
671
|
+
result.params.hash = hash;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
return result.id ? result : undefined;
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
Vimeo.prototype.createUrl = function (baseUrl, vi, params, type) {
|
|
678
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
679
|
+
return undefined;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
var url = baseUrl + vi.id;
|
|
683
|
+
var startTime = params.start;
|
|
684
|
+
delete params.start;
|
|
685
|
+
|
|
686
|
+
if (params.hash) {
|
|
687
|
+
if (type === 'embed') {
|
|
688
|
+
params.h = params.hash;
|
|
689
|
+
} else if (type === 'long') {
|
|
690
|
+
url += '/' + params.hash;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
delete params.hash;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
url += combineParams$6(params);
|
|
697
|
+
|
|
698
|
+
if (startTime) {
|
|
699
|
+
url += '#t=' + startTime;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
return url;
|
|
703
|
+
};
|
|
704
|
+
|
|
705
|
+
Vimeo.prototype.createLongUrl = function (vi, params) {
|
|
706
|
+
return this.createUrl('https://vimeo.com/', vi, params, 'long');
|
|
707
|
+
};
|
|
708
|
+
|
|
709
|
+
Vimeo.prototype.createEmbedUrl = function (vi, params) {
|
|
710
|
+
return this.createUrl('//player.vimeo.com/video/', vi, params, 'embed');
|
|
711
|
+
};
|
|
712
|
+
|
|
713
|
+
base.bind(new Vimeo());
|
|
714
|
+
|
|
715
|
+
var combineParams$7 = util.combineParams,
|
|
716
|
+
getTime$4 = util.getTime;
|
|
717
|
+
|
|
718
|
+
function Wistia() {
|
|
719
|
+
this.provider = 'wistia';
|
|
720
|
+
this.alternatives = [];
|
|
721
|
+
this.defaultFormat = 'long';
|
|
722
|
+
this.formats = {
|
|
723
|
+
"long": this.createLongUrl,
|
|
724
|
+
embed: this.createEmbedUrl,
|
|
725
|
+
embedjsonp: this.createEmbedJsonpUrl
|
|
726
|
+
};
|
|
727
|
+
this.mediaTypes = {
|
|
728
|
+
VIDEO: 'video',
|
|
729
|
+
EMBEDVIDEO: 'embedvideo'
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
Wistia.prototype.parseUrl = function (url) {
|
|
734
|
+
var match = url.match(/(?:(?:medias|iframe)\/|wvideo=)([\w-]+)/);
|
|
735
|
+
return match ? match[1] : undefined;
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
Wistia.prototype.parseChannel = function (url) {
|
|
739
|
+
var match = url.match(/(?:(?:https?:)?\/\/)?([^.]*)\.wistia\./);
|
|
740
|
+
var channel = match ? match[1] : undefined;
|
|
741
|
+
|
|
742
|
+
if (channel === 'fast' || channel === 'content') {
|
|
743
|
+
return undefined;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
return channel;
|
|
747
|
+
};
|
|
748
|
+
|
|
749
|
+
Wistia.prototype.parseParameters = function (params, result) {
|
|
750
|
+
if (params.wtime) {
|
|
751
|
+
params.start = getTime$4(params.wtime);
|
|
752
|
+
delete params.wtime;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
if (params.wvideo === result.id) {
|
|
756
|
+
delete params.wvideo;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
return params;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
Wistia.prototype.parseMediaType = function (result) {
|
|
763
|
+
if (result.id && result.channel) {
|
|
764
|
+
return this.mediaTypes.VIDEO;
|
|
765
|
+
} else if (result.id) {
|
|
766
|
+
delete result.channel;
|
|
767
|
+
return this.mediaTypes.EMBEDVIDEO;
|
|
768
|
+
} else {
|
|
769
|
+
return undefined;
|
|
770
|
+
}
|
|
771
|
+
};
|
|
772
|
+
|
|
773
|
+
Wistia.prototype.parse = function (url, params) {
|
|
774
|
+
var result = {
|
|
775
|
+
id: this.parseUrl(url),
|
|
776
|
+
channel: this.parseChannel(url)
|
|
777
|
+
};
|
|
778
|
+
result.params = this.parseParameters(params, result);
|
|
779
|
+
result.mediaType = this.parseMediaType(result);
|
|
780
|
+
|
|
781
|
+
if (!result.id) {
|
|
782
|
+
return undefined;
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
return result;
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
Wistia.prototype.createUrl = function (vi, params, url) {
|
|
789
|
+
if (params.start) {
|
|
790
|
+
params.wtime = params.start;
|
|
791
|
+
delete params.start;
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
url += combineParams$7(params);
|
|
795
|
+
return url;
|
|
796
|
+
};
|
|
797
|
+
|
|
798
|
+
Wistia.prototype.createLongUrl = function (vi, params) {
|
|
799
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
800
|
+
return undefined;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
var url = 'https://' + vi.channel + '.wistia.com/medias/' + vi.id;
|
|
804
|
+
return this.createUrl(vi, params, url);
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
Wistia.prototype.createEmbedUrl = function (vi, params) {
|
|
808
|
+
if (!vi.id || !(vi.mediaType === this.mediaTypes.VIDEO || vi.mediaType === this.mediaTypes.EMBEDVIDEO)) {
|
|
809
|
+
return undefined;
|
|
810
|
+
}
|
|
811
|
+
|
|
812
|
+
var url = 'https://fast.wistia.com/embed/iframe/' + vi.id;
|
|
813
|
+
return this.createUrl(vi, params, url);
|
|
814
|
+
};
|
|
815
|
+
|
|
816
|
+
Wistia.prototype.createEmbedJsonpUrl = function (vi) {
|
|
817
|
+
if (!vi.id || !(vi.mediaType === this.mediaTypes.VIDEO || vi.mediaType === this.mediaTypes.EMBEDVIDEO)) {
|
|
818
|
+
return undefined;
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
return 'https://fast.wistia.com/embed/medias/' + vi.id + '.jsonp';
|
|
822
|
+
};
|
|
823
|
+
|
|
824
|
+
base.bind(new Wistia());
|
|
825
|
+
|
|
826
|
+
var combineParams$8 = util.combineParams;
|
|
827
|
+
|
|
828
|
+
function Youku() {
|
|
829
|
+
this.provider = 'youku';
|
|
830
|
+
this.defaultFormat = 'long';
|
|
831
|
+
this.formats = {
|
|
832
|
+
embed: this.createEmbedUrl,
|
|
833
|
+
"long": this.createLongUrl,
|
|
834
|
+
flash: this.createFlashUrl,
|
|
835
|
+
"static": this.createStaticUrl
|
|
836
|
+
};
|
|
837
|
+
this.mediaTypes = {
|
|
838
|
+
VIDEO: 'video'
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
Youku.prototype.parseUrl = function (url) {
|
|
843
|
+
var match = url.match(/(?:(?:embed|sid)\/|v_show\/id_|VideoIDS=)([a-zA-Z0-9]+)/);
|
|
844
|
+
return match ? match[1] : undefined;
|
|
845
|
+
};
|
|
846
|
+
|
|
847
|
+
Youku.prototype.parseParameters = function (params) {
|
|
848
|
+
if (params.VideoIDS) {
|
|
849
|
+
delete params.VideoIDS;
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
return params;
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
Youku.prototype.parse = function (url, params) {
|
|
856
|
+
var _this = this;
|
|
857
|
+
|
|
858
|
+
var result = {
|
|
859
|
+
mediaType: this.mediaTypes.VIDEO,
|
|
860
|
+
id: _this.parseUrl(url),
|
|
861
|
+
params: _this.parseParameters(params)
|
|
862
|
+
};
|
|
863
|
+
|
|
864
|
+
if (!result.id) {
|
|
865
|
+
return undefined;
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
return result;
|
|
869
|
+
};
|
|
870
|
+
|
|
871
|
+
Youku.prototype.createUrl = function (baseUrl, vi, params) {
|
|
872
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
873
|
+
return undefined;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
var url = baseUrl + vi.id;
|
|
877
|
+
url += combineParams$8(params);
|
|
878
|
+
return url;
|
|
879
|
+
};
|
|
880
|
+
|
|
881
|
+
Youku.prototype.createEmbedUrl = function (vi, params) {
|
|
882
|
+
return this.createUrl('http://player.youku.com/embed/', vi, params);
|
|
883
|
+
};
|
|
884
|
+
|
|
885
|
+
Youku.prototype.createLongUrl = function (vi, params) {
|
|
886
|
+
return this.createUrl('http://v.youku.com/v_show/id_', vi, params);
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
Youku.prototype.createStaticUrl = function (vi, params) {
|
|
890
|
+
return this.createUrl('http://static.youku.com/v1.0.0638/v/swf/loader.swf?VideoIDS=', vi, params);
|
|
891
|
+
};
|
|
892
|
+
|
|
893
|
+
Youku.prototype.createFlashUrl = function (vi, params) {
|
|
894
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
895
|
+
return undefined;
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
var url = 'http://player.youku.com/player.php/sid/' + vi.id + '/v.swf';
|
|
899
|
+
url += combineParams$8(params);
|
|
900
|
+
return url;
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
base.bind(new Youku());
|
|
904
|
+
|
|
905
|
+
var combineParams$9 = util.combineParams,
|
|
906
|
+
getTime$5 = util.getTime;
|
|
907
|
+
|
|
908
|
+
function YouTube() {
|
|
909
|
+
this.provider = 'youtube';
|
|
910
|
+
this.alternatives = ['youtu', 'ytimg'];
|
|
911
|
+
this.defaultFormat = 'long';
|
|
912
|
+
this.formats = {
|
|
913
|
+
"short": this.createShortUrl,
|
|
914
|
+
"long": this.createLongUrl,
|
|
915
|
+
embed: this.createEmbedUrl,
|
|
916
|
+
shortImage: this.createShortImageUrl,
|
|
917
|
+
longImage: this.createLongImageUrl
|
|
918
|
+
};
|
|
919
|
+
this.imageQualities = {
|
|
920
|
+
'0': '0',
|
|
921
|
+
'1': '1',
|
|
922
|
+
'2': '2',
|
|
923
|
+
'3': '3',
|
|
924
|
+
DEFAULT: 'default',
|
|
925
|
+
HQDEFAULT: 'hqdefault',
|
|
926
|
+
SDDEFAULT: 'sddefault',
|
|
927
|
+
MQDEFAULT: 'mqdefault',
|
|
928
|
+
MAXRESDEFAULT: 'maxresdefault'
|
|
929
|
+
};
|
|
930
|
+
this.defaultImageQuality = this.imageQualities.HQDEFAULT;
|
|
931
|
+
this.mediaTypes = {
|
|
932
|
+
VIDEO: 'video',
|
|
933
|
+
PLAYLIST: 'playlist',
|
|
934
|
+
SHARE: 'share',
|
|
935
|
+
CHANNEL: 'channel'
|
|
936
|
+
};
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
YouTube.prototype.parseVideoUrl = function (url) {
|
|
940
|
+
var match = url.match(/(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w-]{11})/i);
|
|
941
|
+
return match ? match[1] : undefined;
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
YouTube.prototype.parseChannelUrl = function (url) {
|
|
945
|
+
// Match an opaque channel ID
|
|
946
|
+
var match = url.match(/\/channel\/([\w-]+)/);
|
|
947
|
+
|
|
948
|
+
if (match) {
|
|
949
|
+
return {
|
|
950
|
+
id: match[1],
|
|
951
|
+
mediaType: this.mediaTypes.CHANNEL
|
|
952
|
+
};
|
|
953
|
+
} // Match a vanity channel name or a user name. User urls are deprecated and
|
|
954
|
+
// currently redirect to the channel of that same name.
|
|
955
|
+
|
|
956
|
+
|
|
957
|
+
match = url.match(/\/(?:c|user)\/([\w-]+)/);
|
|
958
|
+
|
|
959
|
+
if (match) {
|
|
960
|
+
return {
|
|
961
|
+
name: match[1],
|
|
962
|
+
mediaType: this.mediaTypes.CHANNEL
|
|
963
|
+
};
|
|
964
|
+
}
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
YouTube.prototype.parseParameters = function (params, result) {
|
|
968
|
+
if (params.start || params.t) {
|
|
969
|
+
params.start = getTime$5(params.start || params.t);
|
|
970
|
+
delete params.t;
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
if (params.v === result.id) {
|
|
974
|
+
delete params.v;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
if (params.list === result.id) {
|
|
978
|
+
delete params.list;
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
return params;
|
|
982
|
+
};
|
|
983
|
+
|
|
984
|
+
YouTube.prototype.parseMediaType = function (result) {
|
|
985
|
+
if (result.params.list) {
|
|
986
|
+
result.list = result.params.list;
|
|
987
|
+
delete result.params.list;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
if (result.id && !result.params.ci) {
|
|
991
|
+
result.mediaType = this.mediaTypes.VIDEO;
|
|
992
|
+
} else if (result.list) {
|
|
993
|
+
delete result.id;
|
|
994
|
+
result.mediaType = this.mediaTypes.PLAYLIST;
|
|
995
|
+
} else if (result.params.ci) {
|
|
996
|
+
delete result.params.ci;
|
|
997
|
+
result.mediaType = this.mediaTypes.SHARE;
|
|
998
|
+
} else {
|
|
999
|
+
return undefined;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
return result;
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
YouTube.prototype.parse = function (url, params) {
|
|
1006
|
+
var channelResult = this.parseChannelUrl(url);
|
|
1007
|
+
|
|
1008
|
+
if (channelResult) {
|
|
1009
|
+
return channelResult;
|
|
1010
|
+
} else {
|
|
1011
|
+
var result = {
|
|
1012
|
+
params: params,
|
|
1013
|
+
id: this.parseVideoUrl(url)
|
|
1014
|
+
};
|
|
1015
|
+
result.params = this.parseParameters(params, result);
|
|
1016
|
+
result = this.parseMediaType(result);
|
|
1017
|
+
return result;
|
|
1018
|
+
}
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
YouTube.prototype.createShortUrl = function (vi, params) {
|
|
1022
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
1023
|
+
return undefined;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
var url = 'https://youtu.be/' + vi.id;
|
|
1027
|
+
|
|
1028
|
+
if (params.start) {
|
|
1029
|
+
url += '#t=' + params.start;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
return url;
|
|
1033
|
+
};
|
|
1034
|
+
|
|
1035
|
+
YouTube.prototype.createLongUrl = function (vi, params) {
|
|
1036
|
+
var url = '';
|
|
1037
|
+
var startTime = params.start;
|
|
1038
|
+
delete params.start;
|
|
1039
|
+
|
|
1040
|
+
if (vi.mediaType === this.mediaTypes.CHANNEL) {
|
|
1041
|
+
if (vi.id) {
|
|
1042
|
+
url += 'https://www.youtube.com/channel/' + vi.id;
|
|
1043
|
+
} else if (vi.name) {
|
|
1044
|
+
url += 'https://www.youtube.com/c/' + vi.name;
|
|
1045
|
+
} else {
|
|
1046
|
+
return undefined;
|
|
1047
|
+
}
|
|
1048
|
+
} else if (vi.mediaType === this.mediaTypes.PLAYLIST && vi.list) {
|
|
1049
|
+
params.feature = 'share';
|
|
1050
|
+
url += 'https://www.youtube.com/playlist';
|
|
1051
|
+
} else if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
|
|
1052
|
+
params.v = vi.id;
|
|
1053
|
+
url += 'https://www.youtube.com/watch';
|
|
1054
|
+
} else if (vi.mediaType === this.mediaTypes.SHARE && vi.id) {
|
|
1055
|
+
params.ci = vi.id;
|
|
1056
|
+
url += 'https://www.youtube.com/shared';
|
|
1057
|
+
} else {
|
|
1058
|
+
return undefined;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
if (vi.list) {
|
|
1062
|
+
params.list = vi.list;
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
url += combineParams$9(params);
|
|
1066
|
+
|
|
1067
|
+
if (vi.mediaType !== this.mediaTypes.PLAYLIST && startTime) {
|
|
1068
|
+
url += '#t=' + startTime;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
return url;
|
|
1072
|
+
};
|
|
1073
|
+
|
|
1074
|
+
YouTube.prototype.createEmbedUrl = function (vi, params) {
|
|
1075
|
+
var url = 'https://www.youtube.com/embed';
|
|
1076
|
+
|
|
1077
|
+
if (vi.mediaType === this.mediaTypes.PLAYLIST && vi.list) {
|
|
1078
|
+
params.listType = 'playlist';
|
|
1079
|
+
} else if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
|
|
1080
|
+
url += '/' + vi.id; //loop hack
|
|
1081
|
+
|
|
1082
|
+
if (params.loop === '1') {
|
|
1083
|
+
params.playlist = vi.id;
|
|
1084
|
+
}
|
|
1085
|
+
} else {
|
|
1086
|
+
return undefined;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
if (vi.list) {
|
|
1090
|
+
params.list = vi.list;
|
|
1091
|
+
}
|
|
1092
|
+
|
|
1093
|
+
url += combineParams$9(params);
|
|
1094
|
+
return url;
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
YouTube.prototype.createImageUrl = function (baseUrl, vi, params) {
|
|
1098
|
+
if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
|
|
1099
|
+
return undefined;
|
|
1100
|
+
}
|
|
1101
|
+
|
|
1102
|
+
var url = baseUrl + vi.id + '/';
|
|
1103
|
+
var quality = params.imageQuality || this.defaultImageQuality;
|
|
1104
|
+
return url + quality + '.jpg';
|
|
1105
|
+
};
|
|
1106
|
+
|
|
1107
|
+
YouTube.prototype.createShortImageUrl = function (vi, params) {
|
|
1108
|
+
return this.createImageUrl('https://i.ytimg.com/vi/', vi, params);
|
|
1109
|
+
};
|
|
1110
|
+
|
|
1111
|
+
YouTube.prototype.createLongImageUrl = function (vi, params) {
|
|
1112
|
+
return this.createImageUrl('https://img.youtube.com/vi/', vi, params);
|
|
1113
|
+
};
|
|
1114
|
+
|
|
1115
|
+
base.bind(new YouTube());
|
|
1116
|
+
|
|
1117
|
+
var combineParams$a = util.combineParams,
|
|
1118
|
+
getTime$6 = util.getTime;
|
|
1119
|
+
|
|
1120
|
+
function SoundCloud() {
|
|
1121
|
+
this.provider = 'soundcloud';
|
|
1122
|
+
this.defaultFormat = 'long';
|
|
1123
|
+
this.formats = {
|
|
1124
|
+
"long": this.createLongUrl,
|
|
1125
|
+
embed: this.createEmbedUrl
|
|
1126
|
+
};
|
|
1127
|
+
this.mediaTypes = {
|
|
1128
|
+
TRACK: 'track',
|
|
1129
|
+
PLAYLIST: 'playlist',
|
|
1130
|
+
APITRACK: 'apitrack',
|
|
1131
|
+
APIPLAYLIST: 'apiplaylist'
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
SoundCloud.prototype.parseUrl = function (url, result) {
|
|
1136
|
+
var match = url.match(/(?:m\.)?soundcloud\.com\/(?:([\w-]+)\/(sets\/)?)([\w-]+)/i);
|
|
1137
|
+
|
|
1138
|
+
if (!match) {
|
|
1139
|
+
return result;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
result.channel = match[1];
|
|
1143
|
+
|
|
1144
|
+
if (match[1] === 'playlists' || match[2]) {
|
|
1145
|
+
//playlist
|
|
1146
|
+
result.list = match[3];
|
|
1147
|
+
} else {
|
|
1148
|
+
//track
|
|
1149
|
+
result.id = match[3];
|
|
1150
|
+
}
|
|
1151
|
+
|
|
1152
|
+
return result;
|
|
1153
|
+
};
|
|
1154
|
+
|
|
1155
|
+
SoundCloud.prototype.parseParameters = function (params) {
|
|
1156
|
+
if (params.t) {
|
|
1157
|
+
params.start = getTime$6(params.t);
|
|
1158
|
+
delete params.t;
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
return params;
|
|
1162
|
+
};
|
|
1163
|
+
|
|
1164
|
+
SoundCloud.prototype.parseMediaType = function (result) {
|
|
1165
|
+
if (result.id) {
|
|
1166
|
+
if (result.channel === 'tracks') {
|
|
1167
|
+
delete result.channel;
|
|
1168
|
+
delete result.params.url;
|
|
1169
|
+
result.mediaType = this.mediaTypes.APITRACK;
|
|
1170
|
+
} else {
|
|
1171
|
+
result.mediaType = this.mediaTypes.TRACK;
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if (result.list) {
|
|
1176
|
+
if (result.channel === 'playlists') {
|
|
1177
|
+
delete result.channel;
|
|
1178
|
+
delete result.params.url;
|
|
1179
|
+
result.mediaType = this.mediaTypes.APIPLAYLIST;
|
|
1180
|
+
} else {
|
|
1181
|
+
result.mediaType = this.mediaTypes.PLAYLIST;
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1185
|
+
return result;
|
|
1186
|
+
};
|
|
1187
|
+
|
|
1188
|
+
SoundCloud.prototype.parse = function (url, params) {
|
|
1189
|
+
var result = {};
|
|
1190
|
+
result = this.parseUrl(url, result);
|
|
1191
|
+
result.params = this.parseParameters(params);
|
|
1192
|
+
result = this.parseMediaType(result);
|
|
1193
|
+
|
|
1194
|
+
if (!result.id && !result.list) {
|
|
1195
|
+
return undefined;
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
return result;
|
|
1199
|
+
};
|
|
1200
|
+
|
|
1201
|
+
SoundCloud.prototype.createLongUrl = function (vi, params) {
|
|
1202
|
+
var url = '';
|
|
1203
|
+
var startTime = params.start;
|
|
1204
|
+
delete params.start;
|
|
1205
|
+
|
|
1206
|
+
if (vi.mediaType === this.mediaTypes.TRACK && vi.id && vi.channel) {
|
|
1207
|
+
url = 'https://soundcloud.com/' + vi.channel + '/' + vi.id;
|
|
1208
|
+
} else if (vi.mediaType === this.mediaTypes.PLAYLIST && vi.list && vi.channel) {
|
|
1209
|
+
url = 'https://soundcloud.com/' + vi.channel + '/sets/' + vi.list;
|
|
1210
|
+
} else if (vi.mediaType === this.mediaTypes.APITRACK && vi.id) {
|
|
1211
|
+
url = 'https://api.soundcloud.com/tracks/' + vi.id;
|
|
1212
|
+
} else if (vi.mediaType === this.mediaTypes.APIPLAYLIST && vi.list) {
|
|
1213
|
+
url = 'https://api.soundcloud.com/playlists/' + vi.list;
|
|
1214
|
+
} else {
|
|
1215
|
+
return undefined;
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
url += combineParams$a(params);
|
|
1219
|
+
|
|
1220
|
+
if (startTime) {
|
|
1221
|
+
url += '#t=' + startTime;
|
|
1222
|
+
}
|
|
1223
|
+
|
|
1224
|
+
return url;
|
|
1225
|
+
};
|
|
1226
|
+
|
|
1227
|
+
SoundCloud.prototype.createEmbedUrl = function (vi, params) {
|
|
1228
|
+
var url = 'https://w.soundcloud.com/player/';
|
|
1229
|
+
delete params.start;
|
|
1230
|
+
|
|
1231
|
+
if (vi.mediaType === this.mediaTypes.APITRACK && vi.id) {
|
|
1232
|
+
params.url = 'https%3A//api.soundcloud.com/tracks/' + vi.id;
|
|
1233
|
+
} else if (vi.mediaType === this.mediaTypes.APIPLAYLIST && vi.list) {
|
|
1234
|
+
params.url = 'https%3A//api.soundcloud.com/playlists/' + vi.list;
|
|
1235
|
+
} else {
|
|
1236
|
+
return undefined;
|
|
1237
|
+
}
|
|
1238
|
+
|
|
1239
|
+
url += combineParams$a(params);
|
|
1240
|
+
return url;
|
|
1241
|
+
};
|
|
1242
|
+
|
|
1243
|
+
base.bind(new SoundCloud());
|
|
1244
|
+
|
|
1245
|
+
var combineParams$b = util.combineParams;
|
|
1246
|
+
|
|
1247
|
+
function TeacherTube() {
|
|
1248
|
+
this.provider = 'teachertube';
|
|
1249
|
+
this.alternatives = [];
|
|
1250
|
+
this.defaultFormat = 'long';
|
|
1251
|
+
this.formats = {
|
|
1252
|
+
"long": this.createLongUrl,
|
|
1253
|
+
embed: this.createEmbedUrl
|
|
1254
|
+
};
|
|
1255
|
+
this.mediaTypes = {
|
|
1256
|
+
VIDEO: 'video',
|
|
1257
|
+
AUDIO: 'audio',
|
|
1258
|
+
DOCUMENT: 'document',
|
|
1259
|
+
CHANNEL: 'channel',
|
|
1260
|
+
COLLECTION: 'collection',
|
|
1261
|
+
GROUP: 'group'
|
|
1262
|
+
};
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
TeacherTube.prototype.parse = function (url, params) {
|
|
1266
|
+
var result = {};
|
|
1267
|
+
result.list = this.parsePlaylist(params);
|
|
1268
|
+
result.params = params;
|
|
1269
|
+
var match = url.match(/\/(audio|video|document|user\/channel|collection|group)\/(?:[\w-]+-)?(\w+)/);
|
|
1270
|
+
|
|
1271
|
+
if (!match) {
|
|
1272
|
+
return undefined;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1275
|
+
result.mediaType = this.parseMediaType(match[1]);
|
|
1276
|
+
result.id = match[2];
|
|
1277
|
+
return result;
|
|
1278
|
+
};
|
|
1279
|
+
|
|
1280
|
+
TeacherTube.prototype.parsePlaylist = function (params) {
|
|
1281
|
+
if (params['playlist-id']) {
|
|
1282
|
+
var list = params['playlist-id'];
|
|
1283
|
+
delete params['playlist-id'];
|
|
1284
|
+
return list;
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
return undefined;
|
|
1288
|
+
};
|
|
1289
|
+
|
|
1290
|
+
TeacherTube.prototype.parseMediaType = function (mediaTypeMatch) {
|
|
1291
|
+
switch (mediaTypeMatch) {
|
|
1292
|
+
case 'audio':
|
|
1293
|
+
return this.mediaTypes.AUDIO;
|
|
1294
|
+
|
|
1295
|
+
case 'video':
|
|
1296
|
+
return this.mediaTypes.VIDEO;
|
|
1297
|
+
|
|
1298
|
+
case 'document':
|
|
1299
|
+
return this.mediaTypes.DOCUMENT;
|
|
1300
|
+
|
|
1301
|
+
case 'user/channel':
|
|
1302
|
+
return this.mediaTypes.CHANNEL;
|
|
1303
|
+
|
|
1304
|
+
case 'collection':
|
|
1305
|
+
return this.mediaTypes.COLLECTION;
|
|
1306
|
+
|
|
1307
|
+
case 'group':
|
|
1308
|
+
return this.mediaTypes.GROUP;
|
|
1309
|
+
}
|
|
1310
|
+
};
|
|
1311
|
+
|
|
1312
|
+
TeacherTube.prototype.createLongUrl = function (vi, params) {
|
|
1313
|
+
if (!vi.id) {
|
|
1314
|
+
return undefined;
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
var url = 'https://www.teachertube.com/';
|
|
1318
|
+
|
|
1319
|
+
if (vi.list) {
|
|
1320
|
+
params['playlist-id'] = vi.list;
|
|
1321
|
+
}
|
|
1322
|
+
|
|
1323
|
+
if (vi.mediaType === this.mediaTypes.CHANNEL) {
|
|
1324
|
+
url += 'user/channel/';
|
|
1325
|
+
} else {
|
|
1326
|
+
url += vi.mediaType + '/';
|
|
1327
|
+
}
|
|
1328
|
+
|
|
1329
|
+
url += vi.id;
|
|
1330
|
+
url += combineParams$b(params);
|
|
1331
|
+
return url;
|
|
1332
|
+
};
|
|
1333
|
+
|
|
1334
|
+
TeacherTube.prototype.createEmbedUrl = function (vi, params) {
|
|
1335
|
+
if (!vi.id) {
|
|
1336
|
+
return undefined;
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
var url = 'https://www.teachertube.com/embed/';
|
|
1340
|
+
|
|
1341
|
+
if (vi.mediaType === this.mediaTypes.VIDEO || vi.mediaType === this.mediaTypes.AUDIO) {
|
|
1342
|
+
url += vi.mediaType + '/' + vi.id;
|
|
1343
|
+
} else {
|
|
1344
|
+
return undefined;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
url += combineParams$b(params);
|
|
1348
|
+
return url;
|
|
1349
|
+
};
|
|
1350
|
+
|
|
1351
|
+
base.bind(new TeacherTube());
|
|
1352
|
+
|
|
1353
|
+
var combineParams$c = util.combineParams;
|
|
1354
|
+
|
|
1355
|
+
function TikTok() {
|
|
1356
|
+
this.provider = 'tiktok';
|
|
1357
|
+
this.defaultFormat = 'long';
|
|
1358
|
+
this.formats = {
|
|
1359
|
+
"long": this.createLongUrl
|
|
1360
|
+
};
|
|
1361
|
+
this.mediaTypes = {
|
|
1362
|
+
VIDEO: 'video'
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
TikTok.prototype.parse = function (url, params) {
|
|
1367
|
+
var result = {
|
|
1368
|
+
params: params,
|
|
1369
|
+
mediaType: this.mediaTypes.VIDEO
|
|
1370
|
+
};
|
|
1371
|
+
var match = url.match(/@([^/]+)\/video\/(\d{19})/);
|
|
1372
|
+
|
|
1373
|
+
if (!match) {
|
|
1374
|
+
return;
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
result.channel = match[1];
|
|
1378
|
+
result.id = match[2];
|
|
1379
|
+
return result;
|
|
1380
|
+
};
|
|
1381
|
+
|
|
1382
|
+
TikTok.prototype.createLongUrl = function (vi, params) {
|
|
1383
|
+
var url = '';
|
|
1384
|
+
|
|
1385
|
+
if (vi.mediaType === this.mediaTypes.VIDEO && vi.id && vi.channel) {
|
|
1386
|
+
url += "https://www.tiktok.com/@".concat(vi.channel, "/video/").concat(vi.id);
|
|
1387
|
+
} else {
|
|
1388
|
+
return undefined;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
url += combineParams$c(params);
|
|
1392
|
+
return url;
|
|
1393
|
+
};
|
|
1394
|
+
|
|
1395
|
+
base.bind(new TikTok());
|
|
1396
|
+
|
|
1397
|
+
var combineParams$d = util.combineParams;
|
|
1398
|
+
|
|
1399
|
+
function Ted() {
|
|
1400
|
+
this.provider = 'ted';
|
|
1401
|
+
this.formats = {
|
|
1402
|
+
"long": this.createLongUrl,
|
|
1403
|
+
embed: this.createEmbedUrl
|
|
1404
|
+
};
|
|
1405
|
+
this.mediaTypes = {
|
|
1406
|
+
VIDEO: 'video',
|
|
1407
|
+
PLAYLIST: 'playlist'
|
|
1408
|
+
};
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
Ted.prototype.parseUrl = function (url, result) {
|
|
1412
|
+
var match = url.match(/\/(talks|playlists\/(\d+))\/([\w-]+)/i);
|
|
1413
|
+
var channel = match ? match[1] : undefined;
|
|
1414
|
+
|
|
1415
|
+
if (!channel) {
|
|
1416
|
+
return result;
|
|
1417
|
+
}
|
|
1418
|
+
|
|
1419
|
+
result.channel = channel.split('/')[0];
|
|
1420
|
+
result.id = match[3];
|
|
1421
|
+
|
|
1422
|
+
if (result.channel === 'playlists') {
|
|
1423
|
+
result.list = match[2];
|
|
1424
|
+
}
|
|
1425
|
+
|
|
1426
|
+
return result;
|
|
1427
|
+
};
|
|
1428
|
+
|
|
1429
|
+
Ted.prototype.parseMediaType = function (result) {
|
|
1430
|
+
if (result.id && result.channel === 'playlists') {
|
|
1431
|
+
delete result.channel;
|
|
1432
|
+
result.mediaType = this.mediaTypes.PLAYLIST;
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
if (result.id && result.channel === 'talks') {
|
|
1436
|
+
delete result.channel;
|
|
1437
|
+
result.mediaType = this.mediaTypes.VIDEO;
|
|
1438
|
+
}
|
|
1439
|
+
|
|
1440
|
+
return result;
|
|
1441
|
+
};
|
|
1442
|
+
|
|
1443
|
+
Ted.prototype.parse = function (url, params) {
|
|
1444
|
+
var result = {
|
|
1445
|
+
params: params
|
|
1446
|
+
};
|
|
1447
|
+
result = this.parseUrl(url, result);
|
|
1448
|
+
result = this.parseMediaType(result);
|
|
1449
|
+
|
|
1450
|
+
if (!result.id) {
|
|
1451
|
+
return undefined;
|
|
1452
|
+
}
|
|
1453
|
+
|
|
1454
|
+
return result;
|
|
1455
|
+
};
|
|
1456
|
+
|
|
1457
|
+
Ted.prototype.createLongUrl = function (vi, params) {
|
|
1458
|
+
var url = '';
|
|
1459
|
+
|
|
1460
|
+
if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
|
|
1461
|
+
url += 'https://ted.com/talks/' + vi.id;
|
|
1462
|
+
} else if (vi.mediaType === this.mediaTypes.PLAYLIST && vi.id) {
|
|
1463
|
+
url += 'https://ted.com/playlists/' + vi.list + '/' + vi.id;
|
|
1464
|
+
} else {
|
|
1465
|
+
return undefined;
|
|
1466
|
+
}
|
|
1467
|
+
|
|
1468
|
+
url += combineParams$d(params);
|
|
1469
|
+
return url;
|
|
1470
|
+
};
|
|
1471
|
+
|
|
1472
|
+
Ted.prototype.createEmbedUrl = function (vi, params) {
|
|
1473
|
+
var url = 'https://embed.ted.com/';
|
|
1474
|
+
|
|
1475
|
+
if (vi.mediaType === this.mediaTypes.PLAYLIST && vi.id) {
|
|
1476
|
+
url += 'playlists/' + vi.list + '/' + vi.id;
|
|
1477
|
+
} else if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
|
|
1478
|
+
url += 'talks/' + vi.id;
|
|
1479
|
+
} else {
|
|
1480
|
+
return undefined;
|
|
1481
|
+
}
|
|
1482
|
+
|
|
1483
|
+
url += combineParams$d(params);
|
|
1484
|
+
return url;
|
|
1485
|
+
};
|
|
1486
|
+
|
|
1487
|
+
base.bind(new Ted());
|
|
1488
|
+
|
|
1489
|
+
var combineParams$e = util.combineParams;
|
|
1490
|
+
|
|
1491
|
+
function Facebook() {
|
|
1492
|
+
this.provider = 'facebook';
|
|
1493
|
+
this.alternatives = [];
|
|
1494
|
+
this.defaultFormat = 'long';
|
|
1495
|
+
this.formats = {
|
|
1496
|
+
"long": this.createLongUrl,
|
|
1497
|
+
watch: this.createWatchUrl
|
|
1498
|
+
};
|
|
1499
|
+
this.mediaTypes = {
|
|
1500
|
+
VIDEO: 'video'
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
Facebook.prototype.parse = function (url, params) {
|
|
1505
|
+
var result = {
|
|
1506
|
+
params: params,
|
|
1507
|
+
mediaType: this.mediaTypes.VIDEO
|
|
1508
|
+
};
|
|
1509
|
+
var match = url.match(/(?:\/(\d+))?\/videos(?:\/.*?)?\/(\d+)/i);
|
|
1510
|
+
|
|
1511
|
+
if (match) {
|
|
1512
|
+
if (match[1]) {
|
|
1513
|
+
result.pageId = match[1];
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
result.id = match[2];
|
|
1517
|
+
}
|
|
1518
|
+
|
|
1519
|
+
if (params.v && !result.id) {
|
|
1520
|
+
result.id = params.v;
|
|
1521
|
+
delete params.v;
|
|
1522
|
+
result.params = params;
|
|
1523
|
+
}
|
|
1524
|
+
|
|
1525
|
+
if (!result.id) {
|
|
1526
|
+
return undefined;
|
|
1527
|
+
}
|
|
1528
|
+
|
|
1529
|
+
return result;
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
Facebook.prototype.createWatchUrl = function (vi, params) {
|
|
1533
|
+
var url = 'https://facebook.com/watch/';
|
|
1534
|
+
|
|
1535
|
+
if (vi.mediaType !== this.mediaTypes.VIDEO || !vi.id) {
|
|
1536
|
+
return undefined;
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
params = {
|
|
1540
|
+
v: vi.id
|
|
1541
|
+
};
|
|
1542
|
+
url += combineParams$e(params);
|
|
1543
|
+
return url;
|
|
1544
|
+
};
|
|
1545
|
+
|
|
1546
|
+
Facebook.prototype.createLongUrl = function (vi, params) {
|
|
1547
|
+
var url = 'https://facebook.com/';
|
|
1548
|
+
|
|
1549
|
+
if (vi.pageId) {
|
|
1550
|
+
url += vi.pageId;
|
|
1551
|
+
} else {
|
|
1552
|
+
return undefined;
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
|
|
1556
|
+
url += '/videos/' + vi.id;
|
|
1557
|
+
} else {
|
|
1558
|
+
return undefined;
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
url += combineParams$e(params);
|
|
1562
|
+
return url;
|
|
1563
|
+
};
|
|
1564
|
+
|
|
1565
|
+
base.bind(new Facebook());
|
|
1566
|
+
|
|
1567
|
+
var lib = base;
|
|
1568
|
+
|
|
1569
|
+
return lib;
|
|
1570
|
+
|
|
1571
|
+
})));
|