Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: update activities #9148

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions @types/premid/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
type?: Exclude<ActivityType, ActivityType.Listening>;
interface NonMediaPresenceData extends BasePresenceData {
type?: Exclude<ActivityType, ActivityType.Listening | ActivityType.Watching>;
largeImageText?: never;
}

type PresenceData = ListeningPresenceData | NonListeningPresenceData;
type PresenceData = MediaPresenceData | NonMediaPresenceData;

interface ButtonData {
/**
Expand Down
8 changes: 7 additions & 1 deletion websites/D/Disney+/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -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",
Expand Down
74 changes: 54 additions & 20 deletions websites/D/Disney+/presence.ts
Original file line number Diff line number Diff line change
@@ -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",
}),
Expand All @@ -22,7 +35,8 @@ async function getStrings() {
let strings: Awaited<ReturnType<typeof getStrings>>,
oldLang: string = null,
title: string,
subtitle: string;
subtitle: string,
imageId: string;

presence.on("UpdateData", async () => {
const [newLang, privacy, time, buttons] = await Promise.all([
Expand 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<HTMLVideoElement>("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"): {
Expand Down
11 changes: 10 additions & 1 deletion websites/Y/YouTube Music/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion websites/Y/YouTube Music/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ presence.on("UpdateData", async () => {
showBrowsing,
privacyMode,
useTimeLeft,
showAsListening,
] = await Promise.all([
presence.getSetting<boolean>("buttons"),
presence.getSetting<boolean>("timestamps"),
Expand All @@ -28,6 +29,7 @@ presence.on("UpdateData", async () => {
presence.getSetting<boolean>("browsing"),
presence.getSetting<boolean>("privacy"),
presence.getSetting<boolean>("useTimeLeft"),
presence.getSetting<boolean>("showAsListening"),
]),
{ mediaSession } = navigator,
watchID =
Expand Down Expand Up @@ -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"
Expand Down
Loading