Skip to content

Commit

Permalink
feat(Tellingtone): add presence (PreMiD#6626)
Browse files Browse the repository at this point in the history
* feat(Tellingtone): add new presence

* chore(Tellingtone): run yarn format

* feat(Tellingtone): add smallImageKey

* feat(Tellingtone): fix behavior when listening or not

* chore(Tellingtone): change if statements for settings

* feat(Tellingtone): add the currentlyListening localized string

* chore(Tellingtone): fix currentlyListening localized string

* fix(Tellingtone): fix wrong replace

* fix(Tellingtone): add replace

* Update websites/T/Tellingtone/presence.ts

Signed-off-by: Bas950 <[email protected]>

Signed-off-by: Bas950 <[email protected]>
Co-authored-by: Bas950 <[email protected]>
  • Loading branch information
RisingSunLight42 and Bas950 authored Aug 16, 2022
1 parent 5bf8b03 commit 1735ca0
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 0 deletions.
41 changes: 41 additions & 0 deletions websites/T/Tellingtone/dist/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "https://schemas.premid.app/metadata/1.7",
"author": {
"name": "RisingSunLight",
"id": "240521747852558347"
},
"service": "Tellingtone",
"description": {
"en": "Discover our catalog of original audio series, stories designed at the start to be listened to as a podcast. Immerse yourself in our fantastic universe where suspense, magic and investigation intertwine...",
"fr": "Découvrez notre catalogue de séries audio originales, des histoires conçues dès l'écriture pour être écoutées en podcast. Plongez dans nos univers fantastiques où s'entremêlent suspense, magie et enquête…"
},
"url": "tellingtone.com",
"version": "1.0.0",
"logo": "https://i.imgur.com/L4eWRh1.png",
"thumbnail": "https://i.imgur.com/6FokOfw.png",
"color": "#45A8FC",
"category": "other",
"tags": [
"superflame",
"stories",
"audio"
],
"settings": [
{
"id": "lang",
"multiLanguage": true
},
{
"id": "time",
"title": "Show Timestamp",
"icon": "fad fa-stopwatch",
"value": true
},
{
"id": "cover",
"title": "Show Cover",
"icon": "fad fa-images",
"value": true
}
]
}
99 changes: 99 additions & 0 deletions websites/T/Tellingtone/presence.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
const presence = new Presence({ clientId: "1006201873985961984" }),
browsingTimestamp = Math.floor(Date.now() / 1000);

async function getStrings() {
return presence.getStrings(
{
viewHome: "general.viewHome",
paused: "general.paused",
playing: "general.playing",
episode: "general.episode",
viewPage: "general.viewPage",
buttonViewSeries: "general.buttonViewSeries",
currentlyListening: "general.currentlyListening",
},
await presence.getSetting<string>("lang").catch(() => "en")
);
}

let strings: Awaited<ReturnType<typeof getStrings>>,
oldLang: string = null;

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: "logo",
startTimestamp: browsingTimestamp,
},
{ pathname, href } = document.location,
pathSplit = pathname.split("/"),
[newLang, time, showCover] = await Promise.all([
presence.getSetting<string>("lang").catch(() => "en"),
presence.getSetting<boolean>("time"),
presence.getSetting<boolean>("cover"),
]);

if (oldLang !== newLang || !strings) {
oldLang = newLang;
strings = await getStrings();
}

switch (pathSplit[1]) {
case "":
presenceData.details = strings.viewHome;
break;
case "shop":
case "blog":
presenceData.details = `Viewing ${pathSplit[1]}`;
break;
case "series":
presenceData.details = strings.viewPage;
presenceData.state =
document.querySelector<HTMLHeadingElement>("div.head > h1").textContent;
presenceData.largeImageKey =
document.querySelector<HTMLImageElement>("div.head > img").src;

presenceData.buttons = [{ label: strings.buttonViewSeries, url: href }];
}
if (document.querySelector("div#Player")) {
presenceData.details = strings.currentlyListening
.replace("{0}", " ")
.replace(
"{1}",
document.querySelector<HTMLDivElement>("div.media-title").textContent
);
presenceData.state =
document.querySelector<HTMLDivElement>("div.media-episode").textContent;
presenceData.largeImageKey = document
.querySelector<HTMLImageElement>("div.media-image > svg > image")
.getAttribute("xlink:href");

const timers: string[] = [];
for (const element of document.querySelectorAll("div.desktop > div.timer"))
timers.push(element.textContent);
[presenceData.startTimestamp, presenceData.endTimestamp] =
presence.getTimestamps(
presence.timestampFromFormat(timers[0]),
presence.timestampFromFormat(timers[1])
);
delete presenceData.buttons;

if (document.querySelector(".icon-pause")) {
presenceData.smallImageKey = "play";
presenceData.smallImageText = strings.playing;
} else {
presenceData.smallImageKey = "pause";
presenceData.smallImageText = strings.paused;
delete presenceData.endTimestamp;
delete presenceData.startTimestamp;
}
}

if (!time) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
if (!showCover) presenceData.largeImageKey = "logo";

if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
});
6 changes: 6 additions & 0 deletions websites/T/Tellingtone/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist/"
}
}

0 comments on commit 1735ca0

Please sign in to comment.