-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
iuriineves
wants to merge
13
commits into
PreMiD:main
Choose a base branch
from
iuriineves:Sflix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+152
−0
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
3267169
feat(Sflix): add presence (#5305)
iuriineves 2f71507
feat(Sflix): add privacy setting
iuriineves 29eac85
fix(Sflix): correct large image key assignment based on privacy setting
iuriineves 774084f
fix(Sflix): context on small image
iuriineves 81580ba
refactor(Sflix): prettier refactor
iuriineves 534f5db
Merge branch 'main' into Sflix
iuriineves 7b2c57a
refactor: remove unnecessary comment
iuriineves dc87d97
fix: update logo URL to 512x512 image source
iuriineves 7363702
Merge branch 'main' into Sflix
iuriineves f627d4d
fix: remove unnecessary template literal
iuriineves d268dbd
fix: remove unnecessary template literal and use nullish operator
iuriineves cc87f46
fix: simplify presence timestamp assignment
iuriineves e352c69
Merge branch 'main' into Sflix
iuriineves File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": ".*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
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; | ||
|
||
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) { | ||
if (!privacy) { | ||
[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"; | ||
delete presenceData.startTimestamp; | ||
delete presenceData.endTimestamp; | ||
} | ||
break; | ||
} | ||
} | ||
presence.setActivity(presenceData); | ||
}); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?