-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Closed
Changes from 10 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
658d716
P-Stream create presence
moyaimoment 21d1149
Forgot to remove iFrame stuff after testing.
moyaimoment 27a2c35
No spam API and add video timestamping.
moyaimoment 2d7911a
DeepScan
moyaimoment b2e9318
window > document
moyaimoment 6bc2c3e
Better "thumbnail" photo.
moyaimoment 78741ff
Merge branch 'main' into PStream-create-presence
moyaimoment e24bac8
Modernize metadata.json
moyaimoment bc396e9
Modernize presence.ts
moyaimoment dd82096
Merge branch 'main' into PStream-create-presence
Timeraa eb5eb4d
Merge branch 'main' into PStream-create-presence
moyaimoment File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,29 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.13", | ||
"apiVersion": 1, | ||
"author": { | ||
"id": "529707020937461760", | ||
"name": "creeper78" | ||
}, | ||
"service": "P-Stream", | ||
"altnames": [ | ||
"PStream" | ||
], | ||
"description": { | ||
"en": "Watch your favorite shows and movies for free with no ads ever!" | ||
}, | ||
"url": "pstream.org", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/vnX1akB.png", | ||
"thumbnail": "https://i.imgur.com/nQgvTaq.png", | ||
"color": "#8652bb", | ||
"category": "videos", | ||
"tags": [ | ||
"movie", | ||
"tv", | ||
"watch", | ||
"stream", | ||
"pstream", | ||
"p-stream" | ||
] | ||
} |
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,114 @@ | ||
import { ActivityType, Assets } from 'premid' | ||
|
||
const presence = new Presence({ | ||
clientId: '1337272344800002129', | ||
}) | ||
const browsingTimestamp = Math.floor(Date.now() / 1000) | ||
|
||
const cache = new Map<string, Record<string, unknown>>() | ||
|
||
interface TMDBResponse { | ||
backdropPath?: string | ||
[key: string]: unknown | ||
} | ||
|
||
async function fetchWithCache(url: string): Promise<TMDBResponse | null> { | ||
if (cache.has(url)) | ||
return cache.get(url) as TMDBResponse | ||
|
||
try { | ||
const res = await fetch(url, { | ||
method: 'GET', | ||
headers: { | ||
accept: 'application/json', | ||
Authorization: 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJhNTAwMDQ5ZjNlMDYxMDlmZTNlODI4OWIwNmNmNTY4NSIsInN1YiI6IjY1ZTEyNDAyMmQ1MzFhMDE4NWMwZjJmNSIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.1J3EfnfmpJyZ4MV66eadk3h929zdeZfvjTO2JXhboWw', | ||
}, | ||
}) | ||
|
||
if (!res.ok) | ||
return null | ||
|
||
const data = (await res.json()) as Record<string, unknown> | ||
const formattedData: TMDBResponse = { | ||
backdropPath: typeof data.backdrop_path === 'string' ? data.backdrop_path : undefined, | ||
} | ||
|
||
cache.set(url, formattedData) | ||
return formattedData | ||
} | ||
catch { | ||
return null | ||
} | ||
} | ||
|
||
presence.on('UpdateData', async () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: 'https://i.imgur.com/vnX1akB.png', | ||
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) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check failure
Code scanning / ESLint
Disallow using code marked as `@deprecated`