Skip to content
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(P-Stream): Add presence #9254

Closed
wants to merge 11 commits into from
29 changes: 29 additions & 0 deletions websites/P/P-Stream/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://schemas.premid.app/metadata/1.13",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"apiVersion": 1,

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"author": {

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"id": "529707020937461760",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
"name": "creeper78"

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
},

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"service": "P-Stream",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"altnames": [

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"PStream"

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
],

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"description": {

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"en": "Watch your favorite shows and movies for free with no ads ever!"

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
},

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"url": "pstream.org",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"version": "1.0.0",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"logo": "https://i.imgur.com/vnX1akB.png",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"thumbnail": "https://i.imgur.com/r1EF7gX.png",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"color": "#8652bb",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"category": "videos",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"tags": [

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
"movie",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
"tv",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
"watch",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
"stream",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
"pstream",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
"p-stream"

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
]

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
}
113 changes: 113 additions & 0 deletions websites/P/P-Stream/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
const presence = new Presence({
clientId: "1337272344800002129",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.

Check failure

Code scanning / ESLint

Enforce the consistent use of either backticks, double, or single quotes Error

Strings must use singlequote.
}),

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
browsingTimestamp = Math.floor(Date.now() / 1000);

Check failure

Code scanning / ESLint

Enforce variables to be declared either together or separately in functions Error

Split initialized 'const' declarations into multiple statements.

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.

Check failure

Code scanning / ESLint

Require or disallow semicolons instead of ASI Error

Extra semicolon.

const enum Assets {
Logo = "https://i.imgur.com/vnX1akB.png",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.

Check failure

Code scanning / ESLint

Enforce the consistent use of either backticks, double, or single quotes Error

Strings must use singlequote.
}

Check failure

Code scanning / ESLint

Disallow specified syntax Error

Using 'TSEnumDeclaration[const=true]' is not allowed.

const cache = new Map<string, Record<string, unknown>>();

Check failure

Code scanning / ESLint

Require or disallow semicolons instead of ASI Error

Extra semicolon.

interface TMDBResponse {
backdropPath?: string;

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.

Check failure

Code scanning / ESLint

Require a specific member delimiter style for interfaces and type literals Error

Unexpected separator (;).
[key: string]: unknown;

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.

Check failure

Code scanning / ESLint

Require a specific member delimiter style for interfaces and type literals Error

Unexpected separator (;).
}

async function fetchWithCache(url: string): Promise<TMDBResponse | null> {
if (cache.has(url)) return cache.get(url) as TMDBResponse;

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.

Check failure

Code scanning / ESLint

Newline after if Error

Expect newline after if

Check failure

Code scanning / ESLint

Require or disallow semicolons instead of ASI Error

Extra semicolon.

try {

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 2 spaces but found 1 tab.
const res = await fetch(url, {

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.
method: "GET",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 6 spaces but found 3 tabs.

Check failure

Code scanning / ESLint

Enforce the consistent use of either backticks, double, or single quotes Error

Strings must use singlequote.
headers: {

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 6 spaces but found 3 tabs.
accept: "application/json",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 8 spaces but found 4 tabs.

Check failure

Code scanning / ESLint

Enforce the consistent use of either backticks, double, or single quotes Error

Strings must use singlequote.
Authorization:

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 8 spaces but found 4 tabs.
"Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhNTAwMDQ5ZjNlMDYxMDlmZTNlODI4OWIwNmNmNTY4NSIsInN1YiI6IjY1ZTEyNDAyMmQ1MzFhMDE4NWMwZjJmNSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.1J3EfnfmpJyZ4MV66eadk3h929zdeZfvjTO2JXhboWw",

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce the consistent use of either backticks, double, or single quotes Error

Strings must use singlequote.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a private api key?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The API is free doesn't really matter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a private api key?

It's the same the website itself uses lol. 🤷‍♂️

},

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 6 spaces but found 3 tabs.
});

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

Check failure

Code scanning / ESLint

Enforce consistent indentation Error

Expected indentation of 4 spaces but found 2 tabs.

Check failure

Code scanning / ESLint

Require or disallow semicolons instead of ASI Error

Extra semicolon.

if (!res.ok) return null;

Check failure

Code scanning / ESLint

Disallow all tabs Error

Unexpected tab character.

const data = (await res.json()) as Record<string, unknown>,
formattedData: TMDBResponse = {
backdropPath:
typeof data.backdrop_path === "string" ? data.backdrop_path : null,
};

cache.set(url, formattedData);
return formattedData;
} catch (error) {
return null;
}
}

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: Assets.Logo,
type: ActivityType.Watching,
startTimestamp: browsingTimestamp,
};

switch (document.location.pathname) {
case "/":
presenceData.details = "Browsing...";
break;
case "/settings":
presenceData.details = "Configuring Settings";
break;
case "/discover":
presenceData.details = "Discovering what's new";
break;
case "/about":
presenceData.details = "Reading about P-Stream";
break;
case "/support":
presenceData.details = "Getting support";
break;
default:
if (document.location.pathname.startsWith("/media/tmdb-tv-")) {
const showId = document.location.href
.replace("https://pstream.org/media/tmdb-tv-", "")
.split("-")[0];
if (showId) {
const data = await fetchWithCache(
`https://api.themoviedb.org/3/tv/${showId}`
);
if (data?.backdropPath)
presenceData.largeImageKey = `https://image.tmdb.org/t/p/original${data.backdropPath}`;
}
presenceData.details =
document.querySelector("title")?.textContent?.split(" - ")[0] ?? "";
presenceData.state =
document
.querySelector("title")
?.textContent?.split(" - ")
.slice(1)
.join(" - ") ?? "";
} else if (document.location.pathname.startsWith("/media/tmdb-movie-")) {
const movieId = document.location.href
.replace("https://pstream.org/media/tmdb-movie-", "")
.split("-")[0];
if (movieId) {
const data = await fetchWithCache(
`https://api.themoviedb.org/3/movie/${movieId}`
);
if (data?.backdropPath)
presenceData.largeImageKey = `https://image.tmdb.org/t/p/original${data.backdropPath}`;
}
presenceData.details = document.querySelector("title")?.textContent;
}
}

const video = document.querySelector("video");
if (video) {
if (!video.paused) {
[presenceData.startTimestamp, presenceData.endTimestamp] =
presence.getTimestampsfromMedia(video);
presenceData.smallImageKey = Assets.Play;
} else presenceData.smallImageKey = Assets.Pause;
}

presence.setActivity(presenceData);
});
Loading