vd-plugins/multi-scrobbler/index.js

2 lines
38 KiB
JavaScript
Raw Normal View History

(function(B,f,r,$,ht,D,W,S,m,J,xe,Q){"use strict";const l={DEFAULT_APP_NAME:"Music",DEFAULT_TIME_INTERVAL:5,APPLICATION_ID:"1054951789318909972",MIN_UPDATE_INTERVAL:3,MAX_RETRY_ATTEMPTS:3,RETRY_DELAY:5e3,SERVICES:{lastfm:{name:"Last.fm",baseUrl:"http://ws.audioscrobbler.com/2.0",requiresApiKey:!0,requiresToken:!1},librefm:{name:"Libre.fm",baseUrl:"http://libre.fm/api",requiresApiKey:!0,requiresToken:!1},listenbrainz:{name:"ListenBrainz",baseUrl:"http://api.listenbrainz.org/1",requiresApiKey:!1,requiresToken:!0}},DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f","c6f59c1e5e7240a4c0d427abd71f3dbb"],DEFAULT_SETTINGS:{username:"",apiKey:"",appName:"Music",timeInterval:5,showTimestamp:!0,listeningTo:!0,ignoreSpotify:!0,verboseLogging:!1,service:void 0,librefmUsername:"",librefmApiKey:"",listenbrainzUsername:"",listenbrainzToken:""},API_ERROR_CODES:{2:"Invalid service",3:"Invalid method",4:"Invalid format",5:"Invalid parameters",6:"Invalid resource specified",7:"Invalid session key",8:"Invalid API key",9:"Invalid session",10:"Invalid API signature",11:"Service offline",13:"Invalid method signature supplied",16:"Service temporarily unavailable",26:"Suspended API key",29:"Rate limit exceeded"}};function V(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ge(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function F(e,t,n){return t&&ge(e.prototype,t),n&&ge(e,n),e}const{SET_ACTIVITY:yt}=$.findByProps("SET_ACTIVITY"),Ge=$.findByProps("getAssetIds"),Ke=$.findByStoreName("SelfPresenceStore"),fe=$.findByStoreName("UserStore"),de=function(...e){return console.log("[Activity]",...e)},qe=function(...e){return console.error("[Activity] Error:",...e)},x=function(...e){try{console.log("[Activity] Verbose:",...e)}catch{console.log("[Activity] Verbose:",...e)}};function Z(){return de("Clearing Discord activity"),pe(null)}function pe(e){h.pluginStopped&&(x("Plugin is stopped, clearing activity"),ae(),e=null),h.lastActivity=e,x("Dispatching activity update:",e?"Setting activity":"Clearing activity"),r.FluxDispatcher.dispatch({type:"LOCAL_ACTIVITY_UPDATE",activity:e,pid:2312,socketId:"Multi-Service-Scrobbler@Vendetta"}),de(e?`Activity set: ${e.details} - ${e.state}`:"Activity cleared")}async function je(e,t=l.APPLICATION_ID){if(!e?.length)return x("No assets to fetch"),[];try{x(`Fetching ${e.length} asset(s):`,e);const n=await Ge.fetchAssetIds(t,e);return x(`Successfully fetched ${n.length} asset(s)`),n}catch(n){return qe("Failed to fetch assets:",n),[]}}const p={};p.componentMountErrors=[],p.componentMountCount=0,p.settingsLoadAttempts=0,p.serviceErrors={lastfm:[],librefm:[],listenbrainz:[]},p.apiCallCount=0,p.connectionAttempts=0,p.lastCredentialValidation={lastfm:!1,librefm:!1,listenbrainz:!1};const q=function(...e){return console.log("[Debug]",...e)},be=function(...e){return console.error("[Debug] Error:",...e)};function G(e,t){p[e]=t,e==="lastError"&&t?be("Error recorded:",t.message):e==="lastTrack"&&t?q("Track updated:",`${t.artist} - ${t.name}`):e==="currentService"&&t&&q("Service changed to:",t)}function he(){p.apiCallCount=(p.apiCallCount||0)+1,q(`API call count: ${p.apiCallCount}`)}function j(e,t){p.serviceErrors=p.serviceErrors||{lastfm:[],librefm:[],listenbrainz:[]},p.serviceErrors[e]=p.serviceErrors[e]||[],p.serviceErrors[e].push(`${new Date().toISOString()}: ${t}`),p.serviceErrors[e].length>10&&(p.serviceErrors[e]=p.serviceErrors[e].slice(-10)),be(`${e} error:`,t)}function ye(){p.lastSuccessfulUpdate=new Date().toISOString(),q("Successful update recorded at:",p.lastSuccessfulUpdate)}function Y(e){return Y=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},Y(e)}function ve(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(ve=function(){return!!e})()}function Ye(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}functi