diff --git a/websites/R/RTVE/iframe.ts b/websites/R/RTVE/iframe.ts new file mode 100644 index 000000000000..43211bc5f3eb --- /dev/null +++ b/websites/R/RTVE/iframe.ts @@ -0,0 +1,25 @@ +const iframe = new iFrame() + +iframe.on('UpdateData', async () => { + const video = document.querySelector('video') + const audio = document.querySelector('audio') + + if (video && !Number.isNaN(video.duration)) { + iframe.send({ + iFrameVideoData: { + currTime: video.currentTime, + dur: video.duration, + paused: video.paused, + }, + }) + } + else if (audio && !Number.isNaN(audio.duration)) { + iframe.send({ + iFrameAudioData: { + currTime: audio.currentTime, + dur: audio.duration, + paused: audio.paused, + }, + }) + } +}) diff --git a/websites/R/RTVE/metadata.json b/websites/R/RTVE/metadata.json new file mode 100644 index 000000000000..42f08f03c9f2 --- /dev/null +++ b/websites/R/RTVE/metadata.json @@ -0,0 +1,61 @@ +{ + "$schema": "https://schemas.premid.app/metadata/1.16", + "apiVersion": 1, + "author": { + "id": "970249245955354696", + "name": "_sailok" + }, + "service": "RTVE", + "description": { + "en": "News, sports, current affairs, albums, series and programs, and the latest from Spain and the world.", + "es": "Noticias, deportes, actualidad, álbumes, series y programas, y la última hora de España y el mundo." + }, + "url": "rtve.es", + "regExp": "^https?[:][/][/](www[.])?rtve[.]es[/]", + "version": "1.0.0", + "logo": "https://i.imgur.com/0begwZJ.png", + "thumbnail": "https://i.imgur.com/flAGyNL.png", + "color": "#f56b0d", + "category": "videos", + "tags": [ + "tv", + "radio", + "news", + "streaming", + "clan", + "series", + "playz", + "public-broadcaster" + ], + "iframe": true, + "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": "cover", + "title": "Show Cover Images", + "icon": "fas fa-images", + "value": true, + "if": { + "privacy": false + } + } + ] +} diff --git a/websites/R/RTVE/presence.ts b/websites/R/RTVE/presence.ts new file mode 100644 index 000000000000..610a74602ecb --- /dev/null +++ b/websites/R/RTVE/presence.ts @@ -0,0 +1,161 @@ +import { Assets } from 'premid' + +const presence = new Presence({ + clientId: '1457403769116561528', +}) + +const browsingTimestamp = Math.floor(Date.now() / 1000) + +enum ActivityAssets { + RTVE = 'https://i.imgur.com/0begwZJ.png', + RTVE_PLAY = 'https://i.imgur.com/Ru8b2AX.png', +} + +function getCleanTitle(): string { + const ogTitle = document.querySelector('meta[property="og:title"]')?.getAttribute('content') + const h1Title = document.querySelector('h1')?.textContent?.trim() + + let title = ogTitle || h1Title || document.title + title = title.replace(/\s*\|\s*Ver.*$/, '').replace(/\s*-\s*RTVE\.es$/, '').trim() + return title +} + +function getSectionInfo(): { sectionName: string } { + const path = document.location.pathname.toLowerCase() + + if (path.includes('/videos/directo/')) { + return { sectionName: 'EN DIRECTO' } + } + else if (path.includes('/noticias/')) { + return { sectionName: 'Noticias' } + } + else if (path.startsWith('/infantil/')) { + return { sectionName: 'Clan TV' } + } + else if (path.startsWith('/playz/')) { + return { sectionName: 'Playz' } + } + else if (path.startsWith('/eltiempo/')) { + return { sectionName: 'El Tiempo' } + } + else if (path.includes('/play/radio/') || path.includes('/play/audios/')) { + return { sectionName: 'RNE Radio' } + } + else if (path.includes('/series/') || path.includes('/programas/')) { + return { sectionName: 'Series y Programas' } + } + else if (path.startsWith('/play/')) { + return { sectionName: 'RTVE Play' } + } + else { + return { sectionName: 'RTVE.es' } + } +} + +function getLogoToUse(): ActivityAssets { + const path = document.location.pathname.toLowerCase() + return path.startsWith('/play/') ? ActivityAssets.RTVE_PLAY : ActivityAssets.RTVE +} + +async function getStrings() { + return presence.getStrings({ + play: 'general.playing', + pause: 'general.paused', + live: 'general.live', + browsing: 'general.browsing', + reading: 'general.reading', + watchLive: 'general.buttonWatchStream', + listenRadio: 'general.buttonListen', + }) +} + +presence.on('UpdateData', async () => { + const [buttons, privacy, showCover] = await Promise.all([ + presence.getSetting('buttons'), + presence.getSetting('privacy'), + presence.getSetting('cover'), + ]) + + const strings = await getStrings() + const { href, pathname } = document.location + const { sectionName } = getSectionInfo() + const cleanTitle = getCleanTitle() + const video = document.querySelector('video') + const audio = document.querySelector('audio') + + const presenceData: PresenceData = { + largeImageKey: showCover ? getLogoToUse() : ActivityAssets.RTVE, + } + + // --- EN DIRECTO --- + if (pathname.includes('/videos/directo/')) { + presenceData.details = sectionName + presenceData.state = privacy ? '' : cleanTitle + presenceData.smallImageKey = Assets.Live + presenceData.smallImageText = strings.live + presenceData.startTimestamp = browsingTimestamp + + if (buttons && !privacy) { + presenceData.buttons = [{ label: strings.watchLive, url: href }] + } + + // --- RADIO --- + } + else if (pathname.includes('/play/radio/') || pathname.includes('/play/audios/')) { + presenceData.details = sectionName + presenceData.state = privacy ? '' : cleanTitle + presenceData.smallImageKey = audio?.paused ? Assets.Pause : Assets.Play + presenceData.smallImageText = audio?.paused ? strings.pause : strings.play + presenceData.startTimestamp = browsingTimestamp + + if (buttons && !privacy) { + presenceData.buttons = [{ label: strings.listenRadio, url: href }] + } + + // --- VIDEO --- + } + else if (video && !Number.isNaN(video.duration)) { + presenceData.details = sectionName + presenceData.state = privacy ? '' : cleanTitle + presenceData.smallImageKey = video.paused ? Assets.Pause : Assets.Play + presenceData.smallImageText = video.paused ? strings.pause : strings.play + presenceData.startTimestamp = browsingTimestamp + + if (buttons && !privacy) { + presenceData.buttons = [{ label: 'Ver en RTVE Play', url: href }] + } + + // --- NOTICIAS --- + } + else if (pathname.includes('/noticias/')) { + presenceData.details = sectionName + presenceData.state = privacy ? '' : cleanTitle + presenceData.smallImageKey = Assets.Reading + presenceData.smallImageText = strings.reading + presenceData.startTimestamp = browsingTimestamp + + if (buttons && !privacy) { + presenceData.buttons = [{ label: 'Leer noticia', url: href }] + } + + // --- DEFAULT --- + } + else { + presenceData.details = sectionName + presenceData.state = privacy ? '' : cleanTitle + presenceData.smallImageKey = Assets.Search + presenceData.smallImageText = strings.browsing + presenceData.startTimestamp = browsingTimestamp + + if (buttons && !privacy) { + presenceData.buttons = [{ label: `Visitar ${sectionName}`, url: href }] + } + } + + if (privacy) { + delete presenceData.state + delete presenceData.buttons + } + + presence.setActivity(presenceData) +})