Skip to content

Commit

Permalink
feat(SOOP): add activity (#9081)
Browse files Browse the repository at this point in the history
Signed-off-by: Slowlife <[email protected]>
  • Loading branch information
Slowlife01 authored Jan 5, 2025
1 parent 5ec7b64 commit 2973204
Show file tree
Hide file tree
Showing 2 changed files with 162 additions and 0 deletions.
48 changes: 48 additions & 0 deletions websites/S/SOOP/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"$schema": "https://schemas.premid.app/metadata/1.12",
"apiVersion": 1,
"author": {
"id": "374905512661221377",
"name": "slowlife."
},
"service": "SOOP",
"altnames": [
""
],
"description": {
"en": "SOOP, a streaming platform created through participation and communication! Discover a variety of content at SOOP."
},
"url": [
"www.sooplive.co.kr",
"play.sooplive.co.kr",
"vod.sooplive.co.kr"
],
"version": "1.0.0",
"logo": "https://i.imgur.com/VbU4HLa.png",
"thumbnail": "https://i.imgur.com/WDZMHwK.png",
"color": "#0994ff",
"category": "videos",
"tags": [
"streaming",
"gaming",
"entertainment"
],
"settings": [
{
"id": "lang",
"multiLanguage": true
},
{
"id": "logo",
"title": "Show Streamer Logo",
"icon": "fad fa-images",
"value": true
},
{
"id": "time",
"title": "Show Stream Elapsed Time",
"icon": "fad fa-stopwatch",
"value": false
}
]
}
114 changes: 114 additions & 0 deletions websites/S/SOOP/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
const presence = new Presence({
clientId: "1325035374430519392",
}),
getStrings = async () => {
return presence.getStrings(
{
play: "general.playing",
pause: "general.paused",
live: "general.live",
browse: "general.browsing",
watchStream: "general.buttonWatchStream",
watchVideo: "general.buttonWatchVideo",
},
oldLang
);
},
browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://i.imgur.com/VbU4HLa.png",
}

const enum SoopAssets {
Browse = "https://i.imgur.com/MefUF9R.png",
Live = "https://i.imgur.com/XNGUK9X.png",
Play = "https://i.imgur.com/th6he6j.png",
Pause = "https://i.imgur.com/WN5FaFU.png",
}

let oldLang: string, strings: Awaited<ReturnType<typeof getStrings>>;

presence.on("UpdateData", async () => {
const [newLang, showStreamerLogo, showElapsedTime] = await Promise.all([
presence.getSetting<string>("lang"),
presence.getSetting<boolean>("logo"),
presence.getSetting<boolean>("time"),
]);

if (oldLang !== newLang || !strings) {
oldLang = newLang;
strings = await getStrings();
}

const presenceData: PresenceData = {
details: strings.browse,
largeImageKey: Assets.Logo,
smallImageKey: SoopAssets.Browse,
startTimestamp: browsingTimestamp,
type: ActivityType.Watching,
},
{ hostname, pathname, href } = document.location;

switch (hostname.split(".")[0]) {
case "play": {
presenceData.details =
document.querySelector("span#infoTitle").textContent;
presenceData.state = document.querySelector("a#infoNickName").textContent;
presenceData.largeImageKey = showStreamerLogo
? document.querySelector<HTMLImageElement>("#bjThumbnail img").src
: Assets.Logo;

presenceData.smallImageKey = SoopAssets.Live;
presenceData.smallImageText = strings.live;

if (showElapsedTime) {
presenceData.startTimestamp =
Math.floor(Date.now() / 1000) -
presence.timestampFromFormat(
document.querySelector("span#time").textContent
);
}

presenceData.buttons = [{ url: href, label: strings.watchStream }];
break;
}
case "vod": {
const isCatch = pathname.includes("/catch"),
video = document.querySelector("video");

if (video) {
presenceData.details = document.querySelector(
isCatch ? "h3.title" : "div.broadcast_title"
).textContent;
presenceData.state = document.querySelector(
isCatch ? "button.nick.ictFunc" : "a.ictFunc"
).textContent;
presenceData.largeImageKey = showStreamerLogo
? document.querySelector<HTMLImageElement>(
isCatch ? "div.author_inner img" : "div.thumbnail_box img"
).src
: Assets.Logo;

presenceData.smallImageKey = video.paused
? SoopAssets.Pause
: SoopAssets.Play;
presenceData.smallImageText = video.paused
? strings.pause
: strings.play;

presenceData.buttons = [{ url: href, label: strings.watchVideo }];

[presenceData.startTimestamp, presenceData.endTimestamp] =
presence.getTimestampsfromMedia(video);

if (video.paused) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
}
}
}

presence.setActivity(presenceData);
});

0 comments on commit 2973204

Please sign in to comment.