-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathnapster.min.js
1 lines (1 loc) · 3.99 KB
/
napster.min.js
1
!function(t,o,n){"use strict";if(t&&o&&o.ajax&&n){var r=n.stringify;n.stringify=function(e){return r(e,function(e,t){return"genre"===e?{id:t.id,name:t.name}:t})};var e=function(e,t,n){var r=e[t];e[t]=function(){return n.length===arguments.length?n.apply(this,arguments):"function"==typeof r?r.apply(this,arguments):void 0}},a="napster.member.accessToken",s="napster.member.refreshToken",i=function(e){for(var t in e)this[t]=e[t]},c={init:function(t){this.api.consumerKey=t.consumerKey,t.consumerKey,this.api.version=t.version||this.api.version,this.api.catalog=t.catalog||this.api.catalog;var n=t.player||"player-frame";if(n&&"string"==typeof n){var r=this,e=o("#"+n);if(!0===t.isHTML5Compatible){if(!function(){if(navigator.cookieEnabled){try{if("undefined"==typeof localStorage)return}catch(e){return}return 1}}())throw new Error("Cookies or localStorage is not enabled. Napster.js will not work properly without it.");r.player=new Html5Player,o("<video-js id='napster-streaming-player' class='video-js' playsinline></video-js>").appendTo(o(document.body)),o("#napster-streaming-player").css("display","none"),o.ajax({url:"https://app.napster.com/sdk/streaming-player-1.0.1.js",dataType:"script",async:!0,success:function(){c.player.fire("ready")}})}else if(r.player=new FlashPlayer,0===e.length)o(function(){var e=o("<iframe></iframe>").attr("id",n).attr("name",n).attr("src","http://api.napster.com/v1.1/player/index.html?apikey="+t.consumerKey).attr("frameborder","no").attr("style","display:none;").appendTo(o(document.body)).load(function(){r.player.win=e.get(0)})});else{if(!(e.get(0)instanceof HTMLIFrameElement))throw new Error('The element "'+n+'" is not an HTMLIFrameElement.');r.player.win=e.get(0)}}}};c.api={host:"api.napster.com",catalog:"US",version:"v2.2",endpoint:function(e){return(e?"https://":"http://")+[this.host,this.version].join("/")},headers:function(e){var t={};return e&&c.member.accessToken&&(t.Authorization="Bearer "+c.member.accessToken),t},dataType:function(){return"json"},get:function(e,t,r){var n={apikey:this.consumerKey};o.ajax({type:"GET",dataType:this.dataType(),data:n,headers:this.headers(e),url:this.endpoint(e)+t,success:function(e,t,n){r(e)},error:function(e){r({status:e.status,error:e.statusText,response:e.responseJSON})}})},post:function(e,t,n,r){n=n||{},o.ajax({type:n._method||"POST",data:n,dataType:this.dataType(),headers:this.headers(e),url:this.endpoint(e)+t+(e?"":"?apikey="+this.consumerKey),success:function(e,t,n){r(e)},error:function(e){r({status:e.status,error:e.statusText,response:e.responseJSON})}})},put:function(e,t,n,r){n._method="PUT",this.post.call(this,e,t,n,r)},del:function(e,t,n,r){n._method="DELETE",this.post.call(this,e,t,n,r)}},c.member=new function(){var e={};try{e=new i({accessToken:t.localStorage[a],refreshToken:t.localStorage[s]})}catch(e){throw new Error("Cookies or localStorage is not enabled. Napster.js will not work properly without it.")}return e},c.previewer={play:function(){return this},pause:function(){return this}},c.windows=function(n){return{post:function(e,t){if(!n)throw new Error("An iframe was not found at that reference.");n.contentWindow.postMessage({method:e,args:c.util.jsonClean(t||{})},"*")}}},c.on=function(e,t){window.addEventListener(e,t)},c.util={secondsToTime:function(e){if(isNaN(e))return"0:00";var t=Math.floor(e/60),n=Math.floor(e)%60;return t+":"+(n<10?"0"+n:n)},jsonClean:function(e){return n.parse(n.stringify(e,function(e,t){return"genre"===e?{id:t.id,name:t.name}:t}))}},e(i.prototype,"set",function(e){e&&e.accessToken&&e.refreshToken&&(this.accessToken=t.localStorage[a]=e.accessToken,this.refreshToken=t.localStorage[s]=e.refreshToken,c.player.auth(e.accessToken))}),e(i.prototype,"unset",function(){this.accessToken=this.refreshToken=null,t.localStorage.removeItem(a),t.localStorage.removeItem(s)}),e(i.prototype,"load",function(){return this.accessToken=t.localStorage[a],this.refreshToken=t.localStorage[s],this}),e(i.prototype,"signedIn",function(){return null!=this.accessToken&&null!=this.refreshToken}),t.Napster=c,t.Member=i}}(window,jQuery,JSON);