New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

js-video-url-parser

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

js-video-url-parser - npm Package Compare versions

Comparing version 0.2.3 to 0.2.4

42

dist/jsVideoUrlParser.js

@@ -333,3 +333,2 @@ (function () {

STREAM: 'stream',
EMBEDVIDEO: 'embed-video',
CLIP: 'clip',

@@ -358,19 +357,19 @@ };

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

@@ -383,12 +382,10 @@ return result;

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) {
} else {
mediaType = this.mediaTypes.VIDEO;
} else {
mediaType = this.mediaTypes.STREAM;
}
} else if (result.id) {
mediaType = this.mediaTypes.EMBEDVIDEO;
delete result.channel;

@@ -424,3 +421,3 @@ }

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) {

@@ -431,3 +428,3 @@ params.t = params.start + 's';

} else if (vi.mediaType === this.mediaTypes.CLIP) {
url = 'https://clips.twitch.tv/' + vi.channel + '/' + vi.id;
url = 'https://clips.twitch.tv/' + vi.id;
}

@@ -446,4 +443,3 @@ url += combineParams({

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;

@@ -456,3 +452,3 @@ if (params.start) {

url = 'https://clips.twitch.tv/embed';
params.clip = vi.channel + '/' + vi.id;
params.clip = vi.id;
}

@@ -459,0 +455,0 @@

@@ -1,1 +0,1 @@

!function(){"use strict";function a(b){if(null===b||"object"!=typeof b)return b;var c=b.constructor();for(var d in b)b.hasOwnProperty(d)&&(c[d]=a(b[d]));return c}function b(a){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 c(a){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 d(a){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 e(){this.plugins={}}function f(){this.provider="canalplus",this.defaultFormat="embed",this.formats={embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function g(){this.provider="coub",this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function h(){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 i(){this.provider="twitch",this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video",STREAM:"stream",EMBEDVIDEO:"embed-video",CLIP:"clip"}}function j(){this.provider="vimeo",this.alternatives=["vimeopro"],this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function k(){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 l(){this.provider="youku",this.defaultFormat="long",this.formats={embed:this.createEmbedUrl,long:this.createLongUrl,flash:this.createFlashUrl,static:this.createStaticUrl},this.mediaTypes={VIDEO:"video"}}e.prototype.parseProvider=function(a){var b=a.match(/(?:(?:https?:)?\/\/)?(?:[^\.]+\.)?(\w+)\./i);return b?b[1]:void 0},e.prototype.removeEmptyParameters=function(a){return a.params&&0===Object.keys(a.params).length&&delete a.params,a},e.prototype.parse=function(a){var c,d=this,e=d.parseProvider(a),f=d.plugins[e];if(e&&f&&f.parse)return c=f.parse.apply(f,[a,b(a)]),c&&(c=d.removeEmptyParameters(c),c.provider=f.provider),c},e.prototype.bind=function(a){if(this.plugins[a.provider]=a,a.alternatives)for(var b=0;b<a.alternatives.length;b+=1)this.plugins[a.alternatives[b]]=a},e.prototype.create=function(b){var c=b.videoInfo,d=b.params,e=this.plugins[c.provider];if(d="internal"===d?c.params:d||{},e&&(b.format=b.format||e.defaultFormat,e.formats.hasOwnProperty(b.format)))return e.formats[b.format].apply(e,[c,a(d)])};var m=new e;f.prototype.parseParameters=function(a){return delete a.vid,a},f.prototype.parse=function(a,b){var c=this,d={mediaType:this.mediaTypes.VIDEO,id:b.vid};if(d.params=c.parseParameters(b),d.id)return d},f.prototype.createEmbedUrl=function(a,b){var d="http://player.canalplus.fr/embed/";return b.vid=a.id,d+=c({params:b})},m.bind(new f),g.prototype.parseUrl=function(a){var b=a.match(/(?:embed|view)\/([a-zA-Z\d]+)/i);return b?b[1]:void 0},g.prototype.parse=function(a,b){var c={mediaType:this.mediaTypes.VIDEO,params:b,id:this.parseUrl(a)};if(c.id)return c},g.prototype.createUrl=function(a,b,d){var e=a+b.id;return e+=c({params:d})},g.prototype.createLongUrl=function(a,b){return this.createUrl("https://coub.com/view/",a,b)},g.prototype.createEmbedUrl=function(a,b){return this.createUrl("//coub.com/embed/",a,b)},m.bind(new g),h.prototype.parseParameters=function(a){return this.parseTime(a)},h.prototype.parseTime=function(a){return a.start&&(a.start=d(a.start)),a},h.prototype.parseUrl=function(a){var b=a.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i);return b?b[1]:void 0},h.prototype.parse=function(a,b){var c=this,d={mediaType:this.mediaTypes.VIDEO,params:c.parseParameters(b),id:c.parseUrl(a)};return d.id?d:void 0},h.prototype.createUrl=function(a,b,d){return a+b.id+c({params:d})},h.prototype.createShortUrl=function(a){return this.createUrl("https://dai.ly/",a,{})},h.prototype.createLongUrl=function(a,b){return this.createUrl("https://dailymotion.com/video/",a,b)},h.prototype.createEmbedUrl=function(a,b){return this.createUrl("//www.dailymotion.com/embed/video/",a,b)},m.bind(new h),i.prototype.seperateId=function(a){return{pre:a[0],id:a.substr(1)}},i.prototype.parseChannel=function(a,b){var c=b.channel||b.utm_content||a.channel;return delete b.utm_content,delete b.channel,c},i.prototype.parseUrl=function(a,b,c){var d;if(d=a.match(/(clips\.)?twitch\.tv\/(\w+)(?:\/(?:(.)\/(\d+)|(\w+)))?/i),b.channel=d?d[2]:void 0,d&&d[3]&&d[4])b.id=d[3]+d[4];else if(c.video)b.id=c.video,delete c.video;else if(d&&d[1]&&d[5])b.id=d[5],b.isClip=!0;else if(c.clip){var e=c.clip.split("/");b.channel=e[0],b.id=e[1],b.isClip=!0,delete c.clip}return b},i.prototype.parseMediaType=function(a){var b;return a.channel?a.id&&a.isClip?(b=this.mediaTypes.CLIP,delete a.isClip):b=a.id&&!a.isClip?this.mediaTypes.VIDEO:this.mediaTypes.STREAM:a.id&&(b=this.mediaTypes.EMBEDVIDEO,delete a.channel),b},i.prototype.parseParameters=function(a){return a.t&&(a.start=d(a.t),delete a.t),a},i.prototype.parse=function(a,b){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},i.prototype.createLongUrl=function(a,b){var d="";if(a.mediaType===this.mediaTypes.STREAM)d="https://twitch.tv/"+a.channel;else if(a.mediaType===this.mediaTypes.VIDEO){var e=this.seperateId(a.id);d="https://twitch.tv/"+a.channel+"/"+e.pre+"/"+e.id,b.start&&(b.t=b.start+"s",delete b.start)}else a.mediaType===this.mediaTypes.CLIP&&(d="https://clips.twitch.tv/"+a.channel+"/"+a.id);return d+=c({params:b})},i.prototype.createEmbedUrl=function(a,b){var d="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)):a.mediaType===this.mediaTypes.CLIP&&(d="https://clips.twitch.tv/embed",b.clip=a.channel+"/"+a.id),d+=c({params:b})},m.bind(new i),j.prototype.parseUrl=function(a){var b=a.match(/(?:\/(?:channels\/[\w]+|(?:(?:album\/\d+|groups\/[\w]+)\/)?videos?))?\/(\d+)/i);return b?b[1]:void 0},j.prototype.parseParameters=function(a){return this.parseTime(a)},j.prototype.parseTime=function(a){return a.t&&(a.start=d(a.t),delete a.t),a},j.prototype.parse=function(a,b){var c={mediaType:this.mediaTypes.VIDEO,params:this.parseParameters(b),id:this.parseUrl(a)};return c.id?c:void 0},j.prototype.createUrl=function(a,b,d){var e=a+b.id,f=d.start;return delete d.start,e+=c({params:d}),f&&(e+="#t="+f),e},j.prototype.createLongUrl=function(a,b){return this.createUrl("https://vimeo.com/",a,b)},j.prototype.createEmbedUrl=function(a,b){return this.createUrl("//player.vimeo.com/video/",a,b)},m.bind(new j),k.prototype.parseUrl=function(a){var b=a.match(/(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w\-]{11})/i);return b?b[1]:void 0},k.prototype.parseParameters=function(a,b){return(a.start||a.t)&&(a.start=d(a.start||a.t),delete a.t),a.v===b.id&&delete a.v,a.list===b.id&&delete a.list,a},k.prototype.parseMediaType=function(a){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;delete a.params.ci,a.mediaType=this.mediaTypes.SHARE}return a},k.prototype.parse=function(a,b){var c=this,d={params:b,id:c.parseUrl(a)};return d.params=c.parseParameters(b,d),d=c.parseMediaType(d)},k.prototype.createShortUrl=function(a,b){var c="https://youtu.be/"+a.id;return b.start&&(c+="#t="+b.start),c},k.prototype.createLongUrl=function(a,b){var d="",e=b.start;return delete b.start,a.mediaType===this.mediaTypes.PLAYLIST?(b.feature="share",d+="https://youtube.com/playlist"):a.mediaType===this.mediaTypes.VIDEO?(b.v=a.id,d+="https://youtube.com/watch"):a.mediaType===this.mediaTypes.SHARE&&(b.ci=a.id,d+="https://www.youtube.com/shared"),a.list&&(b.list=a.list),d+=c({params:b}),a.mediaType!==this.mediaTypes.PLAYLIST&&e&&(d+="#t="+e),d},k.prototype.createEmbedUrl=function(a,b){var d="//youtube.com/embed";return a.mediaType===this.mediaTypes.PLAYLIST?b.listType="playlist":(d+="/"+a.id,"1"===b.loop&&(b.playlist=a.id)),a.list&&(b.list=a.list),d+=c({params:b})},k.prototype.createImageUrl=function(a,b,c){var d=a+b.id+"/",e=c.imageQuality||this.defaultImageQuality;return d+e+".jpg"},k.prototype.createShortImageUrl=function(a,b){return this.createImageUrl("https://i.ytimg.com/vi/",a,b)},k.prototype.createLongImageUrl=function(a,b){return this.createImageUrl("https://img.youtube.com/vi/",a,b)},m.bind(new k),l.prototype.parseUrl=function(a){var b=a.match(/(?:(?:embed|sid)\/|v_show\/id_|VideoIDS=)([a-zA-Z0-9]+)/);return b?b[1]:void 0},l.prototype.parseParameters=function(a){return a.VideoIDS&&delete a.VideoIDS,a},l.prototype.parse=function(a,b){var c=this,d={mediaType:this.mediaTypes.VIDEO,id:c.parseUrl(a),params:c.parseParameters(b)};if(d.id)return d},l.prototype.createUrl=function(a,b,d){var e=a+b.id;return e+=c({params:d})},l.prototype.createEmbedUrl=function(a,b){return this.createUrl("http://player.youku.com/embed/",a,b)},l.prototype.createLongUrl=function(a,b){return this.createUrl("http://v.youku.com/v_show/id_",a,b)},l.prototype.createStaticUrl=function(a,b){return this.createUrl("http://static.youku.com/v1.0.0638/v/swf/loader.swf?VideoIDS=",a,b)},l.prototype.createFlashUrl=function(a,b){var d="http://player.youku.com/player.php/sid/"+a.id+"/v.swf";return d+=c({params:b})},m.bind(new l),"undefined"!=typeof window&&(window.urlParser=m),"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports=m)}();
!function(){"use strict";function a(b){if(null===b||"object"!=typeof b)return b;var c=b.constructor();for(var d in b)b.hasOwnProperty(d)&&(c[d]=a(b[d]));return c}function b(a){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 c(a){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 d(a){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 e(){this.plugins={}}function f(){this.provider="canalplus",this.defaultFormat="embed",this.formats={embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function g(){this.provider="coub",this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function h(){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 i(){this.provider="twitch",this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video",STREAM:"stream",CLIP:"clip"}}function j(){this.provider="vimeo",this.alternatives=["vimeopro"],this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}function k(){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 l(){this.provider="youku",this.defaultFormat="long",this.formats={embed:this.createEmbedUrl,long:this.createLongUrl,flash:this.createFlashUrl,static:this.createStaticUrl},this.mediaTypes={VIDEO:"video"}}e.prototype.parseProvider=function(a){var b=a.match(/(?:(?:https?:)?\/\/)?(?:[^\.]+\.)?(\w+)\./i);return b?b[1]:void 0},e.prototype.removeEmptyParameters=function(a){return a.params&&0===Object.keys(a.params).length&&delete a.params,a},e.prototype.parse=function(a){var c,d=this,e=d.parseProvider(a),f=d.plugins[e];if(e&&f&&f.parse)return c=f.parse.apply(f,[a,b(a)]),c&&(c=d.removeEmptyParameters(c),c.provider=f.provider),c},e.prototype.bind=function(a){if(this.plugins[a.provider]=a,a.alternatives)for(var b=0;b<a.alternatives.length;b+=1)this.plugins[a.alternatives[b]]=a},e.prototype.create=function(b){var c=b.videoInfo,d=b.params,e=this.plugins[c.provider];if(d="internal"===d?c.params:d||{},e&&(b.format=b.format||e.defaultFormat,e.formats.hasOwnProperty(b.format)))return e.formats[b.format].apply(e,[c,a(d)])};var m=new e;f.prototype.parseParameters=function(a){return delete a.vid,a},f.prototype.parse=function(a,b){var c=this,d={mediaType:this.mediaTypes.VIDEO,id:b.vid};if(d.params=c.parseParameters(b),d.id)return d},f.prototype.createEmbedUrl=function(a,b){var d="http://player.canalplus.fr/embed/";return b.vid=a.id,d+=c({params:b})},m.bind(new f),g.prototype.parseUrl=function(a){var b=a.match(/(?:embed|view)\/([a-zA-Z\d]+)/i);return b?b[1]:void 0},g.prototype.parse=function(a,b){var c={mediaType:this.mediaTypes.VIDEO,params:b,id:this.parseUrl(a)};if(c.id)return c},g.prototype.createUrl=function(a,b,d){var e=a+b.id;return e+=c({params:d})},g.prototype.createLongUrl=function(a,b){return this.createUrl("https://coub.com/view/",a,b)},g.prototype.createEmbedUrl=function(a,b){return this.createUrl("//coub.com/embed/",a,b)},m.bind(new g),h.prototype.parseParameters=function(a){return this.parseTime(a)},h.prototype.parseTime=function(a){return a.start&&(a.start=d(a.start)),a},h.prototype.parseUrl=function(a){var b=a.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i);return b?b[1]:void 0},h.prototype.parse=function(a,b){var c=this,d={mediaType:this.mediaTypes.VIDEO,params:c.parseParameters(b),id:c.parseUrl(a)};return d.id?d:void 0},h.prototype.createUrl=function(a,b,d){return a+b.id+c({params:d})},h.prototype.createShortUrl=function(a){return this.createUrl("https://dai.ly/",a,{})},h.prototype.createLongUrl=function(a,b){return this.createUrl("https://dailymotion.com/video/",a,b)},h.prototype.createEmbedUrl=function(a,b){return this.createUrl("//www.dailymotion.com/embed/video/",a,b)},m.bind(new h),i.prototype.seperateId=function(a){return{pre:a[0],id:a.substr(1)}},i.prototype.parseChannel=function(a,b){var c=b.channel||b.utm_content||a.channel;return delete b.utm_content,delete b.channel,c},i.prototype.parseUrl=function(a,b,c){var d;return d=a.match(/(clips\.)?twitch\.tv\/(?:(?:videos\/(\d+))|(\w+))?/i),d&&d[2]?b.id="v"+d[2]:c.video?(b.id=c.video,delete c.video):c.clip?(b.id=c.clip,b.isClip=!0,delete c.clip):d&&d[1]&&d[3]?(b.id=d[3],b.isClip=!0):d&&d[3]&&(b.channel=d[3]),b},i.prototype.parseMediaType=function(a){var b;return a.channel?b=this.mediaTypes.STREAM:a.id&&(a.isClip?(b=this.mediaTypes.CLIP,delete a.isClip):b=this.mediaTypes.VIDEO,delete a.channel),b},i.prototype.parseParameters=function(a){return a.t&&(a.start=d(a.t),delete a.t),a},i.prototype.parse=function(a,b){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},i.prototype.createLongUrl=function(a,b){var d="";if(a.mediaType===this.mediaTypes.STREAM)d="https://twitch.tv/"+a.channel;else if(a.mediaType===this.mediaTypes.VIDEO){var e=this.seperateId(a.id);d="https://twitch.tv/videos/"+e.id,b.start&&(b.t=b.start+"s",delete b.start)}else a.mediaType===this.mediaTypes.CLIP&&(d="https://clips.twitch.tv/"+a.id);return d+=c({params:b})},i.prototype.createEmbedUrl=function(a,b){var d="https://player.twitch.tv/";return a.mediaType===this.mediaTypes.STREAM?b.channel=a.channel:a.mediaType===this.mediaTypes.VIDEO?(b.video=a.id,b.start&&(b.t=b.start+"s",delete b.start)):a.mediaType===this.mediaTypes.CLIP&&(d="https://clips.twitch.tv/embed",b.clip=a.id),d+=c({params:b})},m.bind(new i),j.prototype.parseUrl=function(a){var b=a.match(/(?:\/(?:channels\/[\w]+|(?:(?:album\/\d+|groups\/[\w]+)\/)?videos?))?\/(\d+)/i);return b?b[1]:void 0},j.prototype.parseParameters=function(a){return this.parseTime(a)},j.prototype.parseTime=function(a){return a.t&&(a.start=d(a.t),delete a.t),a},j.prototype.parse=function(a,b){var c={mediaType:this.mediaTypes.VIDEO,params:this.parseParameters(b),id:this.parseUrl(a)};return c.id?c:void 0},j.prototype.createUrl=function(a,b,d){var e=a+b.id,f=d.start;return delete d.start,e+=c({params:d}),f&&(e+="#t="+f),e},j.prototype.createLongUrl=function(a,b){return this.createUrl("https://vimeo.com/",a,b)},j.prototype.createEmbedUrl=function(a,b){return this.createUrl("//player.vimeo.com/video/",a,b)},m.bind(new j),k.prototype.parseUrl=function(a){var b=a.match(/(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w\-]{11})/i);return b?b[1]:void 0},k.prototype.parseParameters=function(a,b){return(a.start||a.t)&&(a.start=d(a.start||a.t),delete a.t),a.v===b.id&&delete a.v,a.list===b.id&&delete a.list,a},k.prototype.parseMediaType=function(a){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;delete a.params.ci,a.mediaType=this.mediaTypes.SHARE}return a},k.prototype.parse=function(a,b){var c=this,d={params:b,id:c.parseUrl(a)};return d.params=c.parseParameters(b,d),d=c.parseMediaType(d)},k.prototype.createShortUrl=function(a,b){var c="https://youtu.be/"+a.id;return b.start&&(c+="#t="+b.start),c},k.prototype.createLongUrl=function(a,b){var d="",e=b.start;return delete b.start,a.mediaType===this.mediaTypes.PLAYLIST?(b.feature="share",d+="https://youtube.com/playlist"):a.mediaType===this.mediaTypes.VIDEO?(b.v=a.id,d+="https://youtube.com/watch"):a.mediaType===this.mediaTypes.SHARE&&(b.ci=a.id,d+="https://www.youtube.com/shared"),a.list&&(b.list=a.list),d+=c({params:b}),a.mediaType!==this.mediaTypes.PLAYLIST&&e&&(d+="#t="+e),d},k.prototype.createEmbedUrl=function(a,b){var d="//youtube.com/embed";return a.mediaType===this.mediaTypes.PLAYLIST?b.listType="playlist":(d+="/"+a.id,"1"===b.loop&&(b.playlist=a.id)),a.list&&(b.list=a.list),d+=c({params:b})},k.prototype.createImageUrl=function(a,b,c){var d=a+b.id+"/",e=c.imageQuality||this.defaultImageQuality;return d+e+".jpg"},k.prototype.createShortImageUrl=function(a,b){return this.createImageUrl("https://i.ytimg.com/vi/",a,b)},k.prototype.createLongImageUrl=function(a,b){return this.createImageUrl("https://img.youtube.com/vi/",a,b)},m.bind(new k),l.prototype.parseUrl=function(a){var b=a.match(/(?:(?:embed|sid)\/|v_show\/id_|VideoIDS=)([a-zA-Z0-9]+)/);return b?b[1]:void 0},l.prototype.parseParameters=function(a){return a.VideoIDS&&delete a.VideoIDS,a},l.prototype.parse=function(a,b){var c=this,d={mediaType:this.mediaTypes.VIDEO,id:c.parseUrl(a),params:c.parseParameters(b)};if(d.id)return d},l.prototype.createUrl=function(a,b,d){var e=a+b.id;return e+=c({params:d})},l.prototype.createEmbedUrl=function(a,b){return this.createUrl("http://player.youku.com/embed/",a,b)},l.prototype.createLongUrl=function(a,b){return this.createUrl("http://v.youku.com/v_show/id_",a,b)},l.prototype.createStaticUrl=function(a,b){return this.createUrl("http://static.youku.com/v1.0.0638/v/swf/loader.swf?VideoIDS=",a,b)},l.prototype.createFlashUrl=function(a,b){var d="http://player.youku.com/player.php/sid/"+a.id+"/v.swf";return d+=c({params:b})},m.bind(new l),"undefined"!=typeof window&&(window.urlParser=m),"undefined"!=typeof module&&"undefined"!=typeof module.exports&&(module.exports=m)}();
{
"name": "js-video-url-parser",
"version": "0.2.3",
"version": "0.2.4",
"description": "A parser to extract provider, video id, starttime and others from YouTube, Vimeo, ... urls",

@@ -5,0 +5,0 @@ "main": "dist/jsVideoUrlParser.js",

@@ -15,3 +15,3 @@ jsVideoUrlParser [![Build Status](https://travis-ci.org/Zod-/jsVideoUrlParser.svg)](https://travis-ci.org/Zod-/jsVideoUrlParser) [![Gitter](https://badges.gitter.im/Zod-/jsVideoUrlParser.svg)](https://gitter.im/Zod-/jsVideoUrlParser?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

#grunt
# grunt

@@ -31,7 +31,7 @@ ```shell

#bower
# bower
```shell
bower install js-video-url-parser
```
#npm
# npm
```

@@ -41,8 +41,8 @@ npm install js-video-url-parser

#Usage
##Node
# Usage
## Node
```
urlParser = require('js-video-url-parser');
```
##Parsing
## Parsing

@@ -81,3 +81,3 @@ Parsing a url will return a videoInfo object with all the information

##Url Creation
## Url Creation

@@ -120,3 +120,3 @@ The videoInfo objects can be turned back into urls with the `.create` function.

##Adding a provider
## Adding a provider

@@ -130,7 +130,7 @@ Add a new file in the `src/plugins/provider/` directory with the template found [here](src/plugins/provider/Template.js) and also add it in the [Gruntfile](https://github.com/Zod-/jsVideoUrlParser/blob/master/Gruntfile.js#L13).

#Plugins
# Plugins
##YouTube
## YouTube
####Supported media types:
#### Supported media types:
* `'video'`: Regular videos which can also be livestreams.

@@ -140,3 +140,3 @@ * `'playlist'`: YouTube playlist.

####Supported url formats:
#### Supported url formats:
* `'short'`: Shortened urls.

@@ -148,3 +148,3 @@ * `'long'`(default): Regular urls.

####Creating urls with different media types:
#### Creating urls with different media types:

@@ -157,3 +157,3 @@ | mediaType/formats| short | long | embed | shortImage | longImage |

####Special parameters:
#### Special parameters:
* `'params.start'`: The number where the video should begin in seconds.

@@ -163,3 +163,3 @@ * `'params.imageQuality'`: Custom parameter for generating different qualities of thumbnail urls.

####Parsing Examples:
#### Parsing Examples:
```javascript

@@ -200,3 +200,3 @@ > urlParser.parse('http://www.youtube.com/watch?v=HRb7B9fPhfA');

####Creation Examples:
#### Creation Examples:
```javascript

@@ -296,12 +296,12 @@ > urlParser.create({

##Vimeo
## Vimeo
####Supported media types:
#### Supported media types:
* `'video'`: Regular videos
####Supported url formats:
#### Supported url formats:
* `'long'`(default): Regular urls.
* `'embed'`: Embedded urls.
####Creating urls with different media types:
#### Creating urls with different media types:

@@ -312,6 +312,6 @@ | mediaType/formats| long | embed |

####Special parameters:
#### Special parameters:
* `'params.start'`: The number where the video should begin in seconds.
####Parsing Examples:
#### Parsing Examples:
```javascript

@@ -349,3 +349,3 @@ > urlParser.parse('https://vimeo.com/97276391');

####Creation Examples:
#### Creation Examples:
```javascript

@@ -378,16 +378,14 @@ > urlParser.create({

##Twitch
## Twitch
####Supported media types:
#### Supported media types:
* `'stream'`: Streams which are just a direct url to a channel.
* `'video'`: Regular videos.
* `'video'`: Part of streams or history of a full stream.
* `'clip'`: Short video clips that can be created by anyone on a stream.
* `'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:
#### Supported url formats:
* `'long'`(default): Regular urls.
* `'embed'`: Embedded urls.
####Creating urls with different media types:
#### Creating urls with different media types:

@@ -399,5 +397,4 @@ | mediaType/formats| long | embed |

| **clip** | ✓ | ✓ |
| **embed-video** | X | ✓ |
####Special parameters:
#### Special parameters:
* `'params.start'`: The number where the video should begin in seconds.

@@ -413,12 +410,10 @@

> urlParser.parse('http://www.twitch.tv/rains8/v/75292411');
> urlParser.parse('http://www.twitch.tv/75292411');
{ mediaType: 'video',
id: 'v75292411',
channel: 'rains8',
provider: 'twitch' }
> urlParser.parse('http://www.twitch.tv/rains8/v/75292411?t=1m30s');
> urlParser.parse('http://www.twitch.tv/75292411?t=1m30s');
{ mediaType: 'video',
id: 'v75292411',
channel: 'rains8',
provider: 'twitch',

@@ -430,16 +425,10 @@ params: {

> urlParser.parse('https://player.twitch.tv/?video=v75292411');
{ mediaType: 'embed-video',
id: 'v75292411',
provider: 'twitch' }
> urlParser.parse('https://clips.twitch.tv/rains8/PerfectStingrayFunRun');
> urlParser.parse('https://clips.twitch.tv/embed?clip=rains8/PerfectStingrayFunRun');
> urlParser.parse('https://clips.twitch.tv/SuspiciousImpartialLarkItsBoshyTime');
> urlParser.parse('https://clips.twitch.tv/embed?clip=SuspiciousImpartialLarkItsBoshyTime');
{ mediaType: 'clip',
id: 'PerfectStingrayFunRun',
channel: 'rains8',
id: 'SuspiciousImpartialLarkItsBoshyTime',
provider: 'twitch' }
```
####Creation Examples:
#### Creation Examples:
```javascript

@@ -460,3 +449,2 @@ > urlParser.create({

provider: 'twitch',
channel: 'rains8',
id: 'v75292411',

@@ -467,3 +455,3 @@ mediaType: 'video'

})
'long': 'https://twitch.tv/rains8/v/75292411'
'long': 'https://twitch.tv/75292411'
'embed': 'https://player.twitch.tv/?video=v75292411'

@@ -474,3 +462,2 @@

provider: 'twitch',
channel: 'rains8',
id: 'v75292411',

@@ -484,3 +471,3 @@ mediaType: 'video',

})
'long': 'https://twitch.tv/rains8/v/75292411?t=90s'
'long': 'https://twitch.tv/75292411?t=90s'
'embed': 'https://player.twitch.tv/?video=v75292411?=90s'

@@ -491,14 +478,3 @@

provider: 'twitch',
id: 'v75292411',
mediaType: 'embed-video'
},
format: <format>
})
'embed': 'https://player.twitch.tv/?video=v75292411'
> urlParser.create({
videoInfo: {
provider: 'twitch',
channel: 'rains8',
id: 'PerfectStingrayFunRun',
id: 'SuspiciousImpartialLarkItsBoshyTime',
mediaType: 'clip'

@@ -508,12 +484,12 @@ },

})
'long': 'https://clips.twitch.tv/rains8/PerfectStingrayFunRun'
'embed': 'https://clips.twitch.tv/embed?clip=rains8/PerfectStingrayFunRun'
'long': 'https://clips.twitch.tv/SuspiciousImpartialLarkItsBoshyTime'
'embed': 'https://clips.twitch.tv/embed?clip=SuspiciousImpartialLarkItsBoshyTime'
```
##Dailymotion
## Dailymotion
####Supported media types:
#### Supported media types:
* `'video'`: Regular videos.
####Supported url formats:
#### Supported url formats:
* `'short'`: Shortened urls.

@@ -523,3 +499,3 @@ * `'long'`(default): Regular urls.

####Creating urls with different media types:
#### Creating urls with different media types:

@@ -530,6 +506,6 @@ | mediaType/formats| short | long | embed |

####Special parameters:
#### Special parameters:
* `'params.start'`: The number where the video should begin in seconds.
####Parsing Examples:
#### Parsing Examples:
```javascript

@@ -556,3 +532,3 @@ > urlParser.parse('http://www.dailymotion.com/video/x1e2b95_bruce-lee-nin-kayip-kedisi_animals');

####Creation Examples:
#### Creation Examples:
```javascript

@@ -587,12 +563,12 @@ > urlParser.create({

##Coub
## Coub
####Supported media types:
#### Supported media types:
* `'video'`: Regular videos.
####Supported url formats:
#### Supported url formats:
* `'long'`(default): Regular urls.
* `'embed'`: Embedded urls.
####Creating urls with different media types:
#### Creating urls with different media types:

@@ -603,3 +579,3 @@ | mediaType/formats| long | embed |

####Parsing Examples:
#### Parsing Examples:
```javascript

@@ -613,3 +589,3 @@ > urlParser.parse('https://coub.com/view/by7sm');

####Creation Examples:
#### Creation Examples:
```javascript

@@ -628,8 +604,8 @@ > urlParser.create({

##Youku
## Youku
####Supported media types:
#### Supported media types:
* `'video'`: Regular videos.
####Supported url formats:
#### Supported url formats:
* `'long'`(default): Regular urls.

@@ -640,3 +616,3 @@ * `'static'`: Video player that fills out the whole website.

####Creating urls with different media types:
#### Creating urls with different media types:

@@ -647,3 +623,3 @@ | mediaType/formats| long | static | embed | flash |

####Parsing Examples:
#### Parsing Examples:
```javascript

@@ -659,3 +635,3 @@ > urlParser.parse('http://player.youku.com/embed/XMTQ3OTM4MzMxMg');

####Creation Examples:
#### Creation Examples:
```javascript

@@ -676,11 +652,11 @@ > urlParser.create({

##Canal+
## Canal+
####Supported media types:
#### Supported media types:
* `'video'`: Regular videos.
####Supported url formats:
#### Supported url formats:
* `'embed'`(default): Embedded urls.
####Creating urls with different media types:
#### Creating urls with different media types:

@@ -691,3 +667,3 @@ | mediaType/formats| embed |

####Parsing Examples:
#### Parsing Examples:
```javascript

@@ -701,3 +677,3 @@ > urlParser.parse('http://player.canalplus.fr/embed/?param=cplus&vid=1365175');

####Creation Examples:
#### Creation Examples:
```javascript

@@ -704,0 +680,0 @@ > urlParser.create({

@@ -28,3 +28,2 @@ var tw1 = 'https://clips.twitch.tv/';

id: 'v75292411',
channel: 'rains8',
mediaType: 'video'

@@ -35,13 +34,13 @@ };

formats: {
long: 'https://twitch.tv/rains8/v/75292411',
long: 'https://twitch.tv/videos/75292411',
embed: 'https://player.twitch.tv/?video=v75292411'
},
urls: ['http://www.twitch.tv/rains8/v/75292411']
urls: ['http://www.twitch.tv/videos/75292411']
}, {
videoInfo: cloneObject(vi),
formats: {
long: 'https://twitch.tv/rains8/v/75292411?t=90s',
long: 'https://twitch.tv/videos/75292411?t=90s',
embed: 'https://player.twitch.tv/?t=90s&video=v75292411'
},
urls: ['https://www.twitch.tv/rains8/v/75292411?t=1m30s']
urls: ['https://www.twitch.tv/videos/75292411?t=1m30s']
}];

@@ -54,36 +53,6 @@ tests[1].videoInfo.params = {

QUnit.test('Twitch Embed Video Urls', function (assert) {
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('Twitch Clip Urls', function (assert) {
var vi = {
provider: 'twitch',
id: 'PerfectStingrayFunRun',
channel: 'rains8',
id: 'SuspiciousImpartialLarkItsBoshyTime',
mediaType: 'clip'

@@ -94,8 +63,8 @@ };

formats: {
long: tw1 + 'rains8/PerfectStingrayFunRun',
embed: tw1 + 'embed?clip=rains8/PerfectStingrayFunRun'
long: tw1 + 'SuspiciousImpartialLarkItsBoshyTime',
embed: tw1 + 'embed?clip=SuspiciousImpartialLarkItsBoshyTime'
},
urls: [
tw1 + 'rains8/PerfectStingrayFunRun',
tw1 + 'embed?clip=rains8/PerfectStingrayFunRun'
tw1 + 'SuspiciousImpartialLarkItsBoshyTime',
tw1 + 'embed?clip=SuspiciousImpartialLarkItsBoshyTime'
]

@@ -102,0 +71,0 @@ }];

@@ -499,3 +499,2 @@ (function(){

id: 'v75292411',
channel: 'rains8',
mediaType: 'video'

@@ -506,13 +505,13 @@ };

formats: {
long: 'https://twitch.tv/rains8/v/75292411',
long: 'https://twitch.tv/videos/75292411',
embed: 'https://player.twitch.tv/?video=v75292411'
},
urls: ['http://www.twitch.tv/rains8/v/75292411']
urls: ['http://www.twitch.tv/videos/75292411']
}, {
videoInfo: cloneObject(vi),
formats: {
long: 'https://twitch.tv/rains8/v/75292411?t=90s',
long: 'https://twitch.tv/videos/75292411?t=90s',
embed: 'https://player.twitch.tv/?t=90s&video=v75292411'
},
urls: ['https://www.twitch.tv/rains8/v/75292411?t=1m30s']
urls: ['https://www.twitch.tv/videos/75292411?t=1m30s']
}];

@@ -525,36 +524,6 @@ tests[1].videoInfo.params = {

QUnit.test('Twitch Embed Video Urls', function (assert) {
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('Twitch Clip Urls', function (assert) {
var vi = {
provider: 'twitch',
id: 'PerfectStingrayFunRun',
channel: 'rains8',
id: 'SuspiciousImpartialLarkItsBoshyTime',
mediaType: 'clip'

@@ -565,8 +534,8 @@ };

formats: {
long: tw1 + 'rains8/PerfectStingrayFunRun',
embed: tw1 + 'embed?clip=rains8/PerfectStingrayFunRun'
long: tw1 + 'SuspiciousImpartialLarkItsBoshyTime',
embed: tw1 + 'embed?clip=SuspiciousImpartialLarkItsBoshyTime'
},
urls: [
tw1 + 'rains8/PerfectStingrayFunRun',
tw1 + 'embed?clip=rains8/PerfectStingrayFunRun'
tw1 + 'SuspiciousImpartialLarkItsBoshyTime',
tw1 + 'embed?clip=SuspiciousImpartialLarkItsBoshyTime'
]

@@ -573,0 +542,0 @@ }];

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc