Skip to content

Commit

Permalink
feat(stremio): many improvements (#8994)
Browse files Browse the repository at this point in the history
* feat(stremio): many improvements

* chore: remove onetime var

* chore: update image

Signed-off-by: veryCrunchy <me@verycrunchy.dev>

* fix: deepscan issues

Signed-off-by: veryCrunchy <me@verycrunchy.dev>

* chore: fmt

---------

Signed-off-by: veryCrunchy <me@verycrunchy.dev>
  • Loading branch information
veryCrunchy authored Dec 26, 2024
1 parent bcd3107 commit 06056e8
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 42 deletions.
22 changes: 13 additions & 9 deletions websites/S/Stremio/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
"$schema": "https://schemas.premid.app/metadata/1.12",
"apiVersion": 1,
"author": {
"name": "Sleeyax",
"id": "226037514954080257"
"name": "veryCrunchy",
"id": "576097150359044106"
},
"contributors": [
{
"name": "Sleeyax",
"id": "226037514954080257"
},
{
"name": "Dark_Ville",
"id": "638080361179512853"
Expand All @@ -18,15 +22,15 @@
},
"url": [
"www.stremio.com",
"stremio.com",
"app.strem.io",
"web.strem.io",
"web.stremio.com"
"web.stremio.com",
"stremio.crun.zip"
],
"version": "2.0.7",
"logo": "https://cdn.rcd.gg/PreMiD/websites/S/Stremio/assets/logo.png",
"thumbnail": "https://cdn.rcd.gg/PreMiD/websites/S/Stremio/assets/thumbnail.jpg",
"color": "#8A5AAB",
"version": "2.1.0",
"logo": "https://stremio.crun.zip/e8417074974250bc5c8613be8dac6aa46f432bad/images/icon.png",
"thumbnail": "https://www.stremio.com/website/posters-perspective-home.png",
"color": "#7b5bf5",
"category": "videos",
"tags": [
"streaming",
Expand All @@ -53,7 +57,7 @@
},
"title": "Show Thumbnail",
"icon": "fad fa-album",
"value": false
"value": true
},
{
"id": "buttons",
Expand Down
70 changes: 37 additions & 33 deletions websites/S/Stremio/presence.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const presence = new Presence({
clientId: "969208766807547917",
clientId: "503557087041683458",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

Expand All @@ -10,18 +10,17 @@ enum AppVersion {
}

const enum Assets {
Logo = "https://cdn.rcd.gg/PreMiD/websites/S/Stremio/assets/0.png",
Logo = "https://stremio.crun.zip/e8417074974250bc5c8613be8dac6aa46f432bad/images/stremio_symbol.png",
}

function getAppVersion(hostname: string) {
switch (hostname) {
case "web.strem.io":
case "web.stremio.com":
return AppVersion.V5;
case "www.stremio.com":
return AppVersion.Website;
case "app.strem.io":
return AppVersion.V4;
default:
return AppVersion.Website;
return AppVersion.V5;
}
}

Expand Down Expand Up @@ -107,6 +106,8 @@ presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
type: ActivityType.Watching,
details: "Stremio",
},
{ hash, hostname, pathname, href } = document.location,
[privacy, thumbnails, buttons, search] = await Promise.all([
Expand Down Expand Up @@ -140,13 +141,13 @@ presence.on("UpdateData", async () => {
const video = findVideo(presence);

if (privacy) {
presenceData.details = video !== null ? "Watching" : "Browsing";
presenceData.state = video !== null ? "Watching" : "Browsing";
break;
}

switch (hash.replace("#/", "").split("/").shift().split("?").shift()) {
case "":
presenceData.details = "Board";
presenceData.state = "Browsing";
presenceData.buttons = [
{
label: "View Board",
Expand All @@ -156,10 +157,9 @@ presence.on("UpdateData", async () => {
break;
case "detail": {
if (appVersion === AppVersion.V4) {
const title = document.querySelector(
presenceData.state = document.querySelector(
"#detail > div:nth-child(3) > div > div.sidebar-info-container > div > div.logo > div"
)?.textContent;
presenceData.state = title;
presenceData.largeImageKey =
document
.querySelector(
Expand All @@ -168,21 +168,28 @@ presence.on("UpdateData", async () => {
?.firstElementChild.getAttribute("src") ?? Assets.Logo;
} else {
const imgElement = document.querySelector(
"div[class*='meta-info-container'] > img[class*='logo']"
);
"div[class*='meta-info-container'] > img[class*='logo']"
),
routeContents = document.querySelectorAll(".route-content");
presenceData.largeImageKey =
imgElement?.getAttribute("src") ?? Assets.Logo;
(routeContents.length > 1
? routeContents[routeContents.length - 1]
: routeContents[0]
).querySelector("img")?.src ??
imgElement?.getAttribute("src") ??
Assets.Logo;
presenceData.state =
imgElement?.getAttribute("title") ??
document.querySelector(
"div[class*='logo-placeholder']:last-child"
)?.textContent;
}

presenceData.details = `Viewing a ${hash.split("/")[2]}`;
const type = hash.split("/")[2];
presenceData.details = `Viewing a ${type}`;
presenceData.buttons = [
{
label: "View Metadata",
label: `View ${type}`,
url: href,
},
];
Expand Down Expand Up @@ -221,12 +228,6 @@ presence.on("UpdateData", async () => {
: "div[class*='settings-content'] div[class*='selected']"
)?.textContent ?? "General";
presenceData.details = `${section} settings`;
presenceData.buttons = [
{
label: "View Settings",
url: href,
},
];
break;
}
case "discover": {
Expand Down Expand Up @@ -261,7 +262,9 @@ presence.on("UpdateData", async () => {
type === "series" ? "" : "s"
}`;
presenceData.state = `${category ?? "All"}${
genre ? ` | ${genre}` : ""
genre && !["none", "genre"].includes(genre.toLowerCase())
? ` | ${genre}`
: ""
}`;

break;
Expand Down Expand Up @@ -293,13 +296,13 @@ presence.on("UpdateData", async () => {
];
break;
case "search":
presenceData.details = "Search";
presenceData.details = "Searching";
break;
case "player": {
if (video === null) break;

presenceData.endTimestamp = video.endTimestamp;
delete presenceData.startTimestamp;
presenceData.startTimestamp = video.startTimestamp;

if (
(appVersion === AppVersion.V4
Expand All @@ -312,18 +315,18 @@ presence.on("UpdateData", async () => {
video.isPaused
) {
presenceData.smallImageKey = Assets.Pause;
presenceData.smallImageText = "Player is paused";
presenceData.smallImageText = "Paused";
presenceData.state = "Paused";
} else {
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = "Player is playing";
presenceData.smallImageText = "Playing";
presenceData.state = "Watching";
}

let metaUrl: string, title: string;
let metaUrl: string;

if (appVersion === AppVersion.V4) {
title = document
presenceData.details = document
.querySelector("head > title")
?.textContent?.replace("Stremio -", "")
?.trim();
Expand All @@ -342,16 +345,17 @@ presence.on("UpdateData", async () => {
const {
metaItem: { content },
seriesInfo,
title,
} = playerState;
({ title } = playerState);
metaUrl = `${window.location.origin}/#/detail/${content.type}/${content.id}`;
if (content.type === "series")
metaUrl += `/${content.id}:${seriesInfo.season}:${seriesInfo.episode}`;
presenceData.largeImageKey = content.logo ?? Assets.Logo;
presenceData.largeImageKey = content.poster ?? Assets.Logo;
presenceData.name = content.name;
presenceData.details =
title.replace(`${content.name} -`, "") ?? "Player";
}
}

presenceData.details = title ?? "Player";
if (metaUrl) {
presenceData.buttons = [
{
Expand Down Expand Up @@ -394,7 +398,7 @@ presence.on("UpdateData", async () => {
break;

default: {
const activeTab = document.querySelector("[class='active']");
const activeTab = document.querySelector("[class='nav-link active']");
if (
activeTab === null ||
activeTab.parentElement?.className === "langs"
Expand Down

0 comments on commit 06056e8

Please sign in to comment.