@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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +195 -0
  3. package/dist/jsVideoUrlParser.js +1571 -0
  4. package/dist/jsVideoUrlParser.min.js +1 -0
  5. package/lib/base.d.ts +2 -0
  6. package/lib/base.js +3 -0
  7. package/lib/index.d.ts +17 -0
  8. package/lib/index.js +18 -0
  9. package/lib/provider/allocine.d.ts +13 -0
  10. package/lib/provider/allocine.js +36 -0
  11. package/lib/provider/base-provider.d.ts +13 -0
  12. package/lib/provider/canalplus.d.ts +13 -0
  13. package/lib/provider/canalplus.js +46 -0
  14. package/lib/provider/coub.d.ts +13 -0
  15. package/lib/provider/coub.js +54 -0
  16. package/lib/provider/dailymotion.d.ts +14 -0
  17. package/lib/provider/dailymotion.js +70 -0
  18. package/lib/provider/facebook.d.ts +14 -0
  19. package/lib/provider/facebook.js +78 -0
  20. package/lib/provider/loom.d.ts +13 -0
  21. package/lib/provider/loom.js +51 -0
  22. package/lib/provider/soundcloud.d.ts +16 -0
  23. package/lib/provider/soundcloud.js +125 -0
  24. package/lib/provider/teachertube.d.ts +14 -0
  25. package/lib/provider/teachertube.js +110 -0
  26. package/lib/provider/ted.d.ts +14 -0
  27. package/lib/provider/ted.js +96 -0
  28. package/lib/provider/tiktok.d.ts +14 -0
  29. package/lib/provider/tiktok.js +50 -0
  30. package/lib/provider/twitch.d.ts +15 -0
  31. package/lib/provider/twitch.js +150 -0
  32. package/lib/provider/vimeo.d.ts +14 -0
  33. package/lib/provider/vimeo.js +89 -0
  34. package/lib/provider/voomly.d.ts +14 -0
  35. package/lib/provider/voomly.js +46 -0
  36. package/lib/provider/wistia.d.ts +15 -0
  37. package/lib/provider/wistia.js +112 -0
  38. package/lib/provider/youku.d.ts +13 -0
  39. package/lib/provider/youku.js +83 -0
  40. package/lib/provider/youtube.d.ts +15 -0
  41. package/lib/provider/youtube.js +205 -0
  42. package/lib/testUrls.js +11 -0
  43. package/lib/urlParser.d.ts +23 -0
  44. package/lib/urlParser.js +81 -0
  45. package/lib/util.js +104 -0
  46. package/package.json +59 -0
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).urlParser=t()}(this,(function(){"use strict";function e(t){return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}var t=function(t,i){if("object"!==e(t))return"";var r="",a=0,s=Object.keys(t);if(0===s.length)return"";for(s.sort(),i||(r+="?"+s[0]+"="+t[s[0]],a+=1);a<s.length;a+=1)r+="&"+s[a]+"="+t[s[a]];return r},i=function(e){return void 0===e?0:e.match(/^(\d+[smhdw]?)+$/)?function(e){var t,i=0,r={s:1,m:60,h:3600,d:86400,w:604800};t=(e=e.replace(/([smhdw])/g," $1 ").trim()).split(" ");for(var a=0;a<t.length;a+=2)i+=parseInt(t[a],10)*r[t[a+1]||"s"];return i}(e):e.match(/^(\d+:?)+$/)?function(e){for(var t=0,i=[1,60,3600,86400,604800],r=e.split(":"),a=0;a<r.length;a++)t+=parseInt(r[a],10)*i[r.length-a-1];return t}(e):0},r=function(e){if("string"!=typeof e)return{};var t,i={},r=(e=e.split("+").join(" ")).match(/(?:[?](?:[^=]+)=(?:[^&#]*)(?:[&](?:[^=]+)=(?:[^&#]*))*(?:[#].*)?)|(?:[#].*)/);if(null===r)return{};t=r[0].substr(1).split(/[&#=]/);for(var a=0;a<t.length;a+=2)i[decodeURIComponent(t[a])]=decodeURIComponent(t[a+1]||"");return i};function a(){for(var e=0,t=["parseProvider","parse","bind","create"];e<t.length;e++){var i=t[e];this[i]=this[i].bind(this)}this.plugins={}}var s=a;a.prototype.parseProvider=function(e){var t=e.match(/(?:(?:https?:)?\/\/)?(?:[^.]+\.)?(\w+)\./i);return t?t[1]:void 0},a.prototype.parse=function(e){if(void 0!==e){var t,i=this.parseProvider(e),a=this.plugins[i];if(i&&a&&a.parse)return(t=a.parse.call(a,e,r(e)))&&((t=function(e){e.params&&0===Object.keys(e.params).length&&delete e.params;return e}(t)).provider=a.provider),t}},a.prototype.bind=function(e){if(this.plugins[e.provider]=e,e.alternatives)for(var t=0;t<e.alternatives.length;t+=1)this.plugins[e.alternatives[t]]=e},a.prototype.create=function(t){if("object"===e(t)&&"object"===e(t.videoInfo)){var i=t.videoInfo,r=t.params,a=this.plugins[i.provider];return r="internal"===r?i.params:r||{},a&&(t.format=t.format||a.defaultFormat,a.formats.hasOwnProperty(t.format))?a.formats[t.format].apply(a,[i,Object.assign({},r)]):void 0}};var o=new s;function n(){this.provider="allocine",this.alternatives=[],this.defaultFormat="embed",this.formats={embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}n.prototype.parseUrl=function(e){var t=e.match(/(?:\/video\/player_gen_cmedia=)([A-Za-z0-9]+)/i);return t?t[1]:void 0},n.prototype.parse=function(e){var t={mediaType:this.mediaTypes.VIDEO,id:this.parseUrl(e)};return t.id?t:void 0},n.prototype.createEmbedUrl=function(e){if(e.id&&e.mediaType===this.mediaTypes.VIDEO)return"https://player.allocine.fr/"+e.id+".html"},o.bind(new n);var p=t;function d(){this.provider="canalplus",this.defaultFormat="embed",this.formats={embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}d.prototype.parseParameters=function(e){return delete e.vid,e},d.prototype.parse=function(e,t){var i={mediaType:this.mediaTypes.VIDEO,id:t.vid};if(i.params=this.parseParameters(t),i.id)return i},d.prototype.createEmbedUrl=function(e,t){if(e.id&&e.mediaType===this.mediaTypes.VIDEO){var i="http://player.canalplus.fr/embed/";return t.vid=e.id,i+=p(t)}},o.bind(new d);var l=t;function m(){this.provider="coub",this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}m.prototype.parseUrl=function(e){var t=e.match(/(?:embed|view)\/([a-zA-Z\d]+)/i);return t?t[1]:void 0},m.prototype.parse=function(e,t){var i={mediaType:this.mediaTypes.VIDEO,params:t,id:this.parseUrl(e)};if(i.id)return i},m.prototype.createUrl=function(e,t,i){if(t.id&&t.mediaType===this.mediaTypes.VIDEO){var r=e+t.id;return r+=l(i)}},m.prototype.createLongUrl=function(e,t){return this.createUrl("https://coub.com/view/",e,t)},m.prototype.createEmbedUrl=function(e,t){return this.createUrl("//coub.com/embed/",e,t)},o.bind(new m);var h=t,c=i;function u(){this.provider="dailymotion",this.alternatives=["dai"],this.defaultFormat="long",this.formats={short:this.createShortUrl,long:this.createLongUrl,embed:this.createEmbedUrl,image:this.createImageUrl},this.mediaTypes={VIDEO:"video"}}u.prototype.parseParameters=function(e){return this.parseTime(e)},u.prototype.parseTime=function(e){return e.start&&(e.start=c(e.start)),e},u.prototype.parseUrl=function(e){var t=e.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i);return t?t[1]:void 0},u.prototype.parse=function(e,t){var i={mediaType:this.mediaTypes.VIDEO,params:this.parseParameters(t),id:this.parseUrl(e)};return i.id?i:void 0},u.prototype.createUrl=function(e,t,i){if(t.id&&t.mediaType===this.mediaTypes.VIDEO)return e+t.id+h(i)},u.prototype.createShortUrl=function(e,t){return this.createUrl("https://dai.ly/",e,t)},u.prototype.createLongUrl=function(e,t){return this.createUrl("https://dailymotion.com/video/",e,t)},u.prototype.createEmbedUrl=function(e,t){return this.createUrl("https://www.dailymotion.com/embed/video/",e,t)},u.prototype.createImageUrl=function(e,t){return delete t.start,this.createUrl("https://www.dailymotion.com/thumbnail/video/",e,t)},o.bind(new u);var y=t;function f(){this.provider="loom",this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}f.prototype.parseUrl=function(e){var t=e.match(/(?:share|embed)\/([a-zA-Z\d]+)/i);return t?t[1]:void 0},f.prototype.parse=function(e,t){var i={mediaType:this.mediaTypes.VIDEO,params:t,id:this.parseUrl(e)};return i.id?i:void 0},f.prototype.createUrl=function(e,t,i){if(t.id&&t.mediaType===this.mediaTypes.VIDEO){var r=e+t.id;return r+=y(i)}},f.prototype.createLongUrl=function(e,t){return this.createUrl("https://loom.com/share/",e,t)},f.prototype.createEmbedUrl=function(e,t){return this.createUrl("//loom.com/embed/",e,t)},o.bind(new f);var v=t,T=i;function U(){this.provider="twitch",this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video",STREAM:"stream",CLIP:"clip"}}U.prototype.seperateId=function(e){return{pre:e[0],id:e.substr(1)}},U.prototype.parseChannel=function(e,t){var i=t.channel||t.utm_content||e.channel;return delete t.utm_content,delete t.channel,i},U.prototype.parseUrl=function(e,t,i){var r;return(r=e.match(/(clips\.)?twitch\.tv\/(?:(?:videos\/(\d+))|(\w+(?:-[\w\d-]+)?)(?:\/clip\/(\w+))?)/i))&&r[2]?t.id="v"+r[2]:i.video?(t.id=i.video,delete i.video):i.clip?(t.id=i.clip,t.isClip=!0,delete i.clip):r&&r[1]&&r[3]?(t.id=r[3],t.isClip=!0):r&&r[3]&&r[4]?(t.channel=r[3],t.id=r[4],t.isClip=!0):r&&r[3]&&(t.channel=r[3]),t},U.prototype.parseMediaType=function(e){var t;return e.id?e.isClip?(t=this.mediaTypes.CLIP,delete e.isClip):t=this.mediaTypes.VIDEO:e.channel&&(t=this.mediaTypes.STREAM),t},U.prototype.parseParameters=function(e){return e.t&&(e.start=T(e.t),delete e.t),e},U.prototype.parse=function(e,t){var i=this,r={};return(r=i.parseUrl(e,r,t)).channel=i.parseChannel(r,t),r.mediaType=i.parseMediaType(r),r.params=i.parseParameters(t),r.channel||r.id?r:void 0},U.prototype.createLongUrl=function(e,t){var i="";if(e.mediaType===this.mediaTypes.STREAM&&e.channel)i="https://twitch.tv/"+e.channel;else if(e.mediaType===this.mediaTypes.VIDEO&&e.id){i="https://twitch.tv/videos/"+this.seperateId(e.id).id,t.start&&(t.t=t.start+"s",delete t.start)}else{if(e.mediaType!==this.mediaTypes.CLIP||!e.id)return;i=e.channel?"https://www.twitch.tv/"+e.channel+"/clip/"+e.id:"https://clips.twitch.tv/"+e.id}return i+=v(t)},U.prototype.createEmbedUrl=function(e,t){var i="https://player.twitch.tv/";if(e.mediaType===this.mediaTypes.STREAM&&e.channel)t.channel=e.channel;else if(e.mediaType===this.mediaTypes.VIDEO&&e.id)t.video=e.id,t.start&&(t.t=t.start+"s",delete t.start);else{if(e.mediaType!==this.mediaTypes.CLIP||!e.id)return;i="https://clips.twitch.tv/embed",t.clip=e.id}return i+=v(t)},o.bind(new U);var b=t,E=i;function I(){this.provider="vimeo",this.alternatives=["vimeopro"],this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video"}}I.prototype.parseUrl=function(e){var t=e.match(/(?:\/showcase\/\d+)?(?:\/(?:channels\/[\w]+|(?:(?:album\/\d+|groups\/[\w]+)\/)?videos?))?\/(\d+)/i);return t?t[1]:void 0},I.prototype.parseHash=function(e){var t=e.match(/\/\d+\/(\w+)$/i);return t?t[1]:void 0},I.prototype.parseParameters=function(e){return e.t&&(e.start=E(e.t),delete e.t),e.h&&(e.hash=e.h,delete e.h),e},I.prototype.parse=function(e,t){var i={mediaType:this.mediaTypes.VIDEO,params:this.parseParameters(t),id:this.parseUrl(e)},r=this.parseHash(e,t);return r&&(i.params.hash=r),i.id?i:void 0},I.prototype.createUrl=function(e,t,i,r){if(t.id&&t.mediaType===this.mediaTypes.VIDEO){var a=e+t.id,s=i.start;return delete i.start,i.hash&&("embed"===r?i.h=i.hash:"long"===r&&(a+="/"+i.hash),delete i.hash),a+=b(i),s&&(a+="#t="+s),a}},I.prototype.createLongUrl=function(e,t){return this.createUrl("https://vimeo.com/",e,t,"long")},I.prototype.createEmbedUrl=function(e,t){return this.createUrl("//player.vimeo.com/video/",e,t,"embed")},o.bind(new I);var w=t,g=i;function L(){this.provider="wistia",this.alternatives=[],this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl,embedjsonp:this.createEmbedJsonpUrl},this.mediaTypes={VIDEO:"video",EMBEDVIDEO:"embedvideo"}}L.prototype.parseUrl=function(e){var t=e.match(/(?:(?:medias|iframe)\/|wvideo=)([\w-]+)/);return t?t[1]:void 0},L.prototype.parseChannel=function(e){var t=e.match(/(?:(?:https?:)?\/\/)?([^.]*)\.wistia\./),i=t?t[1]:void 0;if("fast"!==i&&"content"!==i)return i},L.prototype.parseParameters=function(e,t){return e.wtime&&(e.start=g(e.wtime),delete e.wtime),e.wvideo===t.id&&delete e.wvideo,e},L.prototype.parseMediaType=function(e){return e.id&&e.channel?this.mediaTypes.VIDEO:e.id?(delete e.channel,this.mediaTypes.EMBEDVIDEO):void 0},L.prototype.parse=function(e,t){var i={id:this.parseUrl(e),channel:this.parseChannel(e)};if(i.params=this.parseParameters(t,i),i.mediaType=this.parseMediaType(i),i.id)return i},L.prototype.createUrl=function(e,t,i){return t.start&&(t.wtime=t.start,delete t.start),i+=w(t)},L.prototype.createLongUrl=function(e,t){if(e.id&&e.mediaType===this.mediaTypes.VIDEO){var i="https://"+e.channel+".wistia.com/medias/"+e.id;return this.createUrl(e,t,i)}},L.prototype.createEmbedUrl=function(e,t){if(e.id&&(e.mediaType===this.mediaTypes.VIDEO||e.mediaType===this.mediaTypes.EMBEDVIDEO)){var i="https://fast.wistia.com/embed/iframe/"+e.id;return this.createUrl(e,t,i)}},L.prototype.createEmbedJsonpUrl=function(e){if(e.id&&(e.mediaType===this.mediaTypes.VIDEO||e.mediaType===this.mediaTypes.EMBEDVIDEO))return"https://fast.wistia.com/embed/medias/"+e.id+".jsonp"},o.bind(new L);var D=t;function O(){this.provider="youku",this.defaultFormat="long",this.formats={embed:this.createEmbedUrl,long:this.createLongUrl,flash:this.createFlashUrl,static:this.createStaticUrl},this.mediaTypes={VIDEO:"video"}}O.prototype.parseUrl=function(e){var t=e.match(/(?:(?:embed|sid)\/|v_show\/id_|VideoIDS=)([a-zA-Z0-9]+)/);return t?t[1]:void 0},O.prototype.parseParameters=function(e){return e.VideoIDS&&delete e.VideoIDS,e},O.prototype.parse=function(e,t){var i={mediaType:this.mediaTypes.VIDEO,id:this.parseUrl(e),params:this.parseParameters(t)};if(i.id)return i},O.prototype.createUrl=function(e,t,i){if(t.id&&t.mediaType===this.mediaTypes.VIDEO){var r=e+t.id;return r+=D(i)}},O.prototype.createEmbedUrl=function(e,t){return this.createUrl("http://player.youku.com/embed/",e,t)},O.prototype.createLongUrl=function(e,t){return this.createUrl("http://v.youku.com/v_show/id_",e,t)},O.prototype.createStaticUrl=function(e,t){return this.createUrl("http://static.youku.com/v1.0.0638/v/swf/loader.swf?VideoIDS=",e,t)},O.prototype.createFlashUrl=function(e,t){if(e.id&&e.mediaType===this.mediaTypes.VIDEO){var i="http://player.youku.com/player.php/sid/"+e.id+"/v.swf";return i+=D(t)}},o.bind(new O);var A=t,V=i;function P(){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",CHANNEL:"channel"}}P.prototype.parseVideoUrl=function(e){var t=e.match(/(?:(?:v|vi|be|videos|embed)\/(?!videoseries)|(?:v|ci)=)([\w-]{11})/i);return t?t[1]:void 0},P.prototype.parseChannelUrl=function(e){var t=e.match(/\/channel\/([\w-]+)/);return t?{id:t[1],mediaType:this.mediaTypes.CHANNEL}:(t=e.match(/\/(?:c|user)\/([\w-]+)/))?{name:t[1],mediaType:this.mediaTypes.CHANNEL}:void 0},P.prototype.parseParameters=function(e,t){return(e.start||e.t)&&(e.start=V(e.start||e.t),delete e.t),e.v===t.id&&delete e.v,e.list===t.id&&delete e.list,e},P.prototype.parseMediaType=function(e){if(e.params.list&&(e.list=e.params.list,delete e.params.list),e.id&&!e.params.ci)e.mediaType=this.mediaTypes.VIDEO;else if(e.list)delete e.id,e.mediaType=this.mediaTypes.PLAYLIST;else{if(!e.params.ci)return;delete e.params.ci,e.mediaType=this.mediaTypes.SHARE}return e},P.prototype.parse=function(e,t){var i=this.parseChannelUrl(e);if(i)return i;var r={params:t,id:this.parseVideoUrl(e)};return r.params=this.parseParameters(t,r),r=this.parseMediaType(r)},P.prototype.createShortUrl=function(e,t){if(e.id&&e.mediaType===this.mediaTypes.VIDEO){var i="https://youtu.be/"+e.id;return t.start&&(i+="#t="+t.start),i}},P.prototype.createLongUrl=function(e,t){var i="",r=t.start;if(delete t.start,e.mediaType===this.mediaTypes.CHANNEL)if(e.id)i+="https://www.youtube.com/channel/"+e.id;else{if(!e.name)return;i+="https://www.youtube.com/c/"+e.name}else if(e.mediaType===this.mediaTypes.PLAYLIST&&e.list)t.feature="share",i+="https://www.youtube.com/playlist";else if(e.mediaType===this.mediaTypes.VIDEO&&e.id)t.v=e.id,i+="https://www.youtube.com/watch";else{if(e.mediaType!==this.mediaTypes.SHARE||!e.id)return;t.ci=e.id,i+="https://www.youtube.com/shared"}return e.list&&(t.list=e.list),i+=A(t),e.mediaType!==this.mediaTypes.PLAYLIST&&r&&(i+="#t="+r),i},P.prototype.createEmbedUrl=function(e,t){var i="https://www.youtube.com/embed";if(e.mediaType===this.mediaTypes.PLAYLIST&&e.list)t.listType="playlist";else{if(e.mediaType!==this.mediaTypes.VIDEO||!e.id)return;i+="/"+e.id,"1"===t.loop&&(t.playlist=e.id)}return e.list&&(t.list=e.list),i+=A(t)},P.prototype.createImageUrl=function(e,t,i){if(t.id&&t.mediaType===this.mediaTypes.VIDEO)return e+t.id+"/"+(i.imageQuality||this.defaultImageQuality)+".jpg"},P.prototype.createShortImageUrl=function(e,t){return this.createImageUrl("https://i.ytimg.com/vi/",e,t)},P.prototype.createLongImageUrl=function(e,t){return this.createImageUrl("https://img.youtube.com/vi/",e,t)},o.bind(new P);var S=t,C=i;function M(){this.provider="soundcloud",this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={TRACK:"track",PLAYLIST:"playlist",APITRACK:"apitrack",APIPLAYLIST:"apiplaylist"}}M.prototype.parseUrl=function(e,t){var i=e.match(/(?:m\.)?soundcloud\.com\/(?:([\w-]+)\/(sets\/)?)([\w-]+)/i);return i?(t.channel=i[1],"playlists"===i[1]||i[2]?t.list=i[3]:t.id=i[3],t):t},M.prototype.parseParameters=function(e){return e.t&&(e.start=C(e.t),delete e.t),e},M.prototype.parseMediaType=function(e){return e.id&&("tracks"===e.channel?(delete e.channel,delete e.params.url,e.mediaType=this.mediaTypes.APITRACK):e.mediaType=this.mediaTypes.TRACK),e.list&&("playlists"===e.channel?(delete e.channel,delete e.params.url,e.mediaType=this.mediaTypes.APIPLAYLIST):e.mediaType=this.mediaTypes.PLAYLIST),e},M.prototype.parse=function(e,t){var i={};if((i=this.parseUrl(e,i)).params=this.parseParameters(t),(i=this.parseMediaType(i)).id||i.list)return i},M.prototype.createLongUrl=function(e,t){var i="",r=t.start;if(delete t.start,e.mediaType===this.mediaTypes.TRACK&&e.id&&e.channel)i="https://soundcloud.com/"+e.channel+"/"+e.id;else if(e.mediaType===this.mediaTypes.PLAYLIST&&e.list&&e.channel)i="https://soundcloud.com/"+e.channel+"/sets/"+e.list;else if(e.mediaType===this.mediaTypes.APITRACK&&e.id)i="https://api.soundcloud.com/tracks/"+e.id;else{if(e.mediaType!==this.mediaTypes.APIPLAYLIST||!e.list)return;i="https://api.soundcloud.com/playlists/"+e.list}return i+=S(t),r&&(i+="#t="+r),i},M.prototype.createEmbedUrl=function(e,t){var i="https://w.soundcloud.com/player/";if(delete t.start,e.mediaType===this.mediaTypes.APITRACK&&e.id)t.url="https%3A//api.soundcloud.com/tracks/"+e.id;else{if(e.mediaType!==this.mediaTypes.APIPLAYLIST||!e.list)return;t.url="https%3A//api.soundcloud.com/playlists/"+e.list}return i+=S(t)},o.bind(new M);var k=t;function F(){this.provider="teachertube",this.alternatives=[],this.defaultFormat="long",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video",AUDIO:"audio",DOCUMENT:"document",CHANNEL:"channel",COLLECTION:"collection",GROUP:"group"}}F.prototype.parse=function(e,t){var i={};i.list=this.parsePlaylist(t),i.params=t;var r=e.match(/\/(audio|video|document|user\/channel|collection|group)\/(?:[\w-]+-)?(\w+)/);if(r)return i.mediaType=this.parseMediaType(r[1]),i.id=r[2],i},F.prototype.parsePlaylist=function(e){if(e["playlist-id"]){var t=e["playlist-id"];return delete e["playlist-id"],t}},F.prototype.parseMediaType=function(e){switch(e){case"audio":return this.mediaTypes.AUDIO;case"video":return this.mediaTypes.VIDEO;case"document":return this.mediaTypes.DOCUMENT;case"user/channel":return this.mediaTypes.CHANNEL;case"collection":return this.mediaTypes.COLLECTION;case"group":return this.mediaTypes.GROUP}},F.prototype.createLongUrl=function(e,t){if(e.id){var i="https://www.teachertube.com/";return e.list&&(t["playlist-id"]=e.list),e.mediaType===this.mediaTypes.CHANNEL?i+="user/channel/":i+=e.mediaType+"/",i+=e.id,i+=k(t)}},F.prototype.createEmbedUrl=function(e,t){if(e.id){var i="https://www.teachertube.com/embed/";if(e.mediaType===this.mediaTypes.VIDEO||e.mediaType===this.mediaTypes.AUDIO)return i+=e.mediaType+"/"+e.id,i+=k(t)}},o.bind(new F);var R=t;function N(){this.provider="tiktok",this.defaultFormat="long",this.formats={long:this.createLongUrl},this.mediaTypes={VIDEO:"video"}}N.prototype.parse=function(e,t){var i={params:t,mediaType:this.mediaTypes.VIDEO},r=e.match(/@([^/]+)\/video\/(\d{19})/);if(r)return i.channel=r[1],i.id=r[2],i},N.prototype.createLongUrl=function(e,t){var i="";if(e.mediaType===this.mediaTypes.VIDEO&&e.id&&e.channel)return i+="https://www.tiktok.com/@".concat(e.channel,"/video/").concat(e.id),i+=R(t)},o.bind(new N);var Y=t;function H(){this.provider="ted",this.formats={long:this.createLongUrl,embed:this.createEmbedUrl},this.mediaTypes={VIDEO:"video",PLAYLIST:"playlist"}}H.prototype.parseUrl=function(e,t){var i=e.match(/\/(talks|playlists\/(\d+))\/([\w-]+)/i),r=i?i[1]:void 0;return r?(t.channel=r.split("/")[0],t.id=i[3],"playlists"===t.channel&&(t.list=i[2]),t):t},H.prototype.parseMediaType=function(e){return e.id&&"playlists"===e.channel&&(delete e.channel,e.mediaType=this.mediaTypes.PLAYLIST),e.id&&"talks"===e.channel&&(delete e.channel,e.mediaType=this.mediaTypes.VIDEO),e},H.prototype.parse=function(e,t){var i={params:t};if(i=this.parseUrl(e,i),(i=this.parseMediaType(i)).id)return i},H.prototype.createLongUrl=function(e,t){var i="";if(e.mediaType===this.mediaTypes.VIDEO&&e.id)i+="https://ted.com/talks/"+e.id;else{if(e.mediaType!==this.mediaTypes.PLAYLIST||!e.id)return;i+="https://ted.com/playlists/"+e.list+"/"+e.id}return i+=Y(t)},H.prototype.createEmbedUrl=function(e,t){var i="https://embed.ted.com/";if(e.mediaType===this.mediaTypes.PLAYLIST&&e.id)i+="playlists/"+e.list+"/"+e.id;else{if(e.mediaType!==this.mediaTypes.VIDEO||!e.id)return;i+="talks/"+e.id}return i+=Y(t)},o.bind(new H);var j=t;function Q(){this.provider="facebook",this.alternatives=[],this.defaultFormat="long",this.formats={long:this.createLongUrl,watch:this.createWatchUrl},this.mediaTypes={VIDEO:"video"}}return Q.prototype.parse=function(e,t){var i={params:t,mediaType:this.mediaTypes.VIDEO},r=e.match(/(?:\/(\d+))?\/videos(?:\/.*?)?\/(\d+)/i);if(r&&(r[1]&&(i.pageId=r[1]),i.id=r[2]),t.v&&!i.id&&(i.id=t.v,delete t.v,i.params=t),i.id)return i},Q.prototype.createWatchUrl=function(e,t){var i="https://facebook.com/watch/";if(e.mediaType===this.mediaTypes.VIDEO&&e.id)return t={v:e.id},i+=j(t)},Q.prototype.createLongUrl=function(e,t){var i="https://facebook.com/";if(e.pageId&&(i+=e.pageId,e.mediaType===this.mediaTypes.VIDEO&&e.id))return i+="/videos/"+e.id,i+=j(t)},o.bind(new Q),o}));
package/lib/base.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import UrlParser from './urlParser';
2
+ export default UrlParser.prototype;
package/lib/base.js ADDED
@@ -0,0 +1,3 @@
1
+ const UrlParser = require('./urlParser');
2
+ const parser = new UrlParser();
3
+ module.exports = parser;
package/lib/index.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ // Minimum TypeScript Version: 3.1
2
+
3
+ export { default } from './base';
4
+ export * from './provider/allocine';
5
+ export * from './provider/canalplus';
6
+ export * from './provider/coub';
7
+ export * from './provider/dailymotion';
8
+ export * from './provider/loom';
9
+ export * from './provider/soundcloud';
10
+ export * from './provider/teachertube';
11
+ export * from './provider/twitch';
12
+ export * from './provider/vimeo';
13
+ export * from './provider/wistia';
14
+ export * from './provider/youku';
15
+ export * from './provider/youtube';
16
+ export * from './provider/ted';
17
+ export * from './provider/tiktok';
package/lib/index.js ADDED
@@ -0,0 +1,18 @@
1
+ const parser = require('./base');
2
+ require('./provider/allocine');
3
+ require('./provider/canalplus');
4
+ require('./provider/coub');
5
+ require('./provider/dailymotion');
6
+ require('./provider/loom');
7
+ require('./provider/twitch');
8
+ require('./provider/vimeo');
9
+ require('./provider/wistia');
10
+ require('./provider/youku');
11
+ require('./provider/youtube');
12
+ require('./provider/soundcloud');
13
+ require('./provider/teachertube');
14
+ require('./provider/tiktok');
15
+ require('./provider/voomly');
16
+ require('./provider/ted');
17
+ require('./provider/facebook');
18
+ module.exports = parser;
@@ -0,0 +1,13 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export interface AllocineUrlParameters {
4
+ [key: string]: any;
5
+ }
6
+
7
+ export type AllocineMediaTypes = 'video';
8
+
9
+ export interface AllocineVideoInfo extends VideoInfo<AllocineUrlParameters, AllocineMediaTypes> {
10
+ provider: 'allocine';
11
+ }
12
+
13
+ export type AllocineParseResult = AllocineVideoInfo | undefined;
@@ -0,0 +1,36 @@
1
+ function Allocine() {
2
+ this.provider = 'allocine';
3
+ this.alternatives = [];
4
+ this.defaultFormat = 'embed';
5
+ this.formats = {
6
+ embed: this.createEmbedUrl,
7
+ };
8
+ this.mediaTypes = {
9
+ VIDEO: 'video',
10
+ };
11
+ }
12
+
13
+ module.exports = Allocine;
14
+
15
+ Allocine.prototype.parseUrl = function(url) {
16
+ var match = url.match(/(?:\/video\/player_gen_cmedia=)([A-Za-z0-9]+)/i);
17
+ return match ? match[1] : undefined;
18
+ };
19
+
20
+ Allocine.prototype.parse = function(url) {
21
+ var result = {
22
+ mediaType: this.mediaTypes.VIDEO,
23
+ id: this.parseUrl(url),
24
+ };
25
+ return result.id ? result : undefined;
26
+ };
27
+
28
+ Allocine.prototype.createEmbedUrl = function(vi) {
29
+ if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
30
+ return undefined;
31
+ }
32
+
33
+ return 'https://player.allocine.fr/' + vi.id + '.html';
34
+ };
35
+
36
+ require('../base').bind(new Allocine());
@@ -0,0 +1,13 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export type FormatHandler<UrlParameters> = (vi: VideoInfo<UrlParameters>, params: Record<string, string>) => string;
4
+
5
+ export default class Provider<FormatKeys extends string | number | symbol = string, MediaTypes = 'video', UrlParameters = Record<string, any>> {
6
+ provider: string;
7
+ alternatives: string[];
8
+ defaultFormat: FormatKeys;
9
+ formats: Record<FormatKeys, FormatHandler<UrlParameters>>;
10
+ mediaTypes: Record<string, MediaTypes>;
11
+
12
+ parse(url: string, params: Record<string, any>): VideoInfo<UrlParameters> | undefined;
13
+ }
@@ -0,0 +1,13 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export interface CanalPlusUrlParameters {
4
+ [key: string]: any;
5
+ }
6
+
7
+ export type CanalPlusMediaTypes = 'video';
8
+
9
+ export interface CanalPlusVideoInfo extends VideoInfo<CanalPlusUrlParameters, CanalPlusMediaTypes> {
10
+ provider: 'canalplus';
11
+ }
12
+
13
+ export type CanalPlusParseResult = CanalPlusVideoInfo | undefined;
@@ -0,0 +1,46 @@
1
+ const { combineParams } = require('../util');
2
+
3
+ function CanalPlus() {
4
+ this.provider = 'canalplus';
5
+ this.defaultFormat = 'embed';
6
+ this.formats = {
7
+ embed: this.createEmbedUrl,
8
+ };
9
+ this.mediaTypes = {
10
+ VIDEO: 'video',
11
+ };
12
+ }
13
+
14
+ module.exports = CanalPlus;
15
+
16
+ CanalPlus.prototype.parseParameters = function(params) {
17
+ delete params.vid;
18
+ return params;
19
+ };
20
+
21
+ CanalPlus.prototype.parse = function(url, params) {
22
+ var _this = this;
23
+ var result = {
24
+ mediaType: this.mediaTypes.VIDEO,
25
+ id: params.vid,
26
+ };
27
+ result.params = _this.parseParameters(params);
28
+
29
+ if (!result.id) {
30
+ return undefined;
31
+ }
32
+ return result;
33
+ };
34
+
35
+ CanalPlus.prototype.createEmbedUrl = function(vi, params) {
36
+ if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
37
+ return undefined;
38
+ }
39
+ var url = 'http://player.canalplus.fr/embed/';
40
+ params.vid = vi.id;
41
+
42
+ url += combineParams(params);
43
+ return url;
44
+ };
45
+
46
+ require('../base').bind(new CanalPlus());
@@ -0,0 +1,13 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export interface CoubUrlParameters {
4
+ [key: string]: any;
5
+ }
6
+
7
+ export type CoubMediaTypes = 'video';
8
+
9
+ export interface CoubVideoInfo extends VideoInfo<CoubUrlParameters, CoubMediaTypes> {
10
+ provider: 'coub';
11
+ }
12
+
13
+ export type CoubParseResult = CoubVideoInfo | undefined;
@@ -0,0 +1,54 @@
1
+ const { combineParams } = require('../util');
2
+
3
+ function Coub() {
4
+ this.provider = 'coub';
5
+ this.defaultFormat = 'long';
6
+ this.formats = {
7
+ long: this.createLongUrl,
8
+ embed: this.createEmbedUrl,
9
+ };
10
+ this.mediaTypes = {
11
+ VIDEO: 'video',
12
+ };
13
+ }
14
+
15
+ module.exports = Coub;
16
+
17
+ Coub.prototype.parseUrl = function(url) {
18
+ var match = url.match(
19
+ /(?:embed|view)\/([a-zA-Z\d]+)/i
20
+ );
21
+ return match ? match[1] : undefined;
22
+ };
23
+
24
+ Coub.prototype.parse = function(url, params) {
25
+ var result = {
26
+ mediaType: this.mediaTypes.VIDEO,
27
+ params: params,
28
+ id: this.parseUrl(url),
29
+ };
30
+
31
+ if (!result.id) {
32
+ return undefined;
33
+ }
34
+ return result;
35
+ };
36
+
37
+ Coub.prototype.createUrl = function(baseUrl, vi, params) {
38
+ if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
39
+ return undefined;
40
+ }
41
+ var url = baseUrl + vi.id;
42
+ url += combineParams(params);
43
+ return url;
44
+ };
45
+
46
+ Coub.prototype.createLongUrl = function(vi, params) {
47
+ return this.createUrl('https://coub.com/view/', vi, params);
48
+ };
49
+
50
+ Coub.prototype.createEmbedUrl = function(vi, params) {
51
+ return this.createUrl('//coub.com/embed/', vi, params);
52
+ };
53
+
54
+ require('../base').bind(new Coub());
@@ -0,0 +1,14 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export interface DailymotionUrlParameters {
4
+ [key: string]: any;
5
+ start?: number;
6
+ }
7
+
8
+ export type DailymotionMediaTypes = 'video';
9
+
10
+ export interface DailymotionVideoInfo extends VideoInfo<DailymotionUrlParameters, DailymotionMediaTypes> {
11
+ provider: 'dailymotion';
12
+ }
13
+
14
+ export type DailymotionParseResult = DailymotionVideoInfo | undefined;
@@ -0,0 +1,70 @@
1
+ const { combineParams, getTime } = require('../util');
2
+
3
+ function Dailymotion() {
4
+ this.provider = 'dailymotion';
5
+ this.alternatives = ['dai'];
6
+ this.defaultFormat = 'long';
7
+ this.formats = {
8
+ short: this.createShortUrl,
9
+ long: this.createLongUrl,
10
+ embed: this.createEmbedUrl,
11
+ image: this.createImageUrl,
12
+ };
13
+ this.mediaTypes = {
14
+ VIDEO: 'video',
15
+ };
16
+ }
17
+
18
+ module.exports = Dailymotion;
19
+
20
+ Dailymotion.prototype.parseParameters = function(params) {
21
+ return this.parseTime(params);
22
+ };
23
+
24
+ Dailymotion.prototype.parseTime = function(params) {
25
+ if (params.start) {
26
+ params.start = getTime(params.start);
27
+ }
28
+ return params;
29
+ };
30
+
31
+ Dailymotion.prototype.parseUrl = function(url) {
32
+ var match = url.match(/(?:\/video|ly)\/([A-Za-z0-9]+)/i);
33
+ return match ? match[1] : undefined;
34
+ };
35
+
36
+ Dailymotion.prototype.parse = function(url, params) {
37
+ var _this = this;
38
+ var result = {
39
+ mediaType: this.mediaTypes.VIDEO,
40
+ params: _this.parseParameters(params),
41
+ id: _this.parseUrl(url),
42
+ };
43
+ return result.id ? result : undefined;
44
+ };
45
+
46
+ Dailymotion.prototype.createUrl = function(base, vi, params) {
47
+ if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
48
+ return undefined;
49
+ }
50
+ return base + vi.id + combineParams(params);
51
+ };
52
+
53
+ Dailymotion.prototype.createShortUrl = function(vi, params) {
54
+ return this.createUrl('https://dai.ly/', vi, params);
55
+ };
56
+
57
+ Dailymotion.prototype.createLongUrl = function(vi, params) {
58
+ return this.createUrl('https://dailymotion.com/video/', vi, params);
59
+ };
60
+
61
+ Dailymotion.prototype.createEmbedUrl = function(vi, params) {
62
+ return this.createUrl('https://www.dailymotion.com/embed/video/', vi, params);
63
+ };
64
+
65
+ Dailymotion.prototype.createImageUrl = function(vi, params) {
66
+ delete params.start;
67
+ return this.createUrl('https://www.dailymotion.com/thumbnail/video/', vi, params);
68
+ };
69
+
70
+ require('../base').bind(new Dailymotion());
@@ -0,0 +1,14 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export interface FacebookUrlParameters {
4
+ [key: string]: any;
5
+ }
6
+
7
+ export type FacebookMediaTypes = 'video';
8
+
9
+ export interface FacebookVideoInfo extends VideoInfo<FacebookUrlParameters, FacebookMediaTypes> {
10
+ provider: 'facebook';
11
+ pageId?: string;
12
+ }
13
+
14
+ export type FacebookParseResult = FacebookVideoInfo | undefined;
@@ -0,0 +1,78 @@
1
+ const {
2
+ combineParams,
3
+ } = require('../util');
4
+
5
+ function Facebook() {
6
+ this.provider = 'facebook';
7
+ this.alternatives = [];
8
+ this.defaultFormat = 'long';
9
+ this.formats = {
10
+ long: this.createLongUrl,
11
+ watch: this.createWatchUrl,
12
+ };
13
+ this.mediaTypes = {
14
+ VIDEO: 'video',
15
+ };
16
+ }
17
+
18
+ module.exports = Facebook;
19
+
20
+ Facebook.prototype.parse = function(url, params) {
21
+ var result = {
22
+ params: params,
23
+ mediaType: this.mediaTypes.VIDEO,
24
+ };
25
+
26
+ var match = url.match(/(?:\/(\d+))?\/videos(?:\/.*?)?\/(\d+)/i);
27
+ if (match) {
28
+ if (match[1]) {
29
+ result.pageId = match[1];
30
+ }
31
+ result.id = match[2];
32
+ }
33
+ if (params.v && !result.id) {
34
+ result.id = params.v;
35
+ delete params.v;
36
+ result.params = params;
37
+ }
38
+
39
+ if (!result.id) {
40
+ return undefined;
41
+ }
42
+
43
+ return result;
44
+ };
45
+
46
+ Facebook.prototype.createWatchUrl = function(vi, params) {
47
+ var url = 'https://facebook.com/watch/';
48
+
49
+ if (vi.mediaType !== this.mediaTypes.VIDEO || !vi.id) {
50
+ return undefined;
51
+ }
52
+ params = { v: vi.id };
53
+ url += combineParams(params);
54
+
55
+ return url;
56
+ };
57
+
58
+ Facebook.prototype.createLongUrl = function(vi, params) {
59
+ var url = 'https://facebook.com/';
60
+
61
+ if (vi.pageId) {
62
+ url += vi.pageId;
63
+ } else {
64
+ return undefined;
65
+ }
66
+
67
+ if (vi.mediaType === this.mediaTypes.VIDEO && vi.id) {
68
+ url += '/videos/' + vi.id;
69
+ } else {
70
+ return undefined;
71
+ }
72
+
73
+ url += combineParams(params);
74
+
75
+ return url;
76
+ };
77
+
78
+ require('../base').bind(new Facebook());
@@ -0,0 +1,13 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export interface LoomUrlParameters {
4
+ [key: string]: any;
5
+ }
6
+
7
+ export type LoomMediaTypes = 'video';
8
+
9
+ export interface LoomVideoInfo extends VideoInfo<LoomUrlParameters, LoomMediaTypes> {
10
+ provider: 'loom';
11
+ }
12
+
13
+ export type LoomParseResult = LoomVideoInfo | undefined;
@@ -0,0 +1,51 @@
1
+ const { combineParams } = require('../util');
2
+
3
+ function Loom() {
4
+ this.provider = 'loom';
5
+ this.defaultFormat = 'long';
6
+ this.formats = {
7
+ long: this.createLongUrl,
8
+ embed: this.createEmbedUrl,
9
+ };
10
+ this.mediaTypes = {
11
+ VIDEO: 'video',
12
+ };
13
+ }
14
+
15
+ module.exports = Loom;
16
+
17
+ Loom.prototype.parseUrl = function(url) {
18
+ var match = url.match(
19
+ /(?:share|embed)\/([a-zA-Z\d]+)/i
20
+ );
21
+ return match ? match[1] : undefined;
22
+ };
23
+
24
+ Loom.prototype.parse = function(url, params) {
25
+ var result = {
26
+ mediaType: this.mediaTypes.VIDEO,
27
+ params: params,
28
+ id: this.parseUrl(url),
29
+ };
30
+ return result.id ? result : undefined;
31
+ };
32
+
33
+ Loom.prototype.createUrl = function(baseUrl, vi, params) {
34
+ if (!vi.id || vi.mediaType !== this.mediaTypes.VIDEO) {
35
+ return undefined;
36
+ }
37
+
38
+ var url = baseUrl + vi.id;
39
+ url += combineParams(params);
40
+ return url;
41
+ };
42
+
43
+ Loom.prototype.createLongUrl = function(vi, params) {
44
+ return this.createUrl('https://loom.com/share/', vi, params);
45
+ };
46
+
47
+ Loom.prototype.createEmbedUrl = function(vi, params) {
48
+ return this.createUrl('//loom.com/embed/', vi, params);
49
+ };
50
+
51
+ require('../base').bind(new Loom());
@@ -0,0 +1,16 @@
1
+ import { VideoInfo } from '../urlParser';
2
+
3
+ export interface SoundCloudUrlParameters {
4
+ [key: string]: any;
5
+ start?: number;
6
+ }
7
+
8
+ export type SoundCloudMediaTypes = 'track' | 'playlist' | 'apitrack' | 'apiplaylist';
9
+
10
+ export interface SoundCloudVideoInfo extends VideoInfo<SoundCloudUrlParameters, SoundCloudMediaTypes> {
11
+ provider: 'soundcloud';
12
+ list?: string;
13
+ channel?: string;
14
+ }
15
+
16
+ export type SoundCloudParseResult = SoundCloudVideoInfo | undefined;