Skip to content

Commit

Permalink
v0.2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Zod- committed Sep 26, 2016
1 parent 3ee3428 commit 7a44426
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jsVideoUrlParser",
"version": "0.2.1",
"version": "0.2.2",
"homepage": "https://github.com/Zod-/jsVideoUrlParser",
"main": "./dist/jsVideoUrlParser.min.js",
"authors": [{
Expand Down
37 changes: 29 additions & 8 deletions dist/jsVideoUrlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,8 @@ function Twitch() {
this.mediaTypes = {
VIDEO: 'video',
STREAM: 'stream',
EMBEDVIDEO: 'embed-video'
EMBEDVIDEO: 'embed-video',
CLIP: 'clip',
};
}

Expand All @@ -350,26 +351,41 @@ Twitch.prototype.parseChannel = function (result, params) {
return channel;
};


Twitch.prototype.parseUrl = function (url, result, params) {
var match;
match = url.match(
/twitch\.tv\/(\w+)(?:\/(.)\/(\d+))?/i
/(clips\.)?twitch\.tv\/(\w+)(?:\/(?:(.)\/(\d+)|(\w+)))?/i
);
result.channel = match ? match[1] : undefined;
if (match && match[2] && match[3]) {
result.id = match[2] + match[3];
} else if (params.video) {
result.channel = match ? match[2] : undefined;
if (match && match[3] && match[4]) { //video
result.id = match[3] + match[4];
} else if (params.video) { //video embed
result.id = params.video;
delete params.video;
} else if (match && match[1] && match[5]) { //clips
result.id = match[5];
result.isClip = true;
} else if (params.clip) { //clips embed
var split = params.clip.split('/');
result.channel = split[0];
result.id = split[1];
result.isClip = true;
delete params.clip;
}
return result;
};

Twitch.prototype.parseMediaType = function (result) {
var mediaType;
if (result.channel) {
mediaType = result.id ? this.mediaTypes.VIDEO : this.mediaTypes.STREAM;
if (result.id && result.isClip) {
mediaType = this.mediaTypes.CLIP;
delete result.isClip;
} else if (result.id && !result.isClip) {
mediaType = this.mediaTypes.VIDEO;
} else {
mediaType = this.mediaTypes.STREAM;
}
} else if (result.id) {
mediaType = this.mediaTypes.EMBEDVIDEO;
delete result.channel;
Expand Down Expand Up @@ -407,6 +423,8 @@ Twitch.prototype.createLongUrl = function (vi, params) {
params.t = params.start + 's';
delete params.start;
}
} else if (vi.mediaType === this.mediaTypes.CLIP) {
url = 'https://clips.twitch.tv/' + vi.channel + '/' + vi.id;
}
url += combineParams({
params: params
Expand All @@ -427,6 +445,9 @@ Twitch.prototype.createEmbedUrl = function (vi, params) {
params.t = params.start + 's';
delete params.start;
}
} else if (vi.mediaType === this.mediaTypes.CLIP) {
url = 'https://clips.twitch.tv/embed';
params.clip = vi.channel + '/' + vi.id;
}

url += combineParams({
Expand Down
Loading

0 comments on commit 7a44426

Please sign in to comment.