vd-plugins/multi-scrobbler/index.js

2 lines
50 KiB
JavaScript
Raw Normal View History

(function(Y,p,r,F,Dt,_,ne,I,w,J,rt,ae){"use strict";const h={DEFAULT_APP_NAME:"Music",DEFAULT_TIME_INTERVAL:5,APPLICATION_ID:"1368513179272871956",MIN_UPDATE_INTERVAL:3,MAX_RETRY_ATTEMPTS:3,RETRY_DELAY:5e3,SERVICES:{lastfm:{name:"Last.fm",baseUrl:"https://ws.audioscrobbler.com/2.0",requiresApiKey:!0,requiresToken:!1},librefm:{name:"Libre.fm",baseUrl:"https://libre.fm/api",requiresApiKey:!0,requiresToken:!1},listenbrainz:{name:"ListenBrainz",baseUrl:"https://api.listenbrainz.org/1",requiresApiKey:!1,requiresToken:!0}},DEFAULT_HEADERS:{},DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f"],DEFAULT_SETTINGS:{username:"",apiKey:"",appName:"Music",timeInterval:5,showTimestamp:!0,listeningTo:!0,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 O(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function ve(e,t){for(var n=0;n<t.length;n++){var a=t[n];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function K(e,t,n){return t&&ve(e.prototype,t),n&&ve(e,n),e}const{SET_ACTIVITY:_t}=F.findByProps("SET_ACTIVITY"),nt=F.findByProps("getAssetIds"),at=F.findByStoreName("SelfPresenceStore"),we=F.findByStoreName("UserStore"),Re=function(...e){return console.log("[Activity]",...e)},it=function(...e){return console.error("[Activity] Error:",...e)},W=function(...e){try{console.log("[Activity] Verbose:",...e)}catch{console.log("[Activity] Verbose:",...e)}};function ie(){return Re("Clearing Discord activity"),Ee(null)}function Ee(e){T.pluginStopped&&(W("Plugin is stopped, clearing activity"),fe(),e=null),T.lastActivity=e,W("Dispatching activity update:",e?"Setting activity":"Clearing activity"),r.FluxDispatcher.dispatch({type:"LOCAL_ACTIVITY_UPDATE",activity:e,pid:2312,socketId:"Multi-Service-Scrobbler@Vendetta"}),Re(e?`Activity set: ${e.details} - ${e.state}`:"Activity cleared")}async function st(e,t=h.APPLICATION_ID){if(!e?.length)return W("No assets to fetch"),[];try{W(`Fetching ${e.length} asset(s):`,e);const n=await nt.fetchAssetIds(t,e);return W(`Successfully fetched ${n.length} asset(s)`),n}catch(n){return it("Failed to fetch assets:",n),[]}}const R={};R.componentMountErrors=[],R.componentMountCount=0,R.settingsLoadAttempts=0,R.serviceErrors={lastfm:[],librefm:[],listenbrainz:[]},R.apiCallCount=0,R.connectionAttempts=0,R.lastCredentialValidation={lastfm:!1,librefm:!1,listenbrainz:!1};const Z=function(...e){return console.log("[Debug]",...e)},Se=function(...e){return console.error("[Debug] Error:",...e)};function se(e,t){R[e]=t,e==="lastError"&&t?Se("Error recorded:",t.message):e==="lastTrack"&&t?Z("Track updated:",`${t.artist} - ${t.name}`):e==="currentService"&&t&&Z("Service changed to:",t)}function Te(){R.apiCallCount=(R.apiCallCount||0)+1,Z(`API call count: ${R.apiCallCount}`)}function ee(e,t){R.serviceErrors=R.serviceErrors||{lastfm:[],librefm:[],listenbrainz:[]},R.serviceErrors[e]=R.serviceErrors[e]||[],R.serviceErrors[e].push(`${new Date().toISOString()}: ${t}`),R.serviceErrors[e].length>10&&(R.serviceErrors[e]=R.serviceErrors[e].slice(-10)),Se(`${e} error:`,t)}function Ie(){R.lastSuccessfulUpdate=new Date().toISOString(),Z("Successful update recorded at:",R.lastSuccessfulUpdate)}function te(e){return te=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},te(e)}function ke(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(ke=function(){return!!e})()}function ot(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function lt(e){"@swc/helpers - typeof";return