-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(RTVE): add activity #10361
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat(RTVE): add activity #10361
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }, | ||
| }) | ||
| } | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
| } | ||
| ] | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.