From 406b0c27ed64663f44938ccea512cb15d4d434ed Mon Sep 17 00:00:00 2001 From: Kuriel <37979213+Kuriel23@users.noreply.github.com> Date: Fri, 17 Jan 2025 20:52:58 +0000 Subject: [PATCH] feat(Pi Fansubs): add activity --- websites/P/Pi Fansubs/iframe.ts | 22 ++++ websites/P/Pi Fansubs/metadata.json | 29 +++++ websites/P/Pi Fansubs/presence.ts | 175 ++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+) create mode 100644 websites/P/Pi Fansubs/iframe.ts create mode 100644 websites/P/Pi Fansubs/metadata.json create mode 100644 websites/P/Pi Fansubs/presence.ts diff --git a/websites/P/Pi Fansubs/iframe.ts b/websites/P/Pi Fansubs/iframe.ts new file mode 100644 index 000000000000..d396fb96ba9a --- /dev/null +++ b/websites/P/Pi Fansubs/iframe.ts @@ -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, + }, + }); + } +}); + diff --git a/websites/P/Pi Fansubs/metadata.json b/websites/P/Pi Fansubs/metadata.json new file mode 100644 index 000000000000..02dbe4c229a9 --- /dev/null +++ b/websites/P/Pi Fansubs/metadata.json @@ -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" +} \ No newline at end of file diff --git a/websites/P/Pi Fansubs/presence.ts b/websites/P/Pi Fansubs/presence.ts new file mode 100644 index 000000000000..8b946681534e --- /dev/null +++ b/websites/P/Pi Fansubs/presence.ts @@ -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(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); +});