mirror of
https://github.com/Vendicated/Vencord.git
synced 2025-01-11 02:16:23 +00:00
show client info in small image
This commit is contained in:
parent
b4af3e847b
commit
8168ec3f7e
1 changed files with 37 additions and 7 deletions
|
@ -65,6 +65,7 @@ interface TrackData {
|
||||||
end: number;
|
end: number;
|
||||||
};
|
};
|
||||||
client?: string;
|
client?: string;
|
||||||
|
clientDetails: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// only relevant enum values
|
// only relevant enum values
|
||||||
|
@ -94,8 +95,9 @@ const logger = new Logger("LastFMRichPresence");
|
||||||
|
|
||||||
const presenceStore = findByPropsLazy("getLocalPresence");
|
const presenceStore = findByPropsLazy("getLocalPresence");
|
||||||
|
|
||||||
async function getApplicationAsset(key: string): Promise<string> {
|
async function getApplicationAsset(key: string): Promise<string | undefined> {
|
||||||
return (await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]))[0];
|
const ids = await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]);
|
||||||
|
return ids.length > 0 ? ids[0] : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setActivity(activity: Activity | null) {
|
function setActivity(activity: Activity | null) {
|
||||||
|
@ -200,7 +202,7 @@ const settings = definePluginSettings({
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
showLastFmLogo: {
|
showLastFmLogo: {
|
||||||
description: "show the Last.fm logo by the album cover",
|
description: "show the Last.fm/ListenBrainz/streaming service/music player logo by the album cover",
|
||||||
type: OptionType.BOOLEAN,
|
type: OptionType.BOOLEAN,
|
||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
|
@ -281,7 +283,8 @@ export default definePlugin({
|
||||||
album: trackData.album["#text"],
|
album: trackData.album["#text"],
|
||||||
artist: trackData.artist["#text"] || "Unknown",
|
artist: trackData.artist["#text"] || "Unknown",
|
||||||
url: trackData.url,
|
url: trackData.url,
|
||||||
imageUrl: trackData.image?.find((x: any) => x.size === "large")?.["#text"]
|
imageUrl: trackData.image?.find((x: any) => x.size === "large")?.["#text"],
|
||||||
|
clientDetails: "Last.fm"
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("Failed to query Last.fm API", e);
|
logger.error("Failed to query Last.fm API", e);
|
||||||
|
@ -326,6 +329,29 @@ export default definePlugin({
|
||||||
releaseMbid = releaseMbid || metadata.release_mbid;
|
releaseMbid = releaseMbid || metadata.release_mbid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let clientDetails = "ListenBrainz";
|
||||||
|
if (trackAddInfo) {
|
||||||
|
const musicService = trackAddInfo.music_service_name || trackAddInfo.music_service;
|
||||||
|
|
||||||
|
let mediaPlayer = trackAddInfo.media_player;
|
||||||
|
if (mediaPlayer && trackAddInfo.media_player_version)
|
||||||
|
mediaPlayer = `${mediaPlayer} ${trackAddInfo.media_player_version}`;
|
||||||
|
|
||||||
|
let submissionClient = trackAddInfo.submission_client;
|
||||||
|
if (submissionClient && trackAddInfo.submission_client_version)
|
||||||
|
submissionClient = `${submissionClient} ${trackAddInfo.submission_client_version}`;
|
||||||
|
|
||||||
|
if (submissionClient && trackAddInfo.submission_client !== trackAddInfo.media_player)
|
||||||
|
clientDetails = `${clientDetails} via ${submissionClient}`;
|
||||||
|
|
||||||
|
if (musicService && mediaPlayer)
|
||||||
|
clientDetails = `${musicService} through ${mediaPlayer} to ${clientDetails}`;
|
||||||
|
else if (musicService)
|
||||||
|
clientDetails = `${musicService} to ${clientDetails}`;
|
||||||
|
else if (mediaPlayer)
|
||||||
|
clientDetails = `${mediaPlayer} to ${clientDetails}`;
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name: trackMeta.track_name || "Unknown",
|
name: trackMeta.track_name || "Unknown",
|
||||||
album: trackMeta.release_name || "Unknown",
|
album: trackMeta.release_name || "Unknown",
|
||||||
|
@ -333,7 +359,8 @@ export default definePlugin({
|
||||||
url: trackAddInfo?.origin_url || recordingMbid && `https://musicbrainz.org/recording/${recordingMbid}`,
|
url: trackAddInfo?.origin_url || recordingMbid && `https://musicbrainz.org/recording/${recordingMbid}`,
|
||||||
imageUrl: releaseMbid && `https://coverartarchive.org/release/${releaseMbid}/front`,
|
imageUrl: releaseMbid && `https://coverartarchive.org/release/${releaseMbid}/front`,
|
||||||
timestamps: settings.store.sendTimestamps ? await this.getListenBrainzTimestamps(trackData) : undefined,
|
timestamps: settings.store.sendTimestamps ? await this.getListenBrainzTimestamps(trackData) : undefined,
|
||||||
client: trackAddInfo?.music_service_name || trackAddInfo?.music_service || trackAddInfo?.media_player
|
client: trackAddInfo?.music_service_name || trackAddInfo?.music_service || trackAddInfo?.media_player,
|
||||||
|
clientDetails
|
||||||
};
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
logger.error("Failed to query ListenBrainz API", e);
|
logger.error("Failed to query ListenBrainz API", e);
|
||||||
|
@ -466,8 +493,11 @@ export default definePlugin({
|
||||||
large_image: await getApplicationAsset(largeImage),
|
large_image: await getApplicationAsset(largeImage),
|
||||||
large_text: trackData.album || undefined,
|
large_text: trackData.album || undefined,
|
||||||
...(settings.store.showLastFmLogo && {
|
...(settings.store.showLastFmLogo && {
|
||||||
small_image: await getApplicationAsset("lastfm-small"),
|
small_image: trackData.client && (
|
||||||
small_text: "Last.fm"
|
await getApplicationAsset(`client-${trackData.client}-small`) ||
|
||||||
|
trackData.url && await getApplicationAsset(encodeURI(`https://s2.googleusercontent.com/s2/favicons?domain=${trackData.url}`))
|
||||||
|
) || await getApplicationAsset("lastfm-small"),
|
||||||
|
small_text: trackData.clientDetails
|
||||||
}),
|
}),
|
||||||
} : {
|
} : {
|
||||||
large_image: await getApplicationAsset("lastfm-large"),
|
large_image: await getApplicationAsset("lastfm-large"),
|
||||||
|
|
Loading…
Reference in a new issue