Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@thelevicole/youtube-to-html5-loader

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@thelevicole/youtube-to-html5-loader - npm Package Compare versions

Comparing version 3.0.1 to 3.1.0

2

dist/YouTubeToHtml5.js

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

'use strict';function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function YouTubeToHtml5(){var a=0<arguments.length&&arguments[0]!==void 0?arguments[0]:{};for(var b in this.options)b in a&&(this.options[b]=a[b]);this.options.autoload&&this.load()}YouTubeToHtml5.prototype.options={selector:"video[data-yt2html5]",attribute:"data-yt2html5",formats:"*",autoload:!0},YouTubeToHtml5.prototype.hooks={filters:[],actions:[]},YouTubeToHtml5.prototype.getHooks=function(a,b){if(a in this.hooks){var c=this.hooks[a].sort(function(c,a){return c.priority-a.priority});return c.filter(function(a){return a.name===b})}return[]},YouTubeToHtml5.prototype.addAction=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:10;this.hooks.actions.push({name:a,callback:b,priority:c})},YouTubeToHtml5.prototype.doAction=function(a){for(var b=this.getHooks("actions",a),c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];for(var f=0;f<b.length;f++){var g;(g=b[f]).callback.apply(g,d)}},YouTubeToHtml5.prototype.addFilter=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:10;this.hooks.filters.push({name:a,callback:b,priority:c})},YouTubeToHtml5.prototype.applyFilters=function(a,b){for(var c=this.getHooks("filters",a),d=arguments.length,e=Array(2<d?d-2:0),f=2;f<d;f++)e[f-2]=arguments[f];for(var g=0;g<c.length;g++){var h;b=(h=c[g]).callback.apply(h,[b].concat(e))}return b},YouTubeToHtml5.prototype.itagMap={18:"360p",22:"720p",37:"1080p",38:"3072p",82:"360p3d",83:"480p3d",84:"720p3d",85:"1080p3d",133:"240pna",134:"360pna",135:"480pna",136:"720pna",137:"1080pna",264:"1440pna",298:"720p60",299:"1080p60na",160:"144pna",139:"48kbps",140:"128kbps",141:"256kbps"},YouTubeToHtml5.prototype.urlToId=function(a){var b=a.match(/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|(?:(?:youtube-nocookie\.com\/|youtube\.com\/)(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/)))([a-zA-Z0-9\-_]*)/);return Array.isArray(b)&&b[1]?b[1]:a},YouTubeToHtml5.prototype.fetch=function(a){return new Promise(function(b,c){var d=new XMLHttpRequest;d.open("GET",a,!0),d.onreadystatechange=function(){4===this.readyState&&(200<=this.status&&400>this.status?b(this.responseText):c(this))},d.send(),d=null})},YouTubeToHtml5.prototype.getAllowedFormats=function(){var a=[];return Array.isArray(this.options.formats)?a=this.options.formats:this.itagMap[this.options.formats]?a=[this.options.formats]:"*"===this.options.formats&&(a=Object.values(this.itagMap).sort()),a},YouTubeToHtml5.prototype.getElements=function(a){var b=null;return a&&(NodeList.prototype.isPrototypeOf(a)||HTMLCollection.prototype.isPrototypeOf(a)?b=a:"object"===_typeof(a)&&"nodeType"in a&&a.nodeType?b=[a]:b=document.querySelectorAll(this.options.selector)),b=Array.from(b||""),this.applyFilters("elements",b)},YouTubeToHtml5.prototype.youtubeDataApiEndpoint=function(a){var b=~~(33*Math.random()),c="https://images".concat(b,"-focus-opensocial.googleusercontent.com/gadgets/proxy?container=none&url=https%3A%2F%2Fwww.youtube.com%2Fget_video_info%3Fvideo_id%3D").concat(a);return this.applyFilters("api.endpoint",c,a,b)},YouTubeToHtml5.prototype.parseUriString=function(a){return a.split("&").reduce(function(a,b){var c=b.split("=").map(function(a){return decodeURIComponent(a.replace("+"," "))});return a[c[0]]=c[1],a},{})},YouTubeToHtml5.prototype.parseYoutubeMeta=function(a){var b=this,c=[],d={},e=this.parseUriString(a);return e.player_response=JSON.parse(e.player_response),e.fflags=this.parseUriString(e.fflags),e=this.applyFilters("api.response",e,a),e.hasOwnProperty("url_encoded_fmt_stream_map")?c=c.concat(e.url_encoded_fmt_stream_map.split(",").map(function(a){return b.parseUriString(a)})):e.hasOwnProperty("adaptive_fmts")?c=c.concat(e.adaptive_fmts.split(",").map(function(a){return b.parseUriString(a)})):e.player_response.streamingData&&e.player_response.streamingData.adaptiveFormats?c=c.concat(e.player_response.streamingData.adaptiveFormats):e.player_response.streamingData&&e.player_response.streamingData.formats&&(c=c.concat(e.player_response.streamingData.formats)),c.forEach(function(a){if(b.itagMap[a.itag]&&a.url){var c="unknown",e="unknown";if("mimeType"in a){var f=a.mimeType.match(/^(audio|video)(?:\/([^;]+);)?/i);f[1]&&(c=f[1]),f[2]&&(e=f[2])}d[b.itagMap[a.itag]]={url:a.url,label:a.qualityLabel||b.itagMap[a.itag],type:c,mime:e}}}),d=this.applyFilters("api.results",d,e),d},YouTubeToHtml5.prototype.load=function(){var a=this,b=this.getElements(this.options.selector);b&&b.length&&b.forEach(function(b){a.loadSingle(b)})},YouTubeToHtml5.prototype.loadSingle=function(a){var b=this,c=1<arguments.length&&arguments[1]!==void 0?arguments[1]:null,d=c||this.options.attribute;if(a.getAttribute(d)){var e=this.urlToId(a.getAttribute(d)),f=this.youtubeDataApiEndpoint(e);this.doAction("api.before",a),this.fetch(f).then(function(c){if(c){var d=b.parseYoutubeMeta(c);if(d){for(var e,f=b.getAllowedFormats(),g=null,h=null,j=0;j<f.length;j++)if(e=f[j],e in d){g=d[e],h=e;break}g=b.applyFilters("video.stream",g,a,h,d),a.src=b.applyFilters("video.source",g.url,g,a,h,d)}}})["finally"](function(c){b.doAction("api.after",a,c)})}},"object"===("undefined"==typeof module?"undefined":_typeof(module))&&"object"===_typeof(module.exports)&&(module.exports=YouTubeToHtml5);
'use strict';function _typeof(a){"@babel/helpers - typeof";return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},_typeof(a)}function YouTubeToHtml5(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{};for(var b in this.hooks={},this.options={},this.defaultOptions)this.options[b]=b in a?a[b]:this.defaultOptions[b];this.options.autoload&&this.load()}YouTubeToHtml5.prototype.defaultOptions={selector:"video[data-yt2html5]",attribute:"data-yt2html5",formats:"*",autoload:!0},YouTubeToHtml5.prototype.globalHooks={},YouTubeToHtml5.prototype.getHooks=function(a,b){var c=[];if(a in this.globalHooks){var d=this.globalHooks[a];d=d.filter(function(a){return a.name===b}),d=d.sort(function(c,a){return c.priority-a.priority}),c=c.concat(d)}if(a in this.hooks){var e=this.hooks[a];e=e.filter(function(a){return a.name===b}),e=e.sort(function(c,a){return c.priority-a.priority}),c=c.concat(e)}return c},YouTubeToHtml5.prototype.addHook=function(a,b){a in this.globalHooks||(this.globalHooks[a]=[]),a in this.hooks||(this.hooks[a]=[]),"global"in b&&b.global?this.globalHooks[a].push(b):this.hooks[a].push(b)},YouTubeToHtml5.prototype.addAction=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:10,d=!!(3<arguments.length&&arguments[3]!==void 0)&&arguments[3];this.addHook("actions",{name:a,callback:b,priority:c,global:d})},YouTubeToHtml5.prototype.doAction=function(a){for(var b=this.getHooks("actions",a),c=arguments.length,d=Array(1<c?c-1:0),e=1;e<c;e++)d[e-1]=arguments[e];for(var f=0;f<b.length;f++){var g;(g=b[f]).callback.apply(g,d)}},YouTubeToHtml5.prototype.addFilter=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:10,d=!!(3<arguments.length&&arguments[3]!==void 0)&&arguments[3];this.addHook("filters",{name:a,callback:b,priority:c,global:d})},YouTubeToHtml5.prototype.applyFilters=function(a,b){for(var c=this.getHooks("filters",a),d=arguments.length,e=Array(2<d?d-2:0),f=2;f<d;f++)e[f-2]=arguments[f];for(var g=0;g<c.length;g++){var h;b=(h=c[g]).callback.apply(h,[b].concat(e))}return b},YouTubeToHtml5.prototype.itagMap={18:"360p",22:"720p",37:"1080p",38:"3072p",82:"360p3d",83:"480p3d",84:"720p3d",85:"1080p3d",133:"240pna",134:"360pna",135:"480pna",136:"720pna",137:"1080pna",264:"1440pna",298:"720p60",299:"1080p60na",160:"144pna",139:"48kbps",140:"128kbps",141:"256kbps"},YouTubeToHtml5.prototype.urlToId=function(a){var b=a.match(/^(?:http(?:s)?:\/\/)?(?:www\.)?(?:m\.)?(?:youtu\.be\/|(?:(?:youtube-nocookie\.com\/|youtube\.com\/)(?:(?:watch)?\?(?:.*&)?v(?:i)?=|(?:embed|v|vi|user)\/)))([a-zA-Z0-9\-_]*)/);return Array.isArray(b)&&b[1]?b[1]:a},YouTubeToHtml5.prototype.fetch=function(a){return new Promise(function(b,c){var d=new XMLHttpRequest;d.open("GET",a,!0),d.onreadystatechange=function(){4===this.readyState&&(200<=this.status&&400>this.status?b(this.responseText):c(this))},d.send(),d=null})},YouTubeToHtml5.prototype.getAllowedFormats=function(){var a=[];return Array.isArray(this.options.formats)?a=this.options.formats:this.itagMap[this.options.formats]?a=[this.options.formats]:"*"===this.options.formats&&(a=Object.values(this.itagMap).sort()),a},YouTubeToHtml5.prototype.getElements=function(a){var b=null;return a&&(NodeList.prototype.isPrototypeOf(a)||HTMLCollection.prototype.isPrototypeOf(a)?b=a:"object"===_typeof(a)&&"nodeType"in a&&a.nodeType?b=[a]:b=document.querySelectorAll(this.options.selector)),b=Array.from(b||""),this.applyFilters("elements",b)},YouTubeToHtml5.prototype.youtubeDataApiEndpoint=function(a){var b=~~(33*Math.random()),c="https://images".concat(b,"-focus-opensocial.googleusercontent.com/gadgets/proxy?container=none&url=https%3A%2F%2Fwww.youtube.com%2Fget_video_info%3Fvideo_id%3D").concat(a);return this.applyFilters("api.endpoint",c,a,b)},YouTubeToHtml5.prototype.parseUriString=function(a){return a.split("&").reduce(function(a,b){var c=b.split("=").map(function(a){return decodeURIComponent(a.replace("+"," "))});return a[c[0]]=c[1],a},{})},YouTubeToHtml5.prototype.parseYoutubeMeta=function(a){var b=this,c=[],d={},e=this.parseUriString(a);return e.player_response=JSON.parse(e.player_response),e.fflags=this.parseUriString(e.fflags),e=this.applyFilters("api.response",e,a),e.hasOwnProperty("url_encoded_fmt_stream_map")?c=c.concat(e.url_encoded_fmt_stream_map.split(",").map(function(a){return b.parseUriString(a)})):e.hasOwnProperty("adaptive_fmts")?c=c.concat(e.adaptive_fmts.split(",").map(function(a){return b.parseUriString(a)})):e.player_response.streamingData&&e.player_response.streamingData.adaptiveFormats?c=c.concat(e.player_response.streamingData.adaptiveFormats):e.player_response.streamingData&&e.player_response.streamingData.formats&&(c=c.concat(e.player_response.streamingData.formats)),c.forEach(function(a){if(b.itagMap[a.itag]&&a.url){var c="unknown",e="unknown";if("mimeType"in a){var f=a.mimeType.match(/^(audio|video)(?:\/([^;]+);)?/i);f[1]&&(c=f[1]),f[2]&&(e=f[2])}d[b.itagMap[a.itag]]={url:a.url,label:a.qualityLabel||b.itagMap[a.itag],type:c,mime:e}}}),d=this.applyFilters("api.results",d,e),d},YouTubeToHtml5.prototype.load=function(){var a=this,b=this.getElements(this.options.selector);b&&b.length&&b.forEach(function(b){a.loadSingle(b)})},YouTubeToHtml5.prototype.loadSingle=function(a){var b=this,c=1<arguments.length&&arguments[1]!==void 0?arguments[1]:null,d=c||this.options.attribute;if(a.getAttribute(d)){var e=this.urlToId(a.getAttribute(d)),f=this.youtubeDataApiEndpoint(e);this.doAction("api.before",a),this.fetch(f).then(function(c){if(c){var d=b.parseYoutubeMeta(c);if(d){for(var e,f=b.getAllowedFormats(),g=null,h=null,j=0;j<f.length;j++)if(e=f[j],e in d){g=d[e],h=e;break}g=b.applyFilters("video.stream",g,a,h,d),a.src=b.applyFilters("video.source",g.url,g,a,h,d)}}})["finally"](function(c){b.doAction("api.after",a,c)})}},"object"===("undefined"==typeof module?"undefined":_typeof(module))&&"object"===_typeof(module.exports)&&(module.exports=YouTubeToHtml5);
{
"name": "@thelevicole/youtube-to-html5-loader",
"version": "3.0.1",
"version": "3.1.0",
"description": "A javascript library to load YoutTube videos as HTML5 emebed elements.",

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

@@ -12,3 +12,11 @@ 'use strict';

/**
* Create an empty local object for storing hooks.
*
* @type {object}
*/
this.hooks = {};
/**
* Create an empty object for storing options.
*
* @type {object}

@@ -48,8 +56,5 @@ */

*
* @type {{filters: [], actions: []}}
* @type {}
*/
YouTubeToHtml5.prototype.hooks = {
filters: [],
actions: []
};
YouTubeToHtml5.prototype.globalHooks = {};

@@ -64,11 +69,58 @@ /**

YouTubeToHtml5.prototype.getHooks = function( type, name ) {
let hooks = [];
if ( type in this.globalHooks ) {
let globalHooks = this.globalHooks[ type ];
globalHooks = globalHooks.filter( el => el.name === name );
globalHooks = globalHooks.sort( ( a, b ) => a.priority - b.priority );
hooks = hooks.concat( globalHooks );
}
if ( type in this.hooks ) {
let hooks = this.hooks[ type ].sort( ( a, b ) => a.priority - b.priority );
return hooks.filter( el => el.name === name );
let localHooks = this.hooks[ type ];
localHooks = localHooks.filter( el => el.name === name );
localHooks = localHooks.sort( ( a, b ) => a.priority - b.priority );
hooks = hooks.concat( localHooks );
}
return [];
return hooks;
};
/**
* Get hooks by type and name. Ordered by priority.
*
* @param {string} type
* @param {object} hookMeta
*/
YouTubeToHtml5.prototype.addHook = function( type, hookMeta ) {
// Create new global hook type array.
if ( !( type in this.globalHooks ) ) {
this.globalHooks[ type ] = [];
}
// Create new local hook type array.
if ( !( type in this.hooks ) ) {
this.hooks[ type ] = [];
}
// Add to global.
if ( 'global' in hookMeta && hookMeta.global ) {
this.globalHooks[ type ].push( hookMeta );
}
// Else, add to local.
else {
this.hooks[ type ].push( hookMeta );
}
};
/**
* Add event lister.

@@ -79,8 +131,10 @@ *

* @param {number} priority
* @param {boolean} global True if this action should apply to all instances.
*/
YouTubeToHtml5.prototype.addAction = function( action, callback, priority = 10 ) {
this.hooks.actions.push( {
YouTubeToHtml5.prototype.addAction = function( action, callback, priority = 10, global = false ) {
this.addHook( 'actions', {
name: action,
callback: callback,
priority: priority
priority: priority,
global: global
} );

@@ -108,8 +162,10 @@ };

* @param {number} priority
* @param {boolean} global True if this action should apply to all instances.
*/
YouTubeToHtml5.prototype.addFilter = function( filter, callback, priority = 10 ) {
this.hooks.filters.push( {
YouTubeToHtml5.prototype.addFilter = function( filter, callback, priority = 10, global = false ) {
this.addHook( 'filters', {
name: filter,
callback: callback,
priority: priority
priority: priority,
global: global
} );

@@ -116,0 +172,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