From 3267169fa3bf8c61e3d9c336aeb12054fac63184 Mon Sep 17 00:00:00 2001 From: yuri Date: Sat, 28 Dec 2024 20:45:09 +0000 Subject: [PATCH 01/10] feat(Sflix): add presence (#5305) --- websites/S/Sflix/iframe.ts | 12 ++++++ websites/S/Sflix/metadata.json | 38 +++++++++++++++++ websites/S/Sflix/presence.ts | 77 ++++++++++++++++++++++++++++++++++ 3 files changed, 127 insertions(+) create mode 100644 websites/S/Sflix/iframe.ts create mode 100644 websites/S/Sflix/metadata.json create mode 100644 websites/S/Sflix/presence.ts diff --git a/websites/S/Sflix/iframe.ts b/websites/S/Sflix/iframe.ts new file mode 100644 index 000000000000..4ce601abd01e --- /dev/null +++ b/websites/S/Sflix/iframe.ts @@ -0,0 +1,12 @@ +const iframe = new iFrame(); + +iframe.on("UpdateData", async () => { + const video = document.querySelector("video"); + if (!isNaN(video?.duration)) { + iframe.send({ + duration: video.duration, + currentTime: video.currentTime, + paused: video.paused, + }); + } +}); diff --git a/websites/S/Sflix/metadata.json b/websites/S/Sflix/metadata.json new file mode 100644 index 000000000000..357182f049b8 --- /dev/null +++ b/websites/S/Sflix/metadata.json @@ -0,0 +1,38 @@ +{ + "$schema": "https://schemas.premid.app/metadata/1.12", + "apiVersion": 1, + "author": { + "id": "290528827715747841", + "name": "iuriineves" + }, + "service": "Sflix", + "description": { + "en": "SFlix is a Free Movies streaming site with zero ads. We let you watch movies online without having to register or paying, with over 10000 movies and TV-Series." + }, + "url": [ + "sflix2.to", + "enorme.tv" + ], + "version": "1.0.0", + "logo": "https://img.sflix2.to/xxrz/400x400/100/66/35/66356c25ce98cb12993249e21742b129/66356c25ce98cb12993249e21742b129.png", + "thumbnail": "https://img.sflix.to/xxrz/1300x700/100/8e/5a/8e5afb7b78cfcb3c3667504fd5830a0f/8e5afb7b78cfcb3c3667504fd5830a0f.jpeg", + "color": "#03abb8", + "category": "videos", + "tags": [ + "sflix", + "video", + "media", + "movies", + "shows" + ], + "settings": [ + { + "id": "thumbnail", + "title": "Show thumbnail", + "icon": "fad fa-album", + "value": true + } + ], + "iframe": true, + "iFrameRegExp": ".*" +} \ No newline at end of file diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts new file mode 100644 index 000000000000..c0f613307b8c --- /dev/null +++ b/websites/S/Sflix/presence.ts @@ -0,0 +1,77 @@ +const presence = new Presence({ + clientId: "1322565714128797798", + }), + browsingTimestamp = Math.floor(Date.now() / 1000); + +const enum Assets { // Other default assets can be found at index.d.ts + Logo = "https://img.sflix2.to/xxrz/400x400/100/66/35/66356c25ce98cb12993249e21742b129/66356c25ce98cb12993249e21742b129.png", +} + +let video = { + duration: 0, + currentTime: 0, + paused: true, +}; + +presence.on("iFrameData", (data: { duration: number, currentTime: number, paused: boolean }) => { + video = data; +}); + +presence.on("UpdateData", async () => { + const presenceData: PresenceData = { + largeImageKey: Assets.Logo, + type: ActivityType.Watching, + startTimestamp: browsingTimestamp, + }, + + [ thumbnail ] = await Promise.all([ + presence.getSetting("thumbnail"), + ]), + + variables = await presence.getPageVariable("currPage"); + + switch (variables.currPage) { + case "": { + presenceData.details = "Searching"; + presenceData.state = `${document.querySelector("h2[class*='cat-heading']").textContent.split('"')[1] || document.querySelector("h2[class*='cat-heading']").textContent}`; + presenceData.smallImageKey = Assets.Search; + break; + } + case "home_search": + case "home": { + presenceData.details = "Browsing"; + presenceData.state = "Home"; + presenceData.smallImageKey = Assets.Reading; + break; + } + case "detail": { + presenceData.details = "Browsing"; + presenceData.state = document.querySelector(".heading-name")?.textContent; + presenceData.smallImageKey = Assets.Reading; + break; + } + case "watch": { + + const showTitle = document.querySelector(".heading-name").textContent, + thumbnailURL = document.querySelector(`img[title*="${showTitle}"]`)?.getAttribute("src"); + + presenceData.details = `${showTitle}`; + presenceData.state = `${document.querySelector(".on-air div h3")?.textContent || ""}`; + if (thumbnail && thumbnailURL) presenceData.largeImageKey = thumbnailURL; + + + if (!video.paused) { + const timestamps = presence.getTimestamps(video.currentTime, video.duration); + presenceData.smallImageKey = Assets.Play; + presenceData.startTimestamp = timestamps[0]; + presenceData.endTimestamp = timestamps[1]; + } else { + presenceData.smallImageKey = Assets.Pause; + delete presenceData.startTimestamp; + delete presenceData.endTimestamp; + } + break; + } + } + presence.setActivity(presenceData); +}); From 2f7150767b4cb2ca18c8ff407883a1c688020401 Mon Sep 17 00:00:00 2001 From: yuri Date: Sat, 28 Dec 2024 20:53:59 +0000 Subject: [PATCH 02/10] feat(Sflix): add privacy setting --- websites/S/Sflix/metadata.json | 6 ++++++ websites/S/Sflix/presence.ts | 21 ++++++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/websites/S/Sflix/metadata.json b/websites/S/Sflix/metadata.json index 357182f049b8..76ebc11d389d 100644 --- a/websites/S/Sflix/metadata.json +++ b/websites/S/Sflix/metadata.json @@ -31,6 +31,12 @@ "title": "Show thumbnail", "icon": "fad fa-album", "value": true + }, + { + "id": "privacy", + "title": "Privacy", + "icon": "fad fa-user-secret", + "value": false } ], "iframe": true, diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index c0f613307b8c..24c004f1869f 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -24,8 +24,9 @@ presence.on("UpdateData", async () => { startTimestamp: browsingTimestamp, }, - [ thumbnail ] = await Promise.all([ + [ thumbnail, privacy ] = await Promise.all([ presence.getSetting("thumbnail"), + presence.getSetting("privacy"), ]), variables = await presence.getPageVariable("currPage"); @@ -33,8 +34,8 @@ presence.on("UpdateData", async () => { switch (variables.currPage) { case "": { presenceData.details = "Searching"; - presenceData.state = `${document.querySelector("h2[class*='cat-heading']").textContent.split('"')[1] || document.querySelector("h2[class*='cat-heading']").textContent}`; - presenceData.smallImageKey = Assets.Search; + presenceData.smallImageKey = Assets.Search; + presenceData.state = privacy ? "" : `${document.querySelector("h2[class*='cat-heading']").textContent.split('"')[1] || document.querySelector("h2[class*='cat-heading']").textContent}`; break; } case "home_search": @@ -46,7 +47,7 @@ presence.on("UpdateData", async () => { } case "detail": { presenceData.details = "Browsing"; - presenceData.state = document.querySelector(".heading-name")?.textContent; + presenceData.state = privacy ? "" : document.querySelector(".heading-name")?.textContent; presenceData.smallImageKey = Assets.Reading; break; } @@ -55,16 +56,18 @@ presence.on("UpdateData", async () => { const showTitle = document.querySelector(".heading-name").textContent, thumbnailURL = document.querySelector(`img[title*="${showTitle}"]`)?.getAttribute("src"); - presenceData.details = `${showTitle}`; - presenceData.state = `${document.querySelector(".on-air div h3")?.textContent || ""}`; - if (thumbnail && thumbnailURL) presenceData.largeImageKey = thumbnailURL; + presenceData.details = privacy ? "Watching" : `${showTitle}`; + presenceData.state = privacy ? "" : `${document.querySelector(".on-air div h3")?.textContent || ""}`; + presenceData.largeImageKey = (thumbnail && thumbnailURL && !privacy) ? Assets.Logo : thumbnailURL; if (!video.paused) { const timestamps = presence.getTimestamps(video.currentTime, video.duration); presenceData.smallImageKey = Assets.Play; - presenceData.startTimestamp = timestamps[0]; - presenceData.endTimestamp = timestamps[1]; + if (!privacy) { + presenceData.startTimestamp = timestamps[0]; + presenceData.endTimestamp = timestamps[1]; + } } else { presenceData.smallImageKey = Assets.Pause; delete presenceData.startTimestamp; From 29eac85384cbe3f9248dcf713a2ee8acadc69166 Mon Sep 17 00:00:00 2001 From: yuri Date: Sat, 28 Dec 2024 20:58:02 +0000 Subject: [PATCH 03/10] fix(Sflix): correct large image key assignment based on privacy setting --- websites/S/Sflix/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index 24c004f1869f..8adae6e5476d 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -58,7 +58,7 @@ presence.on("UpdateData", async () => { presenceData.details = privacy ? "Watching" : `${showTitle}`; presenceData.state = privacy ? "" : `${document.querySelector(".on-air div h3")?.textContent || ""}`; - presenceData.largeImageKey = (thumbnail && thumbnailURL && !privacy) ? Assets.Logo : thumbnailURL; + presenceData.largeImageKey = (thumbnail && thumbnailURL && !privacy) ? thumbnailURL : Assets.Logo; if (!video.paused) { From 774084fe8cb24d4a150c1d90f6d1fadff23a890e Mon Sep 17 00:00:00 2001 From: yuri Date: Sat, 28 Dec 2024 21:00:25 +0000 Subject: [PATCH 04/10] fix(Sflix): context on small image --- websites/S/Sflix/presence.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index 8adae6e5476d..dc4efd743f4d 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -34,7 +34,8 @@ presence.on("UpdateData", async () => { switch (variables.currPage) { case "": { presenceData.details = "Searching"; - presenceData.smallImageKey = Assets.Search; + presenceData.smallImageKey = Assets.Search; + presenceData.smallImageText = "Searching"; presenceData.state = privacy ? "" : `${document.querySelector("h2[class*='cat-heading']").textContent.split('"')[1] || document.querySelector("h2[class*='cat-heading']").textContent}`; break; } @@ -43,12 +44,14 @@ presence.on("UpdateData", async () => { presenceData.details = "Browsing"; presenceData.state = "Home"; presenceData.smallImageKey = Assets.Reading; + presenceData.smallImageText = "Browsing"; break; } case "detail": { presenceData.details = "Browsing"; presenceData.state = privacy ? "" : document.querySelector(".heading-name")?.textContent; presenceData.smallImageKey = Assets.Reading; + presenceData.smallImageText = "Browsing"; break; } case "watch": { @@ -64,12 +67,14 @@ presence.on("UpdateData", async () => { if (!video.paused) { const timestamps = presence.getTimestamps(video.currentTime, video.duration); presenceData.smallImageKey = Assets.Play; + presenceData.smallImageText = "Playing"; if (!privacy) { presenceData.startTimestamp = timestamps[0]; presenceData.endTimestamp = timestamps[1]; } } else { presenceData.smallImageKey = Assets.Pause; + presenceData.smallImageText = "Paused"; delete presenceData.startTimestamp; delete presenceData.endTimestamp; } From 81580ba71e8c5077352c76390bc27bee7c529ea1 Mon Sep 17 00:00:00 2001 From: yuri Date: Sat, 28 Dec 2024 21:22:28 +0000 Subject: [PATCH 05/10] refactor(Sflix): prettier refactor --- websites/S/Sflix/presence.ts | 62 +++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index dc4efd743f4d..d9d408a8a606 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -13,30 +13,38 @@ let video = { paused: true, }; -presence.on("iFrameData", (data: { duration: number, currentTime: number, paused: boolean }) => { - video = data; -}); +presence.on( + "iFrameData", + (data: { duration: number; currentTime: number; paused: boolean }) => { + video = data; + } +); presence.on("UpdateData", async () => { const presenceData: PresenceData = { - largeImageKey: Assets.Logo, - type: ActivityType.Watching, - startTimestamp: browsingTimestamp, - }, - - [ thumbnail, privacy ] = await Promise.all([ - presence.getSetting("thumbnail"), - presence.getSetting("privacy"), - ]), - - variables = await presence.getPageVariable("currPage"); + largeImageKey: Assets.Logo, + type: ActivityType.Watching, + startTimestamp: browsingTimestamp, + }, + [thumbnail, privacy] = await Promise.all([ + presence.getSetting("thumbnail"), + presence.getSetting("privacy"), + ]), + variables = await presence.getPageVariable("currPage"); switch (variables.currPage) { case "": { presenceData.details = "Searching"; presenceData.smallImageKey = Assets.Search; presenceData.smallImageText = "Searching"; - presenceData.state = privacy ? "" : `${document.querySelector("h2[class*='cat-heading']").textContent.split('"')[1] || document.querySelector("h2[class*='cat-heading']").textContent}`; + presenceData.state = privacy + ? "" + : `${ + document + .querySelector("h2[class*='cat-heading']") + .textContent.split('"')[1] || + document.querySelector("h2[class*='cat-heading']").textContent + }`; break; } case "home_search": @@ -49,23 +57,31 @@ presence.on("UpdateData", async () => { } case "detail": { presenceData.details = "Browsing"; - presenceData.state = privacy ? "" : document.querySelector(".heading-name")?.textContent; + presenceData.state = privacy + ? "" + : document.querySelector(".heading-name")?.textContent; presenceData.smallImageKey = Assets.Reading; presenceData.smallImageText = "Browsing"; break; } case "watch": { - const showTitle = document.querySelector(".heading-name").textContent, - thumbnailURL = document.querySelector(`img[title*="${showTitle}"]`)?.getAttribute("src"); - + thumbnailURL = document + .querySelector(`img[title*="${showTitle}"]`) + ?.getAttribute("src"); + presenceData.details = privacy ? "Watching" : `${showTitle}`; - presenceData.state = privacy ? "" : `${document.querySelector(".on-air div h3")?.textContent || ""}`; - presenceData.largeImageKey = (thumbnail && thumbnailURL && !privacy) ? thumbnailURL : Assets.Logo; - + presenceData.state = privacy + ? "" + : `${document.querySelector(".on-air div h3")?.textContent || ""}`; + presenceData.largeImageKey = + thumbnail && thumbnailURL && !privacy ? thumbnailURL : Assets.Logo; if (!video.paused) { - const timestamps = presence.getTimestamps(video.currentTime, video.duration); + const timestamps = presence.getTimestamps( + video.currentTime, + video.duration + ); presenceData.smallImageKey = Assets.Play; presenceData.smallImageText = "Playing"; if (!privacy) { From 7b2c57a6f80abcbca9c47226d6d6f1fd26bd4464 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=BAri=20Neves?= <60155360+iuriineves@users.noreply.github.com> Date: Mon, 30 Dec 2024 00:19:33 +0000 Subject: [PATCH 06/10] refactor: remove unnecessary comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Daniel Lau <32113157+theusaf@users.noreply.github.com> Signed-off-by: Iúri Neves <60155360+iuriineves@users.noreply.github.com> --- websites/S/Sflix/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index d9d408a8a606..82b855f55887 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -3,7 +3,7 @@ const presence = new Presence({ }), browsingTimestamp = Math.floor(Date.now() / 1000); -const enum Assets { // Other default assets can be found at index.d.ts +const enum Assets { Logo = "https://img.sflix2.to/xxrz/400x400/100/66/35/66356c25ce98cb12993249e21742b129/66356c25ce98cb12993249e21742b129.png", } From dc87d97d18ff88ac96f8ffd69e7f8e18a20177cc Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 30 Dec 2024 01:49:19 +0000 Subject: [PATCH 07/10] fix: update logo URL to 512x512 image source --- websites/S/Sflix/metadata.json | 2 +- websites/S/Sflix/presence.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/websites/S/Sflix/metadata.json b/websites/S/Sflix/metadata.json index 76ebc11d389d..310ac71f4d90 100644 --- a/websites/S/Sflix/metadata.json +++ b/websites/S/Sflix/metadata.json @@ -14,7 +14,7 @@ "enorme.tv" ], "version": "1.0.0", - "logo": "https://img.sflix2.to/xxrz/400x400/100/66/35/66356c25ce98cb12993249e21742b129/66356c25ce98cb12993249e21742b129.png", + "logo": "https://imgur.com/u3xBsLk.png", "thumbnail": "https://img.sflix.to/xxrz/1300x700/100/8e/5a/8e5afb7b78cfcb3c3667504fd5830a0f/8e5afb7b78cfcb3c3667504fd5830a0f.jpeg", "color": "#03abb8", "category": "videos", diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index 82b855f55887..fa22652d1196 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -4,7 +4,7 @@ const presence = new Presence({ browsingTimestamp = Math.floor(Date.now() / 1000); const enum Assets { - Logo = "https://img.sflix2.to/xxrz/400x400/100/66/35/66356c25ce98cb12993249e21742b129/66356c25ce98cb12993249e21742b129.png", + Logo = "https://imgur.com/u3xBsLk.png", } let video = { From f627d4de242eed92dce6281ad8dd456bc6e37226 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=BAri=20Neves?= <60155360+iuriineves@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:55:13 +0000 Subject: [PATCH 08/10] fix: remove unnecessary template literal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: github plz bring back DarkVIllager Signed-off-by: Iúri Neves <60155360+iuriineves@users.noreply.github.com> --- websites/S/Sflix/presence.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index fa22652d1196..258b76b5735c 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -39,12 +39,12 @@ presence.on("UpdateData", async () => { presenceData.smallImageText = "Searching"; presenceData.state = privacy ? "" - : `${ + : document .querySelector("h2[class*='cat-heading']") .textContent.split('"')[1] || document.querySelector("h2[class*='cat-heading']").textContent - }`; + break; } case "home_search": From d268dbd3980058d68a5c1b74ee0db184d944f3c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=BAri=20Neves?= <60155360+iuriineves@users.noreply.github.com> Date: Mon, 30 Dec 2024 14:57:14 +0000 Subject: [PATCH 09/10] fix: remove unnecessary template literal and use nullish operator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: github plz bring back DarkVIllager Signed-off-by: Iúri Neves <60155360+iuriineves@users.noreply.github.com> --- websites/S/Sflix/presence.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index 258b76b5735c..21533bb6b280 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -73,7 +73,7 @@ presence.on("UpdateData", async () => { presenceData.details = privacy ? "Watching" : `${showTitle}`; presenceData.state = privacy ? "" - : `${document.querySelector(".on-air div h3")?.textContent || ""}`; + : {document.querySelector(".on-air div h3")?.textContent ?? "" presenceData.largeImageKey = thumbnail && thumbnailURL && !privacy ? thumbnailURL : Assets.Logo; From cc87f46b673c2787b6f01db294d0459cda210c69 Mon Sep 17 00:00:00 2001 From: yuri Date: Mon, 30 Dec 2024 18:21:14 +0000 Subject: [PATCH 10/10] fix: simplify presence timestamp assignment --- websites/S/Sflix/presence.ts | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/websites/S/Sflix/presence.ts b/websites/S/Sflix/presence.ts index 21533bb6b280..c340c1eb1dc8 100644 --- a/websites/S/Sflix/presence.ts +++ b/websites/S/Sflix/presence.ts @@ -39,12 +39,11 @@ presence.on("UpdateData", async () => { presenceData.smallImageText = "Searching"; presenceData.state = privacy ? "" - : - document - .querySelector("h2[class*='cat-heading']") - .textContent.split('"')[1] || - document.querySelector("h2[class*='cat-heading']").textContent - + : document + .querySelector("h2[class*='cat-heading']") + .textContent.split('"')[1] || + document.querySelector("h2[class*='cat-heading']").textContent; + break; } case "home_search": @@ -73,21 +72,17 @@ presence.on("UpdateData", async () => { presenceData.details = privacy ? "Watching" : `${showTitle}`; presenceData.state = privacy ? "" - : {document.querySelector(".on-air div h3")?.textContent ?? "" + : document.querySelector(".on-air div h3")?.textContent ?? ""; presenceData.largeImageKey = thumbnail && thumbnailURL && !privacy ? thumbnailURL : Assets.Logo; if (!video.paused) { - const timestamps = presence.getTimestamps( - video.currentTime, - video.duration - ); - presenceData.smallImageKey = Assets.Play; - presenceData.smallImageText = "Playing"; if (!privacy) { - presenceData.startTimestamp = timestamps[0]; - presenceData.endTimestamp = timestamps[1]; + [presenceData.startTimestamp, presenceData.endTimestamp] = + presence.getTimestamps(video.currentTime, video.duration); } + presenceData.smallImageKey = Assets.Play; + presenceData.smallImageText = "Playing"; } else { presenceData.smallImageKey = Assets.Pause; presenceData.smallImageText = "Paused";