fix: showing album images in Rich Presence
atleast try, lol.
This commit is contained in:
parent
fc5eb71659
commit
7951d0083a
4 changed files with 51 additions and 9 deletions
|
|
@ -4,7 +4,7 @@ const Constants = {
|
|||
DEFAULT_APP_NAME: "Music",
|
||||
DEFAULT_TIME_INTERVAL: 5,
|
||||
// Discord application ID
|
||||
APPLICATION_ID: "1368513179272871956",
|
||||
APPLICATION_ID: "1054951789318909972",
|
||||
// Don't check more than once every 3 seconds to avoid getting rate limited
|
||||
MIN_UPDATE_INTERVAL: 3,
|
||||
// Libre.fm specifically requested a 1-minute minimum to reduce load
|
||||
|
|
|
|||
|
|
@ -66,9 +66,6 @@ class PluginManager {
|
|||
const serviceName = serviceFactory.getCurrentService().getServiceName();
|
||||
logVerbose(`Fetching latest track from ${serviceName}...`);
|
||||
|
||||
// keep track of whether we actually need to update Discord
|
||||
let willUpdateRPC = false;
|
||||
|
||||
try {
|
||||
// Check if any ignored app is active
|
||||
if (currentSettings.ignoreList && currentSettings.ignoreList.length > 0) {
|
||||
|
|
@ -122,8 +119,6 @@ class PluginManager {
|
|||
return;
|
||||
}
|
||||
|
||||
willUpdateRPC = true;
|
||||
|
||||
log(`🎵 Track changed: ${lastTrack.artist} - ${lastTrack.name}`);
|
||||
|
||||
// set up timestamps for the track
|
||||
|
|
|
|||
|
|
@ -10,6 +10,14 @@ export const AssetManager = findByProps("getAssetIds") as {
|
|||
[key: PropertyKey]: any;
|
||||
};
|
||||
|
||||
// Discord's internal HTTP client — automatically includes auth token
|
||||
export const HTTPUtils = findByProps("getAPIBaseURL", "get") as {
|
||||
get: (opts: { url: string; query?: string; rejectWithError?: boolean; oldFormErrors?: boolean }) => Promise<any>;
|
||||
post: (opts: { url: string; body?: any; rejectWithError?: boolean; oldFormErrors?: boolean }) => Promise<any>;
|
||||
getAPIBaseURL: () => string;
|
||||
[key: PropertyKey]: any;
|
||||
};
|
||||
|
||||
export const SelfPresenceStore = findByStoreName("SelfPresenceStore") as {
|
||||
getActivities: () => any[];
|
||||
findActivity: (filter: (activity) => boolean) => any;
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { pluginState } from "..";
|
|||
import { Activity } from "../../../defs";
|
||||
import Constants from "../constants";
|
||||
import { stop } from "../manager";
|
||||
import { AssetManager } from "../modules";
|
||||
import { AssetManager, HTTPUtils } from "../modules";
|
||||
|
||||
/** Clears the user's activity */
|
||||
export function clearActivity() {
|
||||
|
|
@ -28,7 +28,33 @@ export function sendRequest(activity: Activity | null) {
|
|||
});
|
||||
}
|
||||
|
||||
/** Fetches Discord application assets */
|
||||
async function resolveExternalAssets(
|
||||
urls: string[],
|
||||
appId: string,
|
||||
): Promise<string[]> {
|
||||
const baseUrl = HTTPUtils.getAPIBaseURL();
|
||||
const endpoint = `${baseUrl}/applications/${appId}/external-assets`;
|
||||
|
||||
const resp = await HTTPUtils.post({
|
||||
url: endpoint,
|
||||
body: { urls },
|
||||
oldFormErrors: true,
|
||||
rejectWithError: false,
|
||||
});
|
||||
|
||||
console.log("[Multi-Scrobbler] External assets response:", JSON.stringify(resp));
|
||||
const body = resp?.body;
|
||||
console.log("[Multi-Scrobbler] Response body:", JSON.stringify(body));
|
||||
|
||||
if (!Array.isArray(body)) return [];
|
||||
|
||||
return body.map(
|
||||
(item: { url: string; external_asset_path: string }) =>
|
||||
`mp:${item.external_asset_path}`,
|
||||
);
|
||||
}
|
||||
|
||||
/** Resolves external image URLs to Discord asset paths */
|
||||
export async function fetchAsset(
|
||||
asset: string[],
|
||||
appId: string = Constants.APPLICATION_ID,
|
||||
|
|
@ -36,7 +62,20 @@ export async function fetchAsset(
|
|||
if (!asset?.length) return [];
|
||||
|
||||
try {
|
||||
return await AssetManager.fetchAssetIds(appId, asset);
|
||||
const result = await AssetManager.fetchAssetIds(appId, asset);
|
||||
|
||||
// If it returned an actual array with results, use it
|
||||
if (Array.isArray(result) && result.length > 0 && result[0]) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// fetchAssetIds returned empty/broken — try external-assets API
|
||||
const externalUrls = asset.filter(
|
||||
(url) => url && (url.startsWith("http:") || url.startsWith("https:")),
|
||||
);
|
||||
if (externalUrls.length === 0) return [];
|
||||
|
||||
return await resolveExternalAssets(externalUrls, appId);
|
||||
} catch (error) {
|
||||
console.error("[Multi-Scrobbler] Failed to fetch assets:", error);
|
||||
return [];
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue