vd-plugins/multi-scrobbler/index.js

2 lines
39 KiB
JavaScript
Raw Normal View History

(function(x,f,r,_,yt,M,Q,E,S,Z,xe,ee){"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,ignoreYouTubeMusic:!0,ignoreKizzy:!0,ignoreMetrolist:!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 fe(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&&fe(e.prototype,t),n&&fe(e,n),e}const{SET_ACTIVITY:ht}=_.findByProps("SET_ACTIVITY"),Ge=_.findByProps("getAssetIds"),q=_.findByStoreName("SelfPresenceStore"),de=_.findByStoreName("UserStore"),pe=function(...e){return console.log("[Activity]",...e)},Ye=function(...e){return console.error("[Activity] Error:",...e)},G=function(...e){try{console.log("[Activity] Verbose:",...e)}catch{console.log("[Activity] Verbose:",...e)}};function O(){return pe("Clearing Discord activity"),be(null)}function be(e){h.pluginStopped&&(G("Plugin is stopped, clearing activity"),se(),e=null),h.lastActivity=e,G("Dispatching activity update:",e?"Setting activity":"Clearing activity"),r.FluxDispatcher.dispatch({type:"LOCAL_ACTIVITY_UPDATE",activity:e,pid:2312,socketId:"Multi-Service-Scrobbler@Vendetta"}),pe(e?`Activity set: ${e.details} - ${e.state}`:"Activity cleared")}async function qe(e,t=l.APPLICATION_ID){if(!e?.length)return G("No assets to fetch"),[];try{G(`Fetching ${e.length} asset(s):`,e);const n=await Ge.fetchAssetIds(t,e);return G(`Successfully fetched ${n.length} asset(s)`),n}catch(n){return Ye("Failed to fetch assets:",n),[]}}const b={};b.componentMountErrors=[],b.componentMountCount=0,b.settingsLoadAttempts=0,b.serviceErrors={lastfm:[],librefm:[],listenbrainz:[]},b.apiCallCount=0,b.connectionAttempts=0,b.lastCredentialValidation={lastfm:!1,librefm:!1,listenbrainz:!1};const j=function(...e){return console.log("[Debug]",...e)},ye=function(...e){return console.error("[Debug] Error:",...e)};function P(e,t){b[e]=t,e==="lastError"&&t?ye("Error recorded:",t.message):e==="lastTrack"&&t?j("Track updated:",`${t.artist} - ${t.name}`):e==="currentService"&&t&&j("Service changed to:",t)}function he(){b.apiCallCount=(b.apiCallCount||0)+1,j(`API call count: ${b.apiCallCount}`)}function X(e,t){b.serviceErrors=b.serviceErrors||{lastfm:[],librefm:[],listenbrainz:[]},b.serviceErrors[e]=b.serviceErrors[e]||[],b.serviceErrors[e].push(`${new Date().toISOString()}: ${t}`),b.serviceErrors[e].length>10&&(b.serviceErrors[e]=b.serviceErrors[e].slice(-10)),ye(`${e} error:`,t)}function ve(){b.lastSuccessfulUpdate=new Date().toISOString(),j("Successful update recorded at:",b.lastSuccessfulUpdate)}function H(e){return H=Object.setPrototypeOf?Object.getPrototypeOf:function(n){return n.__proto__||Object.getPrototypeOf(n)},H(e)}function me(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(me=function(){return!!e})()}function je(e){if(e===void 0)throw new ReferenceError("this hasn't been in