Skip to content

Commit

Permalink
feat(Pi Fansubs): add activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuriel23 committed Jan 17, 2025
1 parent ed5f058 commit 406b0c2
Show file tree
Hide file tree
Showing 3 changed files with 226 additions and 0 deletions.
22 changes: 22 additions & 0 deletions websites/P/Pi Fansubs/iframe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const iframe = new iFrame();

iframe.on("UpdateData", async () => {
let video: HTMLVideoElement;

if (document.querySelector(".jw-video"))
video = document.querySelector(".jw-video");
else if (document.querySelector(".html5-video-container"))
video = document.querySelector(".html5-video-container > video");

if (video && !isNaN(video.duration)) {
iframe.send({
iframeVideo: {
iFrameVideo: true,
currTime: video.currentTime,
dur: video.duration,
paused: video.paused,
},
});
}
});

Check failure on line 22 in websites/P/Pi Fansubs/iframe.ts

View workflow job for this annotation

GitHub Actions / Compile and Lint

Too many blank lines at the end of file. Max of 0 allowed
29 changes: 29 additions & 0 deletions websites/P/Pi Fansubs/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://schemas.premid.app/metadata/1.12",
"apiVersion": 1,
"author": {
"id": "354233941550694400",
"name": "kuriel."
},
"service": "Pi Fansubs",
"description": {
"en": "PiFansubs is a free brazilian streaming site where you can watch subtitled bls content.",
"pt": "PiFansubs é um site de streaming gratuito onde você pode assistir a conteúdos bls legendados.",
"pt_BR": "PiFansubs é um site de streaming gratuito onde você pode assistir a conteúdos bls legendados."
},
"url": [
"pifansubs.club",
"www.pifansubs.club"
],
"version": "1.0.0",
"logo": "https://i.imgur.com/RNFFxad.jpeg",
"thumbnail": "https://i.imgur.com/sGD1G3v.png",
"color": "#00be08",
"category": "videos",
"tags": [
"series",
"movies"
],
"iframe": true,
"iFrameRegExp": "blsplayer[.]com|csst[.]online|pifansubs[.]club"
}
175 changes: 175 additions & 0 deletions websites/P/Pi Fansubs/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
const presence = new Presence({
clientId: "1329883342132351058",
}),
strings = presence.getStrings({
playing: "general.playing",
paused: "general.paused",
searchFor: "general.searchFor",
viewHome: "general.viewHome",
viewGenre: "general.viewGenre",
viewPage: "general.viewPage",
viewSeries: "general.viewSeries",
viewMovie: "general.viewMovie",
buttonViewSeries: "general.buttonViewSeries",
buttonViewEpisode: "general.buttonViewEpisode",
buttonWatchMovie: "general.buttonWatchMovie",
viewCategory: "general.viewCategory",
}),
browsingTimestamp = Math.floor(Date.now() / 1000);

const enum Assets {
Logo = "https://i.imgur.com/RNFFxad.jpeg",
}

let iFrameVideo: boolean, currentTime: number, duration: number;

interface IFrameData {
iframeVideo: {
iFrameVideo: boolean;
currTime: number;
dur: number | null;
};
}

presence.on("iFrameData", (data: IFrameData) => {
if (data.iframeVideo.dur) {
({ iFrameVideo } = data.iframeVideo);
currentTime = data.iframeVideo.currTime;
duration = data.iframeVideo.dur;
}
});

function textContent(tags: string) {
return document.querySelector(tags)?.textContent?.trim();
}

function getImage(tags: string) {
return document.querySelector<HTMLImageElement>(tags)?.src ?? Assets.Logo;
}

presence.on("UpdateData", async () => {
const { pathname, href, search } = document.location,
path = pathname.split("/"),
presenceData: PresenceData = {
largeImageKey: Assets.Logo,
startTimestamp: browsingTimestamp,
details: (await strings).viewHome,
type: ActivityType.Watching,
};

switch (path[1]) {
case "release": {
presenceData.details = "Vendo lançamentos de:";
presenceData.state = textContent(".heading-archive");
break;
}
case "genre": {
presenceData.details = (await strings).viewGenre;
presenceData.state = textContent(".heading-archive");
break;
}
case "series-de-tv": {
if (path[2] && path[2] !== "page") {
presenceData.details = (await strings).viewSeries;
presenceData.state = textContent(
".sheader > div:nth-child(2) > h1:nth-child(1)"
);
presenceData.largeImageKey = getImage(".poster > img:nth-child(1)");
presenceData.buttons = [
{
label: (await strings).buttonViewSeries,
url: href,
},
];
} else presenceData.details = "Explorando Séries";
break;
}
case "filmes": {
if (path[2] && path[2] !== "page") {
presenceData.details = (await strings).viewMovie;
presenceData.state = textContent(
".sheader > div:nth-child(2) > h1:nth-child(1)"
);
presenceData.largeImageKey = getImage(".poster > img:nth-child(1)");
if (iFrameVideo && !isNaN(duration)) {
[presenceData.startTimestamp, presenceData.endTimestamp] =
presence.getTimestamps(
Math.floor(currentTime),
Math.floor(duration)
);
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = (await strings).playing;
} else {
presenceData.smallImageKey = Assets.Pause;
presenceData.smallImageText = (await strings).paused;
}
presenceData.buttons = [
{
label: (await strings).buttonWatchMovie,
url: href,
},
];
} else presenceData.details = "Explorando Filmes";
break;
}
case "episodios": {
if (path[2] && path[2] !== "page") {
const match = textContent(".epih1").match(/(\d+)x(\d+)/);

presenceData.details = (await strings).viewSeries;
presenceData.state = textContent(".epih1").replace(/: (\d+)x(\d+)/, "");
presenceData.largeImageKey = getImage(
".mark-1 > div:nth-child(1) > img:nth-child(1)"
);
presenceData.largeImageText = match
? `Season ${match[1]}, Episode ${match[2]}`
: textContent(".epih1");
if (iFrameVideo && !isNaN(duration)) {
[presenceData.startTimestamp, presenceData.endTimestamp] =
presence.getTimestamps(
Math.floor(currentTime),
Math.floor(duration)
);
presenceData.smallImageKey = Assets.Play;
presenceData.smallImageText = (await strings).playing;
} else {
presenceData.smallImageKey = Assets.Pause;
presenceData.smallImageText = (await strings).paused;
}
presenceData.buttons = [
{
label: (await strings).buttonViewEpisode,
url: href,
},
];
} else presenceData.details = "Explorando Episódios";
break;
}
case "avisos-e-informacoes": {
presenceData.details = (await strings).viewPage;
presenceData.state = "Avisos";
break;
}
case "category": {
presenceData.details = (await strings).viewCategory;
presenceData.state = textContent(
".content > header:nth-child(1) > h1:nth-child(1)"
).replace("Category Archives: ", "");
break;
}
default: {
if (search) {
presenceData.details = (await strings).searchFor;
presenceData.state = decodeURI(search.split("=")[1]).replaceAll(
"+",
" "
);
} else if (path[1].length >= 1) {
presenceData.details = (await strings).viewPage;
presenceData.state = textContent(".titl");
}
break;
}
}
presence.setActivity(presenceData);
});

0 comments on commit 406b0c2

Please sign in to comment.