-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Podurama): add presence (#8331)
Signed-off-by: ION606 <[email protected]> Co-authored-by: Daniel Lau <[email protected]>
- Loading branch information
Showing
2 changed files
with
151 additions
and
0 deletions.
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,28 @@ | ||
{ | ||
"$schema": "https://schemas.premid.app/metadata/1.10", | ||
"author": { | ||
"id": "358402930191106049", | ||
"name": "ion606" | ||
}, | ||
"service": "Podurama", | ||
"description": { | ||
"en": "Best free podcast player to listen to free podcasts, add custom rss feeds or upload your private files on mobile and desktop devices. Discover over 2M podcasts and millions of episodes." | ||
}, | ||
"url": "podurama.com", | ||
"version": "1.0.0", | ||
"logo": "https://i.imgur.com/tetKhbd.png", | ||
"thumbnail": "https://i.imgur.com/GbwflGj.png", | ||
"color": "#4B5458", | ||
"category": "other", | ||
"tags": [ | ||
"podurama" | ||
], | ||
"settings": [ | ||
{ | ||
"id": "usetimeleft", | ||
"title": "Use time left", | ||
"icon": "fad fa-stopwatch", | ||
"value": true | ||
} | ||
] | ||
} |
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,123 @@ | ||
const presence = new Presence({ | ||
clientId: "1234257543467892826", | ||
}), | ||
browsingTimestamp = Math.floor(Date.now() / 1000); | ||
|
||
const enum Assets { | ||
Logo = "https://i.imgur.com/tetKhbd.png", | ||
} | ||
|
||
const enum Pages { | ||
home = "home", | ||
podcast = "podcast", | ||
episode = "episode", | ||
bookmarks = "bookmarks", | ||
recent = "recently-played", | ||
Trending = "top-charts", | ||
myPodcasts = "subscribed-podcasts", | ||
newEps = "new-episodes", | ||
myFiles = "my-files", | ||
favorites = "favourites", | ||
tags = "tags", | ||
Bookmarks = "bookmarks", | ||
followed = "followed-playlists", | ||
} | ||
|
||
presence.on("UpdateData", async () => { | ||
const presenceData: PresenceData = { | ||
largeImageKey: Assets.Logo, | ||
startTimestamp: browsingTimestamp, | ||
}, | ||
[, sect, subsect] = document.location.pathname.split("/"), | ||
player = document.querySelector(".audio-player"), | ||
useTimeLeft = await presence.getSetting<boolean>("usetimeleft"); | ||
|
||
if (player) { | ||
const audioEl = document.querySelector("audio"), | ||
[startTS, endTS] = presence.getTimestampsfromMedia(audioEl); | ||
presenceData.details = "Listening to a Podcast"; | ||
presenceData.state = player.querySelector(".episode-title").textContent; | ||
|
||
if (audioEl.paused) { | ||
delete presenceData.startTimestamp; | ||
delete presenceData.endTimestamp; | ||
} else { | ||
presenceData.startTimestamp = startTS; | ||
if (useTimeLeft) presenceData.endTimestamp = endTS; | ||
else delete presenceData.endTimestamp; | ||
} | ||
|
||
presenceData.smallImageKey = audioEl.paused ? Assets.Pause : Assets.Play; | ||
presenceData.largeImageKey = player | ||
?.querySelector(".episode-details") | ||
?.querySelector("img")?.src; | ||
} else { | ||
switch (sect) { | ||
case Pages.podcast: | ||
{ | ||
const header = document.querySelector("header"); | ||
presenceData.details = "Viewing Podcast Page"; | ||
presenceData.state = header.querySelector("h1").textContent; | ||
presenceData.largeImageKey = header.querySelector("img").src; | ||
} | ||
break; | ||
|
||
case Pages.episode: | ||
{ | ||
presenceData.details = "Viewing Podcast Page"; | ||
presenceData.state = | ||
document.querySelector(".episode-title").textContent; | ||
presenceData.largeImageKey = | ||
document.querySelector<HTMLImageElement>(".main-img-loc").src; | ||
} | ||
break; | ||
|
||
case Pages.bookmarks: | ||
presenceData.details = "Browsing Bookmarks"; | ||
break; | ||
|
||
case Pages.Trending: | ||
{ | ||
presenceData.details = "Browsing Trending Podcasts!"; | ||
presenceData.state = `In the '${subsect.replaceAll( | ||
"-", | ||
" " | ||
)}' category`; | ||
} | ||
break; | ||
|
||
case Pages.favorites: | ||
presenceData.details = "Browsing Favorite Episodes!"; | ||
break; | ||
|
||
case Pages.followed: | ||
presenceData.details = "Browsing Followed Podcasts!"; | ||
break; | ||
|
||
case Pages.myFiles: | ||
presenceData.details = "Browsing My Files!"; | ||
break; | ||
|
||
case Pages.myPodcasts: | ||
presenceData.details = "Browsing Subcribed Podcasts!"; | ||
break; | ||
|
||
case Pages.newEps: | ||
presenceData.details = "Searching for New Episodes!"; | ||
break; | ||
|
||
case Pages.recent: | ||
presenceData.details = "Browsing Recently Played!"; | ||
break; | ||
|
||
case Pages.tags: | ||
presenceData.details = "Browsing Collections!"; | ||
break; | ||
|
||
default: | ||
presenceData.details = "Browsing the Site"; | ||
} | ||
} | ||
|
||
presence.setActivity(presenceData); | ||
}); |