Skip to content

Commit

Permalink
feat(Podurama): add presence (PreMiD#8331)
Browse files Browse the repository at this point in the history
Signed-off-by: ION606 <[email protected]>
Co-authored-by: Daniel Lau <[email protected]>
  • Loading branch information
ION606 and theusaf authored Apr 29, 2024
1 parent 8b1c91d commit 6cadda0
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 0 deletions.
28 changes: 28 additions & 0 deletions websites/P/Podurama/metadata.json
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
}
]
}
123 changes: 123 additions & 0 deletions websites/P/Podurama/presence.ts
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);
});

0 comments on commit 6cadda0

Please sign in to comment.