From 507edbbe5b3b430d9573cb91d6e17ad191be8531 Mon Sep 17 00:00:00 2001 From: Cortex <126973723+verysillycat@users.noreply.github.com> Date: Sun, 6 Apr 2025 17:31:37 -0600 Subject: [PATCH] git(revert): "Completed Merge StatsFM> LastFM + Streaming status added. (#201)" by crxa's order --- src/plugins/lastfm/index.tsx | 206 ++++------------------------------- 1 file changed, 19 insertions(+), 187 deletions(-) diff --git a/src/plugins/lastfm/index.tsx b/src/plugins/lastfm/index.tsx index c9ac96d1..75d9c7c3 100644 --- a/src/plugins/lastfm/index.tsx +++ b/src/plugins/lastfm/index.tsx @@ -19,7 +19,7 @@ import { definePluginSettings } from "@api/Settings"; import { getUserSettingLazy } from "@api/UserSettings"; import { Link } from "@components/Link"; -import { Devs, EquicordDevs } from "@utils/constants"; +import { Devs } from "@utils/constants"; import { Logger } from "@utils/Logger"; import definePlugin, { OptionType } from "@utils/types"; import { findByPropsLazy } from "@webpack"; @@ -44,12 +44,10 @@ interface Activity { timestamps?: { start?: number; }; - assets?: ActivityAssets; // LastFM - assets2?: ActivityAssets; // StatsFM + assets?: ActivityAssets; buttons?: Array; name: string; - application_id: string; // LastFM - application_id2: string; // StatsFM + application_id: string; metadata?: { button_urls?: Array; }; @@ -69,91 +67,39 @@ interface TrackData { const enum ActivityType { PLAYING = 0, LISTENING = 2, - STREAMING = 1, // Added Streaming ig as a alt to listening } const enum ActivityFlag { INSTANCE = 1 << 0, } -const enum NameFormat { // (2) = Statsfm config +const enum NameFormat { StatusName = "status-name", ArtistFirst = "artist-first", SongFirst = "song-first", ArtistOnly = "artist", SongOnly = "song", - AlbumName = "album", - AlbumName2 = "album2", // ^ - ArtistOnly2 = "artist2", // ^ - ArtistFirst2 = "ArtistFirst2", // ^ - SongFirst2 = "SongFirst2", // ^ - SongOnly2 = "SongOnly2", // ^ -} - -interface Albums { - id: number; - name: string; - image: string; -} - -interface Artists { - id: number; - name: string; - image: string; -} -interface ExternalIds { - spotify: string[]; - appleMusic: string[]; -} - - -interface Track { - albums: Albums[]; - artists: Artists[]; - durationMs: number; - explicit: boolean; - externalIds: ExternalIds; - id: number; - name: string; - spotifyPopularity: number; - spotifyPreview: string; - appleMusicPreview: string; -} - -interface Item { - date: string; - isPlaying: boolean; - progressMs: number; - deviceName: string; - track: Track; - platform: string; -} - -interface SFMR { - item: Item; + AlbumName = "album" } const ShowCurrentGame = getUserSettingLazy("status", "showCurrentGame")!; -const applicationId = "1108588077900898414"; // LastFM Appid -const applicationId2 = "1325126169179197500"; // StatsFM Appid +const applicationId = "1108588077900898414"; const placeholderId = "2a96cbd8b46e442fc41c2b86b821562f"; -const logger = new Logger("LastFMRichPresence + StatsfmFMRichPresence"); +const logger = new Logger("LastFMRichPresence"); const PresenceStore = findByPropsLazy("getLocalPresence"); async function getApplicationAsset(key: string): Promise { return (await ApplicationAssetUtils.fetchAssetIds(applicationId, [key]))[0]; } -async function getApplicationAsset2(key: string): Promise { - return (await ApplicationAssetUtils.fetchAssetIds(applicationId2, [key]))[0]; -} + function setActivity(activity: Activity | null) { FluxDispatcher.dispatch({ type: "LOCAL_ACTIVITY_UPDATE", activity, - socketId: "LastFM + Statsfm", + socketId: "LastFM", }); } @@ -162,10 +108,6 @@ const settings = definePluginSettings({ description: "last.fm username", type: OptionType.STRING, }, - statsfmusername: { - description: "stats.fm username", - type: OptionType.STRING, - }, apiKey: { description: "last.fm api key", type: OptionType.STRING, @@ -175,51 +117,26 @@ const settings = definePluginSettings({ type: OptionType.BOOLEAN, default: false, }, - shareUsernameStatsfm: { - description: "show link to stats.fm profile", - type: OptionType.BOOLEAN, - default: false, - }, shareSong: { description: "show link to song on last.fm", type: OptionType.BOOLEAN, default: true, }, - StatsfmSong: { - description: "show link to song on stats.fm", - type: OptionType.BOOLEAN, - default: true, - }, hideWithSpotify: { description: "hide last.fm presence if spotify is running", type: OptionType.BOOLEAN, default: true, }, - hidewithSpotifySFM: { - description: "hide stats.fm presence if spotify is running", - type: OptionType.BOOLEAN, - default: true, - }, hideWithActivity: { description: "Hide Last.fm presence if you have any other presence", type: OptionType.BOOLEAN, default: false, }, - hideStatsfmWithExternalRPC: { - description: "Hide Stats.fm presence if you have any other presence", - type: OptionType.BOOLEAN, - default: false, - }, enableGameActivity: { description: "Enable game activity for last.fm", type: OptionType.BOOLEAN, default: false, }, - enableGameActivitySFM: { - description: "Enable game activity for stats.fm", - type: OptionType.BOOLEAN, - default: false, - }, statusName: { description: "custom status text", type: OptionType.STRING, @@ -261,11 +178,6 @@ const settings = definePluginSettings({ type: OptionType.BOOLEAN, default: false, }, - useStreamingStatus: { - description: 'show "Streaming" status instead of "Playing"', - type: OptionType.BOOLEAN, - default: false, - }, missingArt: { description: "When album or album art is missing", type: OptionType.SELECT, @@ -275,11 +187,6 @@ const settings = definePluginSettings({ value: "lastfmLogo", default: true }, - { - label: "Use Large Stats.fm logo", - value: "StatsFMLogo", - default: false - }, { label: "Use generic placeholder", value: "placeholder" @@ -291,11 +198,6 @@ const settings = definePluginSettings({ type: OptionType.BOOLEAN, default: true, }, - showStatsFMLogo: { - description: "show the Stats.fm logo by the album cover", - type: OptionType.BOOLEAN, - default: false, - }, alwaysHideArt: { description: "Disable downloading album art", type: OptionType.BOOLEAN, @@ -305,8 +207,8 @@ const settings = definePluginSettings({ export default definePlugin({ name: "LastFMRichPresence", - description: "Little plugin for Last.fm rich presence + Stats.fm rich presence", - authors: [Devs.dzshn, Devs.RuiNtD, Devs.blahajZip, Devs.archeruwu, EquicordDevs.Crxa], + description: "Little plugin for Last.fm rich presence", + authors: [Devs.dzshn, Devs.RuiNtD, Devs.blahajZip, Devs.archeruwu], settingsAboutComponent: () => ( <> @@ -321,12 +223,6 @@ export default definePlugin({ And copy the API key (not the shared secret!) - - How to get Stats.fm Presence! - - STATSFM ONLY: - If you want to use stats.fm, you will need an account linked @ and have your listening history public. - ), @@ -340,7 +236,7 @@ export default definePlugin({ stop() { clearInterval(this.updateInterval); }, - // Last.fm Fetching + async fetchTrackData(): Promise { if (!settings.store.username || !settings.store.apiKey) return null; @@ -382,33 +278,6 @@ export default definePlugin({ return null; } }, - // Stats.fm Fetching - async fetchTrackDataStatsfm(): Promise { - if (!settings.store.statsfmusername) - return null; - try { - const res2 = await fetch(`https://api.stats.fm/api/v1/user/${settings.store.statsfmusername}/recent`); - if (!res2.ok) throw `${res2.status} ${res2.statusText}`; - - const json = await res2.json() as SFMR; - if (!json.item) { - logger.error("Error from Stats.fm API"), json; - return null; - } - const trackData2 = json.item.track; - if (!trackData2) return null; - return { - name: trackData2.name || "Unknown", - album: trackData2.albums.map(a => a.name).join(", ") || "Unknown", - artist: trackData2.artists[0].name ?? "Unknown", - url: `https://stats.fm/track/${trackData2.id}`, - imageUrl: trackData2.albums[0].image - }; - } catch (e) { - logger.error("Failed to query Stats.fm API, Report to Equicord Discord. https://discord.gg/equicord", e); - return null; - } - }, async updatePresence() { setActivity(await this.getActivity()); @@ -424,14 +293,13 @@ export default definePlugin({ async getActivity(): Promise { if (settings.store.hideWithActivity) { - if (PresenceStore.getActivities().some(a => a.application_id !== applicationId && (!a.application_id2 || a.application_id2 !== applicationId2))) + if (PresenceStore.getActivities().some(a => a.application_id !== applicationId)) { return null; - { } } if (settings.store.hideWithSpotify) { - if (PresenceStore.getActivities().some(a => (a.type === ActivityType.LISTENING || a.type === ActivityType.STREAMING) && a.application_id !== applicationId)) { + if (PresenceStore.getActivities().some(a => a.type === ActivityType.LISTENING && a.application_id !== applicationId)) { // there is already music status because of Spotify or richerCider (probably more) return null; } @@ -458,21 +326,7 @@ export default definePlugin({ large_image: await getApplicationAsset("lastfm-large"), large_text: trackData.album || undefined, }; - // Stats.fm image stuff - const largeImage2 = this.getLargeImage(trackData); - const assets2: ActivityAssets = largeImage2 ? - { - large_image: await getApplicationAsset2(largeImage2), - large_text: trackData.album || undefined, - ...(settings.store.showStatsFMLogo && { - small_image: await getApplicationAsset2("statsfm-large"), - small_text: "Stats.fm" - }), - } : { - large_image: await getApplicationAsset2("statsfm-large"), - large_text: trackData.album || undefined, - }; - const trackData2 = await this.fetchTrackDataStatsfm(); + const buttons: ActivityButton[] = []; if (settings.store.shareUsername) @@ -480,24 +334,14 @@ export default definePlugin({ label: "Last.fm Profile", url: `https://www.last.fm/user/${settings.store.username}`, }); - // Stats.fm settings - if (settings.store.shareUsernameStatsfm) - buttons.push({ - label: "Stats.fm Profile", - url: `https://stats.fm/user/${settings.store.statsfmusername}`, - }); - if (settings.store.StatsfmSong) - buttons.push({ - label: "View Song", - url: trackData.url, - }); + if (settings.store.shareSong) buttons.push({ label: "View Song", url: trackData.url, }); - const statusName = (() => { // Last.FM satus stuff dont touch + const statusName = (() => { switch (settings.store.nameFormat) { case NameFormat.ArtistFirst: return trackData.artist + " - " + trackData.name; @@ -509,17 +353,6 @@ export default definePlugin({ return trackData.name; case NameFormat.AlbumName: return trackData.album || settings.store.statusName; - // Stats.fm Status stuff - case NameFormat.ArtistFirst2: // hoping my code works - return trackData2?.artist ? `${trackData2.artist} - ${trackData2.name}` : settings.store.statusName; - case NameFormat.SongFirst2: - return trackData2?.name ? `${trackData2.name} - ${trackData2.artist}` : settings.store.statusName; - case NameFormat.ArtistOnly2: - return trackData2?.artist ?? settings.store.statusName; - case NameFormat.SongOnly2: - return trackData2?.name ?? settings.store.statusName; - case NameFormat.AlbumName2: - return trackData2?.album ?? settings.store.statusName; default: return settings.store.statusName; } @@ -527,19 +360,18 @@ export default definePlugin({ return { application_id: applicationId, - application_id2: applicationId2, // StatsFM Appid name: statusName, details: trackData.name, state: trackData.artist, assets, - assets2, // StatsFM assets buttons: buttons.length ? buttons.map(v => v.label) : undefined, metadata: { button_urls: buttons.map(v => v.url), }, - type: settings.store.useStreamingStatus ? ActivityType.STREAMING : settings.store.useListeningStatus ? ActivityType.LISTENING : ActivityType.PLAYING, + + type: settings.store.useListeningStatus ? ActivityType.LISTENING : ActivityType.PLAYING, flags: ActivityFlag.INSTANCE, }; }