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

feat(Kick): add VOD support & watchtype && fix(Kick): fix issues due to code change #8827

Merged
merged 2 commits into from
Oct 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion websites/K/Kick/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"kick.com",
"help.kick.com"
],
"version": "1.0.3",
"version": "1.1.0",
"logo": "https://cdn.rcd.gg/PreMiD/websites/K/Kick/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/K/Kick/assets/thumbnail.png",
"color": "#53fc18",
Expand Down
59 changes: 52 additions & 7 deletions websites/K/Kick/presence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

presence.on("UpdateData", async () => {
const { pathname, hostname, href } = document.location,
videoEl = document.querySelector<HTMLVideoElement>("video"),
pathArr = pathname.split("/"),
{ details, smallImageKey, largeImageKey, state, buttons } = getPageData(
pathArr[1],
Expand All @@ -24,6 +25,17 @@
if (smallImageKey) presenceData.smallImageKey = smallImageKey;
if (state) presenceData.state = state;

if (videoEl?.duration && presenceData.smallImageKey !== Assets.Viewing) {
presenceData.smallImageKey = videoEl?.paused ? Assets.Pause : Assets.Play;
presenceData.smallImageText = videoEl?.paused ? "Paused" : "Playing";
if (!videoEl?.paused) {
[presenceData.startTimestamp, presenceData.endTimestamp] =
presence.getTimestampsfromMedia(
document.querySelector<HTMLVideoElement>("video")
);
}
}

if (!(await presence.getSetting<boolean>("details"))) {
presenceData.details = "Browsing Kick...";
delete presenceData.state;
Expand All @@ -35,6 +47,13 @@
if (await presence.getSetting<boolean>("logo"))
presenceData.largeImageKey = Assets.Logo;

if (
presenceData.smallImageKey === Assets.Play ||
presenceData.smallImageKey === Assets.Pause ||
presenceData.smallImageKey === Assets.Viewing
)
presenceData.type = ActivityType.Watching;

if (details) presence.setActivity(presenceData);
});

Expand Down Expand Up @@ -131,14 +150,16 @@
details: `Reading ${formatText(page)}...`,
smallImageKey: Assets.Reading,
};
default:
default: {
// watching/viewing a stream
if (document.querySelector(".stream-username")) {
const streamer = document.querySelector(
".stream-username,#channel-username"
)?.textContent,
titleEl = document.querySelector("title")?.textContent;
if (streamer && titleEl.includes("Live")) {
let smallImageKey = "",
state = "",
buttons: [ButtonData, ButtonData?];
const streamer =
document.querySelector(".stream-username").textContent;
if (document.querySelector(".odometer-value")) {
state = `Watching: ${streamer}`;
smallImageKey = Assets.Live;
Expand All @@ -159,33 +180,57 @@
];
}
return {
details: document.querySelector(".stream-title").textContent,
details:
JSON.parse(
document.querySelectorAll('[type="application/ld+json"]')?.[1]
?.textContent
)?.broadcastOfEvent?.name ?? "Unknown title",
state,
largeImageKey:
document.querySelector<HTMLImageElement>(".owner-avatar img")
?.src,
smallImageKey,
buttons,
};
} else if (streamer && titleEl?.includes("VOD")) {
const smallImageKey = "";

Check warning on line 196 in websites/K/Kick/presence.ts

View workflow job for this annotation

GitHub Actions / Compile and Lint

Variable 'smallImageKey' is only used once
return {
details: document.querySelector<HTMLMetaElement>(
'meta[name="description"]'
)?.content,
state: document.querySelector("#channel-username")?.textContent,
largeImageKey:
document.querySelector<HTMLImageElement>(".owner-avatar img")
?.src,
smallImageKey,
buttons: [
{
label: "Watch Stream VOD",
url,
},
],
};
} else {
return {
details: "Browsing Kick...",
};
}
}
}
}
case "help.kick.com": {
const topic = document.querySelector("header.text-2xl")?.textContent;
switch (pageDetail) {
case "collections": {
return {
details: document.querySelector("header.text-2xl").textContent,
details: topic ?? "Unknown title",
state: "Searching resource category...",
smallImageKey: Assets.Search,
};
}
case "articles": {
return {
details: document.querySelector("header.text-2xl").textContent,
details: topic ?? "Unknown title",
state: "Reading article...",
smallImageKey: Assets.Reading,
};
Expand Down
Loading