Skip to content

Commit

Permalink
feat(HBO GO): use watching type & fix only show browsing (#8890)
Browse files Browse the repository at this point in the history
* feat(HBO GO): use watching type & fix only show browsing

* feat(HBO GO): update presence details for series

---------

Signed-off-by: Slowlife <[email protected]>
Co-authored-by: Daniel Lau <[email protected]>
  • Loading branch information
Slowlife01 and theusaf authored Nov 19, 2024
1 parent 1359f44 commit 9459ced
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion websites/H/HBO GO/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"www.hbogoasia.id",
"www.hbogoasia.ph"
],
"version": "2.3.9",
"version": "2.4.0",
"logo": "https://cdn.rcd.gg/PreMiD/websites/H/HBO%20GO/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/H/HBO%20GO/assets/thumbnail.png",
"color": "#011921",
Expand Down
58 changes: 32 additions & 26 deletions websites/H/HBO GO/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,35 +6,43 @@ const presence = new Presence({
pause: "general.paused",
});

function convertToTitleCase(str: string): string {
if (!str) return "";

return str.toLowerCase().replace(/\b\w/g, s => s.toUpperCase());
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
details: "Browsing...",
largeImageKey:
"https://cdn.rcd.gg/PreMiD/websites/H/HBO%20GO/assets/logo.png",
type: ActivityType.Watching,
},
video: HTMLVideoElement = document.querySelector(
"#hbo-sdk--controller-container #hbo-sdk--controller-osd #hbo-sdk--vid #hbo-sdk--vid_Clpp_html5_mse_smooth_api"
);
if (
(document.querySelector(
"#hbo-sdk--controller-container #hbo-sdk--controller-osd #hbo-sdk--vid #hbo-sdk--vid_Clpp_html5_mse_smooth_api"
) === null &&
document.querySelector("#hbo-sdk--player-title > div.content-title") ===
null) ||
!video
) {
presenceData.details = "Browsing...";
presenceData.startTimestamp = Math.floor(Date.now() / 1000);

return presence.setActivity(presenceData);
}
video: HTMLVideoElement = document.querySelector("video");

if (!isNaN(video.duration)) {
//* Get required tags
const title: HTMLElement = document.querySelector(
"#hbo-sdk--player-title > div.content-title"
if (!isNaN(video?.duration) && !!document.querySelector("div.movie-title")) {
const title = convertToTitleCase(
document.querySelector("div.movie-title").textContent
);
presenceData.details = "Watching:";
presenceData.state = title.textContent;
if (document.location.pathname.includes("/series/")) {
const match = title.match(
/(?<series>.+?)\sS(?<season>\d+)\s(?<episode>\d{2})(?::\s*(?<title>.+))?/
);

match.groups.episode = parseInt(match.groups.episode).toString();

presenceData.name = match.groups.series;
presenceData.details =
match.groups.title || `Episode ${match.groups.episode}`;
presenceData.state = `Season ${match.groups.season}, Episode ${match.groups.episode}`;
} else {
presenceData.details = title;
presenceData.state = document.location.pathname.includes("/movies/")
? "Movie"
: "Extra";
}

presenceData.smallImageKey = video.paused ? Assets.Pause : Assets.Play;
presenceData.smallImageText = video.paused
? (await strings).pause
Expand All @@ -45,13 +53,11 @@ presence.on("UpdateData", async () => {
Math.floor(video.duration)
);

//* Remove timestamps if paused
if (video.paused) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
}

//* If tags are not "null"
if (title.textContent) presence.setActivity(presenceData, !video.paused);
} else presence.setActivity();
presence.setActivity(presenceData);
});

0 comments on commit 9459ced

Please sign in to comment.