Skip to content

Commit

Permalink
feat(FMovies): add presence (PreMiD#5823)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys <64903135+EncryptedDev@users.noreply.github.com>
  • Loading branch information
kyrie25 and EncryptedDev authored Feb 17, 2022
1 parent d839088 commit 1c08eb4
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
33 changes: 33 additions & 0 deletions websites/F/FMovies/dist/metadata.json
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
}
]
}
12 changes: 12 additions & 0 deletions websites/F/FMovies/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({
currTime: video.currentTime,
duration: video.duration,
paused: video.paused
});
}
});
100 changes: 100 additions & 0 deletions websites/F/FMovies/presence.ts
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);
});
6 changes: 6 additions & 0 deletions websites/F/FMovies/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "dist"
}
}

0 comments on commit 1c08eb4

Please sign in to comment.