Skip to content

Commit

Permalink
v0.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Zod- committed Aug 5, 2017
1 parent d84fb6f commit 53f0ddd
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 66 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.3",
"version": "0.2.4",
"homepage": "https://github.com/Zod-/jsVideoUrlParser",
"main": "./dist/jsVideoUrlParser.min.js",
"authors": [{
Expand Down
42 changes: 19 additions & 23 deletions dist/jsVideoUrlParser.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,6 @@ function Twitch() {
this.mediaTypes = {
VIDEO: 'video',
STREAM: 'stream',
EMBEDVIDEO: 'embed-video',
CLIP: 'clip',
};
}
Expand All @@ -354,40 +353,38 @@ Twitch.prototype.parseChannel = function (result, params) {
Twitch.prototype.parseUrl = function (url, result, params) {
var match;
match = url.match(
/(clips\.)?twitch\.tv\/(\w+)(?:\/(?:(.)\/(\d+)|(\w+)))?/i
/(clips\.)?twitch\.tv\/(?:(?:videos\/(\d+))|(\w+))?/i
);
result.channel = match ? match[2] : undefined;
if (match && match[3] && match[4]) { //video
result.id = match[3] + match[4];

if (match && match[2]) { //video
result.id = 'v' + match[2];
} 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];
} else if (params.clip) { //clips embed
result.id = params.clip;
result.isClip = true;
delete params.clip;
} else if (match && match[1] && match[3]) { //clips
result.id = match[3];
result.isClip = true;
} else if (match && match[3]){
result.channel = match[3];
}
return result;
};

Twitch.prototype.parseMediaType = function (result) {
var mediaType;
if (result.channel) {
if (result.id && result.isClip) {
mediaType = this.mediaTypes.STREAM;
} else if (result.id) {
if (result.isClip){
mediaType = this.mediaTypes.CLIP;
delete result.isClip;
} else if (result.id && !result.isClip) {
mediaType = this.mediaTypes.VIDEO;
} else {
mediaType = this.mediaTypes.STREAM;
mediaType = this.mediaTypes.VIDEO;
}
} else if (result.id) {
mediaType = this.mediaTypes.EMBEDVIDEO;
delete result.channel;
}
return mediaType;
Expand Down Expand Up @@ -418,13 +415,13 @@ Twitch.prototype.createLongUrl = function (vi, params) {
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;
url = 'https://twitch.tv/videos/' + sep.id;
if (params.start) {
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 = 'https://clips.twitch.tv/' + vi.id;
}
url += combineParams({
params: params
Expand All @@ -438,16 +435,15 @@ Twitch.prototype.createEmbedUrl = function (vi, params) {

if (vi.mediaType === this.mediaTypes.STREAM) {
params.channel = vi.channel;
} else if (vi.mediaType === this.mediaTypes.VIDEO ||
vi.mediaType === this.mediaTypes.EMBEDVIDEO) {
} else if (vi.mediaType === this.mediaTypes.VIDEO) {
params.video = vi.id;
if (params.start) {
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;
params.clip = vi.id;
}

url += combineParams({
Expand Down
Loading

0 comments on commit 53f0ddd

Please sign in to comment.