From 06056e83e903b183952e99295a1437859aedbadd Mon Sep 17 00:00:00 2001 From: veryCrunchy Date: Thu, 26 Dec 2024 01:58:01 +0100 Subject: [PATCH] feat(stremio): many improvements (#8994) * feat(stremio): many improvements * chore: remove onetime var * chore: update image Signed-off-by: veryCrunchy * fix: deepscan issues Signed-off-by: veryCrunchy * chore: fmt --------- Signed-off-by: veryCrunchy --- websites/S/Stremio/metadata.json | 22 ++++++---- websites/S/Stremio/presence.ts | 70 +++++++++++++++++--------------- 2 files changed, 50 insertions(+), 42 deletions(-) diff --git a/websites/S/Stremio/metadata.json b/websites/S/Stremio/metadata.json index 4a6bbdfbfdcf..a9901acbf2e1 100644 --- a/websites/S/Stremio/metadata.json +++ b/websites/S/Stremio/metadata.json @@ -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" @@ -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", @@ -53,7 +57,7 @@ }, "title": "Show Thumbnail", "icon": "fad fa-album", - "value": false + "value": true }, { "id": "buttons", diff --git a/websites/S/Stremio/presence.ts b/websites/S/Stremio/presence.ts index 8f4437c1724d..7caee49f916f 100644 --- a/websites/S/Stremio/presence.ts +++ b/websites/S/Stremio/presence.ts @@ -1,5 +1,5 @@ const presence = new Presence({ - clientId: "969208766807547917", + clientId: "503557087041683458", }), browsingTimestamp = Math.floor(Date.now() / 1000); @@ -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; } } @@ -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([ @@ -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", @@ -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( @@ -168,10 +168,16 @@ 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( @@ -179,10 +185,11 @@ presence.on("UpdateData", async () => { )?.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, }, ]; @@ -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": { @@ -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; @@ -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 @@ -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(); @@ -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 = [ { @@ -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"