vd-plugins/multi-scrobbler/index.js

2 lines
53 KiB
JavaScript
Raw Normal View History

(function(q,g,n,M,Nt,D,re,I,S,J,Qe,ne){"use strict";const d={DEFAULT_APP_NAME:"Music",DEFAULT_TIME_INTERVAL:5,APPLICATION_ID:"1054951789318909972",MIN_UPDATE_INTERVAL:3,LIBREFM_MIN_UPDATE_INTERVAL:60,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/2.0",requiresApiKey:!0,requiresToken:!1},listenbrainz:{name:"ListenBrainz",baseUrl:"https://api.listenbrainz.org/1",requiresApiKey:!0,requiresToken:!0}},DEFAULT_HEADERS:{},DEFAULT_COVER_HASHES:["2a96cbd8b46e442fc41c2b86b821562f"],DEFAULT_SETTINGS:{username:"",apiKey:"",appName:"Music",timeInterval:5,showTimestamp:!0,listeningTo:!0,showLargeText:!0,ignoreYouTubeMusic:!1,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 B(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function pe(e,r){for(var t=0;t<r.length;t++){var a=r[t];a.enumerable=a.enumerable||!1,a.configurable=!0,"value"in a&&(a.writable=!0),Object.defineProperty(e,a.key,a)}}function O(e,r,t){return r&&pe(e.prototype,r),t&&pe(e,t),e}const{SET_ACTIVITY:$t}=M.findByProps("SET_ACTIVITY"),Ze=M.findByProps("getAssetIds"),be=M.findByProps("getAPIBaseURL","get"),et=M.findByStoreName("SelfPresenceStore"),he=M.findByStoreName("UserStore");function ae(){return ye(null)}function ye(e){E.pluginStopped&&(ue(),e=null),E.lastActivity=e,n.FluxDispatcher.dispatch({type:"LOCAL_ACTIVITY_UPDATE",activity:e,pid:2312,socketId:"Multi-Scrobbler@Vendetta"})}async function tt(e,r){const t=`${be.getAPIBaseURL()}/applications/${r}/external-assets`,a=await be.post({url:t,body:{urls:e},oldFormErrors:!0,rejectWithError:!1});console.log("[Multi-Scrobbler] External assets response:",JSON.stringify(a));const i=a?.body;return console.log("[Multi-Scrobbler] Response body:",JSON.stringify(i)),Array.isArray(i)?i.map(function(s){return`mp:${s.external_asset_path}`}):[]}async function rt(e,r=d.APPLICATION_ID){if(!e?.length)return[];try{const t=await Ze.fetchAssetIds(r,e);if(Array.isArray(t)&&t.length>0&&t[0])return t;const a=e.filter(function(i){return i&&(i.startsWith("http:")||i.startsWith("https:"))});return a.length===0?[]:await tt(a,r)}catch(t){return console.error("[Multi-Scrobbler] Failed to fetch assets:",t),[]}}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 Q=function(...e){return console.log("[Debug]",...e)},me=function(...e){return console.error("[Debug] Error:",...e)};function j(e,r){R[e]=r,e==="lastError"&&r?me("Error recorded:",r.message):e==="lastTrack"&&r?Q("Track updated:",`${r.artist} - ${r.name}`):e==="currentService"&&r&&Q("Service changed to:",r)}function we(){R.apiCallCount=(R.apiCallCount||0)+1,Q(`API call count: ${R.apiCallCount}`)}function Z(e,r){R.serviceErrors=R.serviceErrors||{lastfm:[],librefm:[],listenbrainz:[]},R.serviceErrors[e]=R.serviceErrors[e]||[],R.serviceErrors[e].push(`${new Date().toISOString()}: ${r}`),R.serviceErrors[e].length>10&&(R.serviceErrors[e]=R.serviceErrors[e].slice(-10)),me(`${e} error:`,r)}function ve(){R.lastSuccessfulUpdate=new Date().toISOString(),Q("Successful update recorded at:",R.lastSuccessfulUpdate)}function ee(e){return ee=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},ee(e)}function Se(){try{var e=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){}))}catch{}return(Se=function(){return!!e})()}function nt