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 (#5305) #9027

Closed
wants to merge 5 commits into from
Closed
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
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://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
},
{
"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

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
}
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 { // 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, 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
}`;
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 || ""}`;
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];
}
} else {
presenceData.smallImageKey = Assets.Pause;
presenceData.smallImageText = "Paused";
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
break;
}
}
presence.setActivity(presenceData);
});
Loading