forked from PreMiD/Presences
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(FMovies): add presence (PreMiD#5823)
Co-authored-by: Rhys <64903135+EncryptedDev@users.noreply.github.com>
- Loading branch information
1 parent
d839088
commit 1c08eb4
Showing
4 changed files
with
151 additions
and
0 deletions.
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,33 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.6", | ||
"author": { | ||
"name": "Kyrie", | ||
"id": "368399721494216706" | ||
}, | ||
"service": "FMovies", | ||
"description": { | ||
"en": "Watch online movies for free, watch movies free in high quality without registration. Just a better place for watching online movies for free. Fmovies.to, FFmovies.is, FFmovies.to" | ||
}, | ||
"url": "fmovies.to", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/gnXTraq.png", | ||
"thumbnail": "https://i.imgur.com/j7RpmBJ.jpeg", | ||
"color": "#1BB3C6", | ||
"category": "videos", | ||
"tags": ["movies", "stream"], | ||
"iframe": true, | ||
"settings": [ | ||
{ | ||
"id": "image", | ||
"title": "Show Images", | ||
"icon": "fad fa-images", | ||
"value": true | ||
}, | ||
{ | ||
"id": "buttons", | ||
"title": "Show Buttons", | ||
"icon": "fas fa-compress-arrows-alt", | ||
"value": true | ||
} | ||
] | ||
} |
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({ | ||
currTime: video.currentTime, | ||
duration: video.duration, | ||
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,100 @@ | ||
const presence = new Presence({ | ||
clientId: "943521983730171966" | ||
}), | ||
browsingTimestamp = Math.floor(Date.now() / 1000); | ||
|
||
let iFrameData: { | ||
currTime: number; | ||
duration: number; | ||
paused: boolean; | ||
} = null; | ||
|
||
presence.on( | ||
"iFrameData", | ||
(data: { currTime: number; duration: number; paused: boolean }) => { | ||
iFrameData = data; | ||
} | ||
); | ||
|
||
presence.on("UpdateData", async () => { | ||
const presenceData: PresenceData = { | ||
startTimestamp: browsingTimestamp, | ||
largeImageKey: "logo" | ||
}, | ||
{ pathname } = document.location, | ||
[buttons, image] = await Promise.all([ | ||
presence.getSetting<boolean>("buttons"), | ||
presence.getSetting<boolean>("image") | ||
]); | ||
|
||
if (pathname === "/home") presenceData.details = "Browsing"; | ||
else if (pathname.startsWith("/series/")) { | ||
const title = document.querySelector<HTMLHeadingElement>( | ||
"#watch > div.container > div.watch-extra > div.bl-1 > section.info > div.info > h1" | ||
), | ||
season = document.querySelector<HTMLSpanElement>(".value"), | ||
episode = document.querySelector<HTMLAnchorElement>("a.active"); | ||
if (title) presenceData.details = title.textContent; | ||
if (season) { | ||
presenceData.state = season.textContent.split("-")[0].trim(); | ||
if (episode) presenceData.state += ` - ${episode.textContent.trim()}`; | ||
} | ||
if (image) { | ||
presenceData.largeImageKey = document | ||
.querySelector("meta[property='og:image']") | ||
.getAttribute("content"); | ||
} | ||
if (!iFrameData?.paused) { | ||
[, presenceData.endTimestamp] = presence.getTimestamps( | ||
iFrameData.currTime, | ||
iFrameData.duration | ||
); | ||
presenceData.smallImageKey = "play"; | ||
} else presenceData.smallImageKey = "pause"; | ||
if (buttons) { | ||
presenceData.buttons = [ | ||
{ | ||
label: "Watch Series", | ||
url: document.location.href | ||
} | ||
]; | ||
} | ||
} else if (pathname.startsWith("/movie/")) { | ||
const title = document.querySelector<HTMLHeadingElement>( | ||
"#watch > div.container > div.watch-extra > div.bl-1 > section.info > div.info > h1" | ||
); | ||
if (title) presenceData.details = title.textContent; | ||
if (image) { | ||
presenceData.largeImageKey = document | ||
.querySelector("meta[property='og:image']") | ||
.getAttribute("content"); | ||
} | ||
if (iFrameData && !iFrameData.paused) { | ||
[, presenceData.endTimestamp] = presence.getTimestamps( | ||
iFrameData.currTime, | ||
iFrameData.duration | ||
); | ||
presenceData.smallImageKey = "play"; | ||
} else presenceData.smallImageKey = "pause"; | ||
if (buttons) { | ||
presenceData.buttons = [ | ||
{ | ||
label: "Watch Movie", | ||
url: document.location.href | ||
} | ||
]; | ||
} | ||
} else if (pathname === "/user/profile") | ||
presenceData.details = "Checking Profile"; | ||
else if (pathname === "/user/watchlist") | ||
presenceData.details = "Checking Watchlist"; | ||
else { | ||
const genre = document.querySelector<HTMLHeadingElement>("section.bl h1"); | ||
if (genre) { | ||
presenceData.details = genre.textContent; | ||
presenceData.smallImageKey = "search"; | ||
} | ||
} | ||
|
||
presence.setActivity(presenceData); | ||
}); |
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,6 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"compilerOptions": { | ||
"outDir": "dist" | ||
} | ||
} |