Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions websites/R/RTVE/iframe.ts
Original file line number Diff line number Diff line change
@@ -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,
},
})
}
})
61 changes: 61 additions & 0 deletions websites/R/RTVE/metadata.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]
}
161 changes: 161 additions & 0 deletions websites/R/RTVE/presence.ts
Original file line number Diff line number Diff line change
@@ -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<boolean>('buttons'),
presence.getSetting<boolean>('privacy'),
presence.getSetting<boolean>('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)
})
Loading