Merge pull request #3042 from davidrobin/master

Add rts.ch (endpoint updated)
This commit is contained in:
Ismaël Moret
2026-03-23 13:00:16 +01:00
committed by GitHub
4 changed files with 148 additions and 0 deletions

21
sites/rts.ch/readme.md Normal file
View File

@@ -0,0 +1,21 @@
# rts.ch
https://rts.ch
### Download the guide
```sh
npm run grab --- --site=rts.ch
```
### Update channel list
```sh
npm run channels:parse --- --config=./sites/rts.ch/rts.ch.config.js --output=./sites/rts.ch/rts.ch.channels.xml
```
### Test
```sh
npm test --- rts.ch
```

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<channels>
<channel site="rts.ch" site_id="143932a79bb5a123a646b68b1d1188d7ae493e5b" lang="fr" xmltv_id="RTS1.ch@SD">RTS 1</channel>
<channel site="rts.ch" site_id="d7dfff28deee44e1d3c49a3d37d36d492b29671b" lang="fr" xmltv_id="RTS2.ch@SD">RTS 2</channel>
<channel site="rts.ch" site_id="5d332a26e06d08eec8ad385d566187df72955623" lang="fr" xmltv_id="RTSInfo.ch@SD">RTS Info</channel>
</channels>

View File

@@ -0,0 +1,42 @@
const axios = require('axios')
const dayjs = require('dayjs')
module.exports = {
site: 'rts.ch',
days: 2,
url({ channel, date }) {
return `https://il.srgssr.ch/integrationlayer/2.0/rts/programGuide/tv/byDate/${date.format('YYYY-MM-DD')}?reduced=false&channelId=${channel.site_id}`
},
parser({ content }) {
try {
const { programGuide } = JSON.parse(content)
if (!programGuide?.[0]?.programList) return []
return programGuide[0].programList.map(program => ({
title: program.title || '',
subTitle: program.subtitle || undefined,
description: program.description || program.show?.description || undefined,
start: new Date(program.startTime).toISOString(),
stop: new Date(program.endTime).toISOString(),
icon: program.imageUrl ? { src: program.imageUrl } : undefined,
category: program.genre || undefined,
}))
} catch {
return []
}
},
async channels() {
const today = dayjs().format('YYYY-MM-DD')
const { data } = await axios.get(
`https://www.rts.ch/play/v3/api/rts/production/tv-program-guide?date=${today}`
)
return data.data.map(entry => ({
site_id: entry.channel.id,
name: entry.channel.title,
lang: 'fr',
}))
}
}

View File

@@ -0,0 +1,79 @@
const { parser, url } = require('./rts.ch.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
const date = dayjs.utc('2026-03-21', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: '5d332a26e06d08eec8ad385d566187df72955623', name: 'RTS Info', lang: 'fr' }
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
'https://il.srgssr.ch/integrationlayer/2.0/rts/programGuide/tv/byDate/2026-03-21?reduced=false&channelId=5d332a26e06d08eec8ad385d566187df72955623'
)
})
it('can parse response', () => {
const content = JSON.stringify({
programGuide: [
{
channel: { id: '5d332a26e06d08eec8ad385d566187df72955623', title: 'RTS Info' },
programList: [
{
title: "L'essentiel de l'actualité",
startTime: '2026-03-21T07:00:00+01:00',
endTime: '2026-03-21T19:00:00+01:00',
imageUrl: 'https://kingfisher.rts.ch/res/img/cdns3/sherlock/urn:orphea-image:1043433',
genre: 'Actualité',
},
{
title: 'Forum',
startTime: '2026-03-21T19:00:00+01:00',
endTime: '2026-03-21T20:00:00+01:00',
imageUrl: 'https://kingfisher.rts.ch/res/img/cdns3/sherlock/urn:orphea-image:1831387',
genre: 'Actualité',
description: 'Le magazine du soir.',
},
],
},
],
})
const results = parser({ content })
expect(results[0]).toMatchObject({
title: "L'essentiel de l'actualité",
start: '2026-03-21T06:00:00.000Z',
stop: '2026-03-21T18:00:00.000Z',
category: 'Actualité',
icon: { src: 'https://kingfisher.rts.ch/res/img/cdns3/sherlock/urn:orphea-image:1043433' },
})
expect(results[1]).toMatchObject({
title: 'Forum',
start: '2026-03-21T18:00:00.000Z',
stop: '2026-03-21T19:00:00.000Z',
description: 'Le magazine du soir.',
})
})
it('can handle empty programList', () => {
const content = JSON.stringify({
programGuide: [
{ channel: { id: '5d332a26e06d08eec8ad385d566187df72955623', title: 'RTS Info' }, programList: [] },
],
})
const results = parser({ content })
expect(results).toMatchObject([])
})
it('can handle empty guide', () => {
const results = parser({ content: '' })
expect(results).toMatchObject([])
})
it('can handle malformed JSON', () => {
const results = parser({ content: 'not-json' })
expect(results).toMatchObject([])
})