Skip to content

Commit

Permalink
feat(Tubi): multilang, buttons, covers, privacy & refactor (PreMiD#6692)
Browse files Browse the repository at this point in the history
Co-authored-by: Rhys Rakoff <64903135+EncryptedDev@users.noreply.github.com>
  • Loading branch information
Dark_Ville and EncryptedDev authored Aug 30, 2022
1 parent f334747 commit 657c90d
Show file tree
Hide file tree
Showing 2 changed files with 122 additions and 28 deletions.
32 changes: 31 additions & 1 deletion websites/T/Tubi/dist/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"nl": "Tubi is een Amerikaanse streamingdienst gevestigd in San Francisco, Californië, Verenigde Staten, die in 2014 werd gelanceerd. Het is een gratis, door advertenties ondersteunde dienst, met advertenties die worden getoond tijdens reclameblokken tussen het programmeren. Het is de grootste onafhankelijke videodienst in de Verenigde Staten."
},
"url": "tubitv.com",
"version": "1.2.4",
"version": "1.3.0",
"logo": "https://i.imgur.com/PfRmgZm.png",
"thumbnail": "https://i.imgur.com/44Esu8y.png",
"color": "#F12C7B",
Expand All @@ -29,5 +29,35 @@
"tubi",
"video",
"media"
],
"settings": [
{
"id": "lang",
"multiLanguage": true
},
{
"id": "privacy",
"title": "Privacy Mode",
"icon": "fas fa-user-secret",
"value": false
},
{
"id": "buttons",
"title": "Show Buttons",
"icon": "fas fa-compress-arrows-alt",
"value": true,
"if": {
"privacy": false
}
},
{
"id": "covers",
"title": "Show Cover",
"icon": "fad fa-images",
"value": true,
"if": {
"privacy": false
}
}
]
}
118 changes: 91 additions & 27 deletions websites/T/Tubi/presence.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,105 @@
const presence = new Presence({
clientId: "937290941285429311",
}),
strings = presence.getStrings({
play: "general.playing",
pause: "general.paused",
});
browingTimestamp = Math.floor(Date.now() / 1000);
async function getStrings() {
return presence.getStrings(
{
play: "general.playing",
paused: "general.paused",
browse: "general.browsing",
live: "general.live",
buttonWatchVideo: "general.buttonWatchVideo",
buttonWatchLive: "general.buttonWatchStream",
viewCategory: "general.viewCategory",
search: "general.searchFor",
},
await presence.getSetting<string>("lang").catch(() => "en")
);
}
enum Assets {
Logo = "https://i.imgur.com/PfRmgZm.png",
Live = "https://i.imgur.com/gYNKPnn.png",
Play = "https://i.imgur.com/OLaz6JN.png",
Paused = "https://i.imgur.com/4iyMINk.png",
SearchImage = "https://i.imgur.com/oGQtnIY.png",
}
let strings: Awaited<ReturnType<typeof getStrings>>,
oldLang: string = null;

presence.on("UpdateData", async () => {
const presenceData: PresenceData = {
largeImageKey: "tubi-logo",
largeImageKey: Assets.Logo,
},
video: HTMLVideoElement = document.querySelector(
"video#videoPlayerComponent"
);
if (video && !isNaN(video.duration)) {
const [startTimestamp, endTimestamp] = presence.getTimestamps(
Math.floor(video.currentTime),
Math.floor(video.duration)
);
presenceData.details = document
.querySelector('meta[property="og:title"]')
.getAttribute("content");
presenceData.smallImageKey = video.paused ? "pause" : "play";
presenceData.smallImageText = video.paused
? (await strings).pause
: (await strings).play;
presenceData.startTimestamp = startTimestamp;
presenceData.endTimestamp = endTimestamp;
video = document.querySelector<HTMLVideoElement>("video"),
search = document.querySelector<HTMLInputElement>('[type="search"]'),
{ href, pathname } = document.location,
[newLang, privacy, buttons, covers] = await Promise.all([
presence.getSetting<string>("lang").catch(() => "en"),
presence.getSetting<boolean>("privacy"),
presence.getSetting<boolean>("buttons"),
presence.getSetting<boolean>("covers"),
]);
if (oldLang !== newLang || !strings) {
oldLang = newLang;
strings = await getStrings();
}

if (privacy) {
presenceData.details = strings.browse;
return;
}
if (search?.value) {
presenceData.details = strings.search;
presenceData.state = search.value;
presenceData.smallImageKey = Assets.SearchImage;
} else if (pathname.includes("/category/")) {
presenceData.details = strings.viewCategory;
presenceData.state = document.querySelector<HTMLMetaElement>(
'[property="og:title"]'
).content;
} else if (video && !isNaN(video.duration)) {
presenceData.largeImageKey = document.querySelector<HTMLMetaElement>(
'meta[property="og:image"]'
).content;
presenceData.details = document.querySelector<HTMLMetaElement>(
'meta[property="og:title"]'
).content;
if (!pathname.includes("live")) {
presenceData.smallImageKey = video.paused ? Assets.Paused : Assets.Play;
presenceData.smallImageText = video.paused
? strings.paused
: strings.play;
presenceData.endTimestamp = presence.getTimestamps(
Math.floor(video.currentTime),
Math.floor(video.duration)
)[1];
presenceData.buttons = [
{
label: strings.buttonWatchVideo,
url: href,
},
];
} else {
presenceData.buttons = [
{
label: strings.buttonWatchLive,
url: href,
},
];
presenceData.smallImageText = strings.live;
presenceData.smallImageKey = Assets.Live;
}
presenceData.startTimestamp = browingTimestamp;

if (video.paused) {
delete presenceData.startTimestamp;
delete presenceData.endTimestamp;
}
} else presenceData.details = strings.browse;

if (presenceData.details) presence.setActivity(presenceData, !video.paused);
} else {
presenceData.details = "Browsing...";
presence.setActivity(presenceData);
}
if (!buttons) delete presenceData.buttons;
if (!covers) presenceData.largeImageKey = Assets.Logo;
if (presenceData.details) presence.setActivity(presenceData);
else presence.setActivity();
});

0 comments on commit 657c90d

Please sign in to comment.