vd-plugins/multi-scrobbler/index.js

2 lines
54 KiB
JavaScript
Raw Normal View History

(function(H,p,n,V,Ft,z,se,I,R,te,nt,oe){"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 K(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function we(e,t){for(var r=0;r<t.length;r++){var a=t[r];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function G(e,t,r){return t&&we(e.prototype,t),r&&we(e,r),e}const{SET_ACTIVITY:xt}=V.findByProps("SET_ACTIVITY"),at=V.findByProps("getAssetIds"),it=V.findByStoreName("SelfPresenceStore"),Re=V.findByStoreName("UserStore"),Ee=function(...e){return console.log("[Activity]",...e)},st=function(...e){return console.error("[Activity] Error:",...e)},X=function(...e){try{console.log("[Activity] Verbose:",...e)}catch{console.log("[Activity] Verbose:",...e)}};function le(){return Ee("Clearing Discord activity"),Se(null)}function Se(e){S.pluginStopped&&(X("Plugin is stopped, clearing activity"),pe(),e=null),S.lastActivity=e,X("Dispatching activity update:",e?"Setting activity":"Clearing activity"),n.FluxDispatcher.dispatch({type:"LOCAL_ACTIVITY_UPDATE",activity:e,pid:2312,socketId:"Multi-Service-Scrobbler@Vendetta"}),Ee(e?`Activity set: ${e.details} - ${e.state}`:"Activity cleared")}async function ot(e,t=h.APPLICATION_ID){if(!e?.length)return X("No assets to fetch"),[];try{X(`Fetching ${e.length} asset(s):`,e);const r=await at.fetchAssetIds(t,e);return X(`Successfully fetched ${r.length} asset(s)`),r}catch(r){return st("Failed to fetch assets:",r),[]}}const E={};E.componentMountErrors=[],E.componentMountCount=0,E.settingsLoadAttempts=0,E.serviceErrors={lastfm:[],librefm:[],listenbrainz:[]},E.apiCallCount=0,E.connectionAttempts=0,E.lastCredentialValidation={lastfm:!1,librefm:!1,listenbrainz:!1};const re=function(...e){return console.log("[Debug]",...e)},Te=function(...e){return console.error("[Debug] Error:",...e)};function Y(e,t){E[e]=t,e==="lastError"&&t?Te("Error recorded:",t.message):e==="lastTrack"&&t?re("Track updated:",`${t.artist} - ${t.name}`):e==="currentService"&&t&&re("Service changed to:",t)}function Ie(){E.apiCallCount=(E.apiCallCount||0)+1,re(`API call count: ${E.apiCallCount}`)}function ne(e,t){E.serviceErrors=E.serviceErrors||{lastfm:[],librefm:[],listenbrainz:[]},E.serviceErrors[e]=E.serviceErrors[e]||[],E.serviceErrors[e].push(`${new Date().toISOString()}: ${t}`),E.serviceErrors[e].length>10&&(E.serviceErrors[e]=E.serviceErrors[e].slice(-10)),Te(`${e} error:`,t)}function ke(){E.lastSuccessfulUpdate=new Date().toISOString(),re("Successful update recorded at:",E.lastSuccessfulUpdate)}function ae(e){return ae=Object.setPrototypeOf?Object.getPrototypeOf:function(r){return r.__proto__||Object.getPrototypeOf(r)},ae(e)}function Ae(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Ae=function(){return!!e})()}function lt(e){if(e===void 0)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function ct(e){"@swc/helpers - typeof";re