Skip to content

Commit 6cb52fd

Browse files
Sailok25Bas950
andauthored
feat(RTVE): add activity (#10361)
* feat(RTVE): add presence for RTVE website * fix: remove unused settings and update thumbnail * Update websites/R/RTVE/metadata.json Co-authored-by: Bas van Zanten <bas.van.zanten007@gmail.com> Signed-off-by: Alba Ayala <127998789+Sailok25@users.noreply.github.com> --------- Signed-off-by: Alba Ayala <127998789+Sailok25@users.noreply.github.com> Co-authored-by: Bas van Zanten <bas.van.zanten007@gmail.com>
1 parent 5a36be0 commit 6cb52fd

File tree

3 files changed

+247
-0
lines changed

3 files changed

+247
-0
lines changed

websites/R/RTVE/iframe.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const iframe = new iFrame()
2+
3+
iframe.on('UpdateData', async () => {
4+
const video = document.querySelector('video')
5+
const audio = document.querySelector('audio')
6+
7+
if (video && !Number.isNaN(video.duration)) {
8+
iframe.send({
9+
iFrameVideoData: {
10+
currTime: video.currentTime,
11+
dur: video.duration,
12+
paused: video.paused,
13+
},
14+
})
15+
}
16+
else if (audio && !Number.isNaN(audio.duration)) {
17+
iframe.send({
18+
iFrameAudioData: {
19+
currTime: audio.currentTime,
20+
dur: audio.duration,
21+
paused: audio.paused,
22+
},
23+
})
24+
}
25+
})

websites/R/RTVE/metadata.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"$schema": "https://schemas.premid.app/metadata/1.16",
3+
"apiVersion": 1,
4+
"author": {
5+
"id": "970249245955354696",
6+
"name": "_sailok"
7+
},
8+
"service": "RTVE",
9+
"description": {
10+
"en": "News, sports, current affairs, albums, series and programs, and the latest from Spain and the world.",
11+
"es": "Noticias, deportes, actualidad, álbumes, series y programas, y la última hora de España y el mundo."
12+
},
13+
"url": "rtve.es",
14+
"regExp": "^https?[:][/][/](www[.])?rtve[.]es[/]",
15+
"version": "1.0.0",
16+
"logo": "https://i.imgur.com/0begwZJ.png",
17+
"thumbnail": "https://i.imgur.com/flAGyNL.png",
18+
"color": "#f56b0d",
19+
"category": "videos",
20+
"tags": [
21+
"tv",
22+
"radio",
23+
"news",
24+
"streaming",
25+
"clan",
26+
"series",
27+
"playz",
28+
"public-broadcaster"
29+
],
30+
"iframe": true,
31+
"settings": [
32+
{
33+
"id": "lang",
34+
"multiLanguage": true
35+
},
36+
{
37+
"id": "privacy",
38+
"title": "Privacy Mode",
39+
"icon": "fas fa-user-secret",
40+
"value": false
41+
},
42+
{
43+
"id": "buttons",
44+
"title": "Show Buttons",
45+
"icon": "fas fa-compress-arrows-alt",
46+
"value": true,
47+
"if": {
48+
"privacy": false
49+
}
50+
},
51+
{
52+
"id": "cover",
53+
"title": "Show Cover Images",
54+
"icon": "fas fa-images",
55+
"value": true,
56+
"if": {
57+
"privacy": false
58+
}
59+
}
60+
]
61+
}

websites/R/RTVE/presence.ts

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
import { Assets } from 'premid'
2+
3+
const presence = new Presence({
4+
clientId: '1457403769116561528',
5+
})
6+
7+
const browsingTimestamp = Math.floor(Date.now() / 1000)
8+
9+
enum ActivityAssets {
10+
RTVE = 'https://i.imgur.com/0begwZJ.png',
11+
RTVE_PLAY = 'https://i.imgur.com/Ru8b2AX.png',
12+
}
13+
14+
function getCleanTitle(): string {
15+
const ogTitle = document.querySelector('meta[property="og:title"]')?.getAttribute('content')
16+
const h1Title = document.querySelector('h1')?.textContent?.trim()
17+
18+
let title = ogTitle || h1Title || document.title
19+
title = title.replace(/\s*\|\s*Ver.*$/, '').replace(/\s*-\s*RTVE\.es$/, '').trim()
20+
return title
21+
}
22+
23+
function getSectionInfo(): { sectionName: string } {
24+
const path = document.location.pathname.toLowerCase()
25+
26+
if (path.includes('/videos/directo/')) {
27+
return { sectionName: 'EN DIRECTO' }
28+
}
29+
else if (path.includes('/noticias/')) {
30+
return { sectionName: 'Noticias' }
31+
}
32+
else if (path.startsWith('/infantil/')) {
33+
return { sectionName: 'Clan TV' }
34+
}
35+
else if (path.startsWith('/playz/')) {
36+
return { sectionName: 'Playz' }
37+
}
38+
else if (path.startsWith('/eltiempo/')) {
39+
return { sectionName: 'El Tiempo' }
40+
}
41+
else if (path.includes('/play/radio/') || path.includes('/play/audios/')) {
42+
return { sectionName: 'RNE Radio' }
43+
}
44+
else if (path.includes('/series/') || path.includes('/programas/')) {
45+
return { sectionName: 'Series y Programas' }
46+
}
47+
else if (path.startsWith('/play/')) {
48+
return { sectionName: 'RTVE Play' }
49+
}
50+
else {
51+
return { sectionName: 'RTVE.es' }
52+
}
53+
}
54+
55+
function getLogoToUse(): ActivityAssets {
56+
const path = document.location.pathname.toLowerCase()
57+
return path.startsWith('/play/') ? ActivityAssets.RTVE_PLAY : ActivityAssets.RTVE
58+
}
59+
60+
async function getStrings() {
61+
return presence.getStrings({
62+
play: 'general.playing',
63+
pause: 'general.paused',
64+
live: 'general.live',
65+
browsing: 'general.browsing',
66+
reading: 'general.reading',
67+
watchLive: 'general.buttonWatchStream',
68+
listenRadio: 'general.buttonListen',
69+
})
70+
}
71+
72+
presence.on('UpdateData', async () => {
73+
const [buttons, privacy, showCover] = await Promise.all([
74+
presence.getSetting<boolean>('buttons'),
75+
presence.getSetting<boolean>('privacy'),
76+
presence.getSetting<boolean>('cover'),
77+
])
78+
79+
const strings = await getStrings()
80+
const { href, pathname } = document.location
81+
const { sectionName } = getSectionInfo()
82+
const cleanTitle = getCleanTitle()
83+
const video = document.querySelector('video')
84+
const audio = document.querySelector('audio')
85+
86+
const presenceData: PresenceData = {
87+
largeImageKey: showCover ? getLogoToUse() : ActivityAssets.RTVE,
88+
}
89+
90+
// --- EN DIRECTO ---
91+
if (pathname.includes('/videos/directo/')) {
92+
presenceData.details = sectionName
93+
presenceData.state = privacy ? '' : cleanTitle
94+
presenceData.smallImageKey = Assets.Live
95+
presenceData.smallImageText = strings.live
96+
presenceData.startTimestamp = browsingTimestamp
97+
98+
if (buttons && !privacy) {
99+
presenceData.buttons = [{ label: strings.watchLive, url: href }]
100+
}
101+
102+
// --- RADIO ---
103+
}
104+
else if (pathname.includes('/play/radio/') || pathname.includes('/play/audios/')) {
105+
presenceData.details = sectionName
106+
presenceData.state = privacy ? '' : cleanTitle
107+
presenceData.smallImageKey = audio?.paused ? Assets.Pause : Assets.Play
108+
presenceData.smallImageText = audio?.paused ? strings.pause : strings.play
109+
presenceData.startTimestamp = browsingTimestamp
110+
111+
if (buttons && !privacy) {
112+
presenceData.buttons = [{ label: strings.listenRadio, url: href }]
113+
}
114+
115+
// --- VIDEO ---
116+
}
117+
else if (video && !Number.isNaN(video.duration)) {
118+
presenceData.details = sectionName
119+
presenceData.state = privacy ? '' : cleanTitle
120+
presenceData.smallImageKey = video.paused ? Assets.Pause : Assets.Play
121+
presenceData.smallImageText = video.paused ? strings.pause : strings.play
122+
presenceData.startTimestamp = browsingTimestamp
123+
124+
if (buttons && !privacy) {
125+
presenceData.buttons = [{ label: 'Ver en RTVE Play', url: href }]
126+
}
127+
128+
// --- NOTICIAS ---
129+
}
130+
else if (pathname.includes('/noticias/')) {
131+
presenceData.details = sectionName
132+
presenceData.state = privacy ? '' : cleanTitle
133+
presenceData.smallImageKey = Assets.Reading
134+
presenceData.smallImageText = strings.reading
135+
presenceData.startTimestamp = browsingTimestamp
136+
137+
if (buttons && !privacy) {
138+
presenceData.buttons = [{ label: 'Leer noticia', url: href }]
139+
}
140+
141+
// --- DEFAULT ---
142+
}
143+
else {
144+
presenceData.details = sectionName
145+
presenceData.state = privacy ? '' : cleanTitle
146+
presenceData.smallImageKey = Assets.Search
147+
presenceData.smallImageText = strings.browsing
148+
presenceData.startTimestamp = browsingTimestamp
149+
150+
if (buttons && !privacy) {
151+
presenceData.buttons = [{ label: `Visitar ${sectionName}`, url: href }]
152+
}
153+
}
154+
155+
if (privacy) {
156+
delete presenceData.state
157+
delete presenceData.buttons
158+
}
159+
160+
presence.setActivity(presenceData)
161+
})

0 commit comments

Comments
 (0)