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(Sflix): add presence #9029

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
12 changes: 12 additions & 0 deletions websites/S/Sflix/iframe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const iframe = new iFrame();

iframe.on("UpdateData", async () => {
const video = document.querySelector<HTMLVideoElement>("video");
if (!isNaN(video?.duration)) {
iframe.send({
duration: video.duration,
currentTime: video.currentTime,
paused: video.paused,
});
}
});
44 changes: 44 additions & 0 deletions websites/S/Sflix/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"$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://imgur.com/u3xBsLk.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
},
{
"id": "privacy",
"title": "Privacy",
"icon": "fad fa-user-secret",
"value": false
}
],
"iframe": true,
"iFrameRegExp": ".*"

Check warning on line 43 in websites/S/Sflix/metadata.json

View workflow job for this annotation

GitHub Actions / Presence Validator

Presence (Sflix) has metadata.iFrameRegExp set to '.*', please change this if possible
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you able to make the regex more narrow?

}
101 changes: 101 additions & 0 deletions websites/S/Sflix/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const presence = new Presence({
clientId: "1322565714128797798",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://imgur.com/u3xBsLk.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, privacy] = await Promise.all([
presence.getSetting<boolean>("thumbnail"),
presence.getSetting<boolean>("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
}`;
iuriineves marked this conversation as resolved.
Show resolved Hide resolved
break;
}
case "home_search":
case "home": {
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": {
const showTitle = document.querySelector(".heading-name").textContent,
thumbnailURL = document
.querySelector(`img[title*="${showTitle}"]`)
?.getAttribute("src");

presenceData.details = privacy ? "Watching" : `${showTitle}`;
presenceData.state = privacy
? ""
: `${document.querySelector(".on-air div h3")?.textContent || ""}`;
iuriineves marked this conversation as resolved.
Show resolved Hide resolved
presenceData.largeImageKey =
thumbnail && thumbnailURL && !privacy ? thumbnailURL : Assets.Logo;

if (!video.paused) {
const timestamps = presence.getTimestamps(
video.currentTime,
video.duration
iuriineves marked this conversation as resolved.
Show resolved Hide resolved
);
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = "Playing";
if (!privacy) {
presenceData.startTimestamp = timestamps[0];
presenceData.endTimestamp = timestamps[1];
}
iuriineves marked this conversation as resolved.
Show resolved Hide resolved
} else {
presenceData.smallImageKey = Assets.Pause;
presenceData.smallImageText = "Paused";
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
break;
}
}
presence.setActivity(presenceData);
});
Loading