Skip to content

Commit

Permalink
v0.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Zod- committed Nov 16, 2020
1 parent 021a153 commit e1f2fb4
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 3 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-video-url-parser",
"version": "0.4.2",
"version": "0.4.3",
"homepage": "https://github.com/Zod-/jsVideoUrlParser",
"main": "dist/jsVideoUrlParser.js",
"authors": [{
Expand Down
92 changes: 92 additions & 0 deletions dist/jsVideoUrlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,98 @@

base.bind(new TikTok());

var combineParams$c = util.combineParams;

function Ted() {
this.provider = 'ted';
this.formats = {
"long": this.createLongUrl,
embed: this.createEmbedUrl
};
this.mediaTypes = {
VIDEO: 'video',
PLAYLIST: 'playlist'
};
}

Ted.prototype.parseUrl = function (url, result) {
var match = url.match(/\/(talks|playlists\/(\d+))\/([\w-]+)/);
var channel = match ? match[1] : undefined;

if (!channel) {
return result;
}

result.channel = channel.split('/')[0];
result.id = match[3];

if (result.channel === 'playlists') {
result.list = match[2];
}

return result;
};

Ted.prototype.parseMediaType = function (result) {
if (result.id && result.channel === 'playlists') {
delete result.channel;
result.mediaType = this.mediaTypes.PLAYLIST;
}

if (result.id && result.channel === 'talks') {
delete result.channel;
result.mediaType = this.mediaTypes.VIDEO;
}

return result;
};

Ted.prototype.parse = function (url, params) {
var result = {
params: params
};
result = this.parseUrl(url, result);
result = this.parseMediaType(result);

if (!result.id) {
return undefined;
}

return result;
};

Ted.prototype.createLongUrl = function (vi, params) {
var url = '';

if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
url += 'https://ted.com/talks/' + vi.id;
} else if (vi.mediaType === this.mediaTypes.PLAYLIST && vi.id) {
url += 'https://ted.com/playlists/' + vi.list + '/' + vi.id;
} else {
return undefined;
}

url += combineParams$c(params);
return url;
};

Ted.prototype.createEmbedUrl = function (vi, params) {
var url = 'https://embed.ted.com/';

if (vi.mediaType === this.mediaTypes.PLAYLIST && vi.id) {
url += 'playlists/' + vi.list + '/' + vi.id;
} else if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
url += 'talks/' + vi.id;
} else {
return undefined;
}

url += combineParams$c(params);
return url;
};

base.bind(new Ted());

var lib = base;

return lib;
Expand Down
2 changes: 1 addition & 1 deletion dist/jsVideoUrlParser.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "js-video-url-parser",
"version": "0.4.2",
"version": "0.4.3",
"description": "A parser to extract provider, video id, starttime and others from YouTube, Vimeo, ... urls",
"main": "lib/index.js",
"browser": "dist/jsVideoUrlParser.js",
Expand Down

0 comments on commit e1f2fb4

Please sign in to comment.