From 27e2a15e24e476679c9aeb3f81e0548acd3d2b23 Mon Sep 17 00:00:00 2001 From: Florian Metz Date: Sat, 11 Jan 2025 02:36:14 +0100 Subject: [PATCH 1/6] feat: allow watching type to set largeImageText --- @types/premid/index.d.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/@types/premid/index.d.ts b/@types/premid/index.d.ts index 5fd119c9bced..c8cb698caf6c 100644 --- a/@types/premid/index.d.ts +++ b/@types/premid/index.d.ts @@ -102,17 +102,17 @@ interface BasePresenceData { buttons?: [ButtonData, ButtonData?]; } -interface ListeningPresenceData extends BasePresenceData { - type: ActivityType.Listening; +interface MediaPresenceData extends BasePresenceData { + type: ActivityType.Listening | ActivityType.Watching; largeImageText?: string | Node; } -interface NonListeningPresenceData extends BasePresenceData { +interface NonMediaPresenceData extends BasePresenceData { type?: Exclude; largeImageText?: never; } -type PresenceData = ListeningPresenceData | NonListeningPresenceData; +type PresenceData = MediaPresenceData | NonMediaPresenceData; interface ButtonData { /** From 549d73cba0626bd3b2260ead7cdf3619dfd95a71 Mon Sep 17 00:00:00 2001 From: Florian Metz Date: Sat, 11 Jan 2025 04:12:40 +0100 Subject: [PATCH 2/6] feat: add toggle for showing title --- websites/Y/YouTube Music/metadata.json | 11 ++++++++++- websites/Y/YouTube Music/presence.ts | 4 +++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/websites/Y/YouTube Music/metadata.json b/websites/Y/YouTube Music/metadata.json index 0c7760b4f5df..7ceb95fc9db4 100644 --- a/websites/Y/YouTube Music/metadata.json +++ b/websites/Y/YouTube Music/metadata.json @@ -20,7 +20,7 @@ "vi_VN": "Một dịch vụ phát nhạc với các album, đĩa đơn, video, bản remix, và các tiết mục trực tiếp chính thức và hơn nữa cho Android, iOS và máy tính. Tất cả đều tại đây." }, "url": "music.youtube.com", - "version": "3.0.25", + "version": "3.0.26", "logo": "https://cdn.rcd.gg/PreMiD/websites/Y/YouTube%20Music/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/Y/YouTube%20Music/assets/thumbnail.png", "color": "#E40813", @@ -36,6 +36,15 @@ "icon": "fad fa-shield-alt", "value": false }, + { + "id": "showAsListening", + "title": "Show song in status", + "icon": "fad fa-music", + "if": { + "privacy": false + }, + "value": false + }, { "id": "cover", "title": "Show Cover", diff --git a/websites/Y/YouTube Music/presence.ts b/websites/Y/YouTube Music/presence.ts index 60909e8dcf70..338061a7f716 100644 --- a/websites/Y/YouTube Music/presence.ts +++ b/websites/Y/YouTube Music/presence.ts @@ -20,6 +20,7 @@ presence.on("UpdateData", async () => { showBrowsing, privacyMode, useTimeLeft, + showAsListening, ] = await Promise.all([ presence.getSetting("buttons"), presence.getSetting("timestamps"), @@ -28,6 +29,7 @@ presence.on("UpdateData", async () => { presence.getSetting("browsing"), presence.getSetting("privacy"), presence.getSetting("useTimeLeft"), + presence.getSetting("showAsListening"), ]), { mediaSession } = navigator, watchID = @@ -122,7 +124,7 @@ presence.on("UpdateData", async () => { presenceData = { type: ActivityType.Listening, - name: mediaSession.metadata.title, + name: showAsListening ? mediaSession.metadata.title : "YouTube Music", largeImageKey: showCover ? mediaSession?.metadata?.artwork?.at(-1)?.src ?? "https://cdn.rcd.gg/PreMiD/websites/Y/YouTube%20Music/assets/1.png" From 2ea31a9abcd41bf760fd2f853fb769cccdb1492c Mon Sep 17 00:00:00 2001 From: Florian Metz Date: Sat, 11 Jan 2025 04:48:19 +0100 Subject: [PATCH 3/6] chore: retrofit activities --- websites/D/Disney+/metadata.json | 8 +++- websites/D/Disney+/presence.ts | 74 +++++++++++++++++++++++--------- 2 files changed, 61 insertions(+), 21 deletions(-) diff --git a/websites/D/Disney+/metadata.json b/websites/D/Disney+/metadata.json index c7cfb2b2a0da..bf44644e8b4e 100644 --- a/websites/D/Disney+/metadata.json +++ b/websites/D/Disney+/metadata.json @@ -5,6 +5,12 @@ "name": "Tiemen", "id": "152164749868662784" }, + "contributors": [ + { + "name": "Timeraa", + "id": "223238938716798978" + } + ], "service": "Disney+", "description": { "en": "Disney+ is the exclusive home for your favorite movies and TV shows from Disney, Pixar, Marvel, Star Wars, National Geographic, and Star. Start streaming today.", @@ -22,7 +28,7 @@ }, "url": "www.disneyplus.com", "regExp": "([a-z0-9-]+[.])*disneyplus[.]com[/]|([a-z0-9-]+[.])*hotstar[.]com[/]", - "version": "1.6.5", + "version": "1.7.0", "logo": "https://cdn.rcd.gg/PreMiD/websites/D/Disney+/assets/logo.png", "thumbnail": "https://cdn.rcd.gg/PreMiD/websites/D/Disney+/assets/thumbnail.png", "color": "#233778", diff --git a/websites/D/Disney+/presence.ts b/websites/D/Disney+/presence.ts index 03f957cf6888..daf46c7001dd 100644 --- a/websites/D/Disney+/presence.ts +++ b/websites/D/Disney+/presence.ts @@ -1,3 +1,16 @@ +//* I think this is a browser bug because the custom element does not have any properties when accessing it directly... +window.addEventListener("message", e => { + if (e.data.type === "pmd-receive-image-id") ({ imageId } = e.data); +}); + +const script = document.createElement("script"); +script.textContent = ` +setInterval(() => { + window.postMessage({ type: "pmd-receive-image-id", imageId: document.querySelector("disney-web-player")?.mediaPlayer?.mediaPlaybackCriteria?.metadata?.images_experience?.standard?.tile["1.00"]?.imageId }, "*"); +}, 100); +`; +document.head.appendChild(script); + const presence: Presence = new Presence({ clientId: "630236276829716483", }), @@ -22,7 +35,8 @@ async function getStrings() { let strings: Awaited>, oldLang: string = null, title: string, - subtitle: string; + subtitle: string, + imageId: string; presence.on("UpdateData", async () => { const [newLang, privacy, time, buttons] = await Promise.all([ @@ -48,34 +62,54 @@ presence.on("UpdateData", async () => { "https://cdn.rcd.gg/PreMiD/websites/D/Disney+/assets/logo.png"; switch (true) { case pathname.includes("play"): { + const video = + document.querySelector("video#hivePlayer"); + + //* Wait for elements to load to prevent setactivity spam + if (!imageId || !video) return; + + presenceData.largeImageKey = `https://disney.images.edge.bamgrid.com/ripcut-delivery/v2/variant/disney/${imageId}/compose?format=png&width=512`; + if (!privacy) { if (presenceData.startTimestamp) delete presenceData.startTimestamp; presenceData.details = document.querySelector( ".title-field.body-copy" )?.textContent; - presenceData.state = - document.querySelector(".subtitle-field")?.textContent; - const paused = !!document.querySelector("[aria-label='Play']"), - timeRemaining = document.querySelector( - ".time-remaining-label" - )?.textContent; + const { paused } = video; - presenceData.smallImageKey = paused ? Assets.Pause : Assets.Play; - presenceData.smallImageText = paused ? strings.pause : strings.play; - - if (!paused && timeRemaining) { - presenceData.endTimestamp = - Date.now() / 1000 + presence.timestampFromFormat(timeRemaining); + if (!paused) { + const sliderEl = document.querySelector( + ".progress-bar .slider-container" + ), + timestamps = presence.getTimestamps( + parseInt(sliderEl.getAttribute("aria-valuenow")), + parseInt(sliderEl.getAttribute("aria-valuemax")) + ); + presenceData.startTimestamp = timestamps[0]; + presenceData.endTimestamp = timestamps[1]; + } else { + presenceData.smallImageKey = Assets.Pause; + presenceData.smallImageText = strings.pause; } - } else presenceData.details = "Watching content"; - presenceData.buttons = [ - { - label: "Watch Content", - url: href, - }, - ]; + const parts = document + .querySelector(".subtitle-field") + ?.textContent.match(/S(\d+):E(\d+) /); + if (parts.length > 2) + presenceData.largeImageText = `Season ${parts[1]}, Episode ${parts[2]}`; + + presenceData.state = document + .querySelector(".subtitle-field") + ?.textContent.replace(/S(\d+):E(\d+) /, ""); + + presenceData.buttons = [ + { + label: parts.length > 2 ? "Watch Episode" : "Watch Movie", + url: href, + }, + ]; + } else presenceData.details = "Watching content"; break; } case pathname.includes("entity"): { From 3bc92fd3801d8dc17673b6012d59169884205c4e Mon Sep 17 00:00:00 2001 From: Florian Metz Date: Sat, 11 Jan 2025 04:53:47 +0100 Subject: [PATCH 4/6] fix: deepscan issue --- websites/D/Disney+/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/D/Disney+/presence.ts b/websites/D/Disney+/presence.ts index daf46c7001dd..3f234b0c88b3 100644 --- a/websites/D/Disney+/presence.ts +++ b/websites/D/Disney+/presence.ts @@ -96,7 +96,7 @@ presence.on("UpdateData", async () => { const parts = document .querySelector(".subtitle-field") ?.textContent.match(/S(\d+):E(\d+) /); - if (parts.length > 2) + if (parts?.length > 2) presenceData.largeImageText = `Season ${parts[1]}, Episode ${parts[2]}`; presenceData.state = document From 3a15466c8b353e199e53a9252ebdcebb618cddb9 Mon Sep 17 00:00:00 2001 From: Florian Metz Date: Sat, 11 Jan 2025 05:00:39 +0100 Subject: [PATCH 5/6] fix: deepscan issue --- websites/D/Disney+/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/D/Disney+/presence.ts b/websites/D/Disney+/presence.ts index 3f234b0c88b3..71ee6db87c3a 100644 --- a/websites/D/Disney+/presence.ts +++ b/websites/D/Disney+/presence.ts @@ -105,7 +105,7 @@ presence.on("UpdateData", async () => { presenceData.buttons = [ { - label: parts.length > 2 ? "Watch Episode" : "Watch Movie", + label: parts?.length > 2 ? "Watch Episode" : "Watch Movie", url: href, }, ]; From 3d5e80e9b33df42bc29bb078fb80bb20ec5c7d7d Mon Sep 17 00:00:00 2001 From: Florian Metz Date: Sat, 11 Jan 2025 21:37:15 +0100 Subject: [PATCH 6/6] Update index.d.ts Co-authored-by: Skully <117316808+skullysmods@users.noreply.github.com> Signed-off-by: Florian Metz --- @types/premid/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/@types/premid/index.d.ts b/@types/premid/index.d.ts index c8cb698caf6c..1622b0955ebb 100644 --- a/@types/premid/index.d.ts +++ b/@types/premid/index.d.ts @@ -108,7 +108,7 @@ interface MediaPresenceData extends BasePresenceData { } interface NonMediaPresenceData extends BasePresenceData { - type?: Exclude; + type?: Exclude; largeImageText?: never; }