mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 17:10:07 -04:00
Merge pull request #1442 from iptv-org/add-rtp.pt
Add guide from rtp.pt
This commit is contained in:
commit
84d7b59616
5 changed files with 148 additions and 0 deletions
17
.github/workflows/rtp.pt.yml
vendored
Normal file
17
.github/workflows/rtp.pt.yml
vendored
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
name: rtp.pt
|
||||||
|
on:
|
||||||
|
schedule:
|
||||||
|
- cron: '0 3 * * *'
|
||||||
|
workflow_dispatch:
|
||||||
|
workflow_run:
|
||||||
|
workflows: [_trigger]
|
||||||
|
types:
|
||||||
|
- completed
|
||||||
|
jobs:
|
||||||
|
load:
|
||||||
|
uses: ./.github/workflows/_load.yml
|
||||||
|
with:
|
||||||
|
site: ${{github.workflow}}
|
||||||
|
secrets:
|
||||||
|
APP_ID: ${{ secrets.APP_ID }}
|
||||||
|
APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }}
|
1
sites/rtp.pt/__data__/content.json
Normal file
1
sites/rtp.pt/__data__/content.json
Normal file
File diff suppressed because one or more lines are too long
72
sites/rtp.pt/rtp.pt.config.js
Normal file
72
sites/rtp.pt/rtp.pt.config.js
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
const _ = require('lodash')
|
||||||
|
const axios = require('axios')
|
||||||
|
const dayjs = require('dayjs')
|
||||||
|
const utc = require('dayjs/plugin/utc')
|
||||||
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
site: 'rtp.pt',
|
||||||
|
url({ channel, date }) {
|
||||||
|
return `https://www.rtp.pt/EPG/json/rtp-channels-page/list-grid/tv/${
|
||||||
|
channel.site_id
|
||||||
|
}/${date.format('D-M-YYYY')}`
|
||||||
|
},
|
||||||
|
parser({ content }) {
|
||||||
|
let programs = []
|
||||||
|
const items = parseItems(content)
|
||||||
|
items.forEach(item => {
|
||||||
|
const prev = programs[programs.length - 1]
|
||||||
|
let start = parseStart(item)
|
||||||
|
if (!start) return
|
||||||
|
if (prev) {
|
||||||
|
prev.stop = start
|
||||||
|
}
|
||||||
|
const stop = start.add(30, 'm')
|
||||||
|
programs.push({
|
||||||
|
title: item.name,
|
||||||
|
description: item.description,
|
||||||
|
icon: parseIcon(item),
|
||||||
|
start,
|
||||||
|
stop
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return programs
|
||||||
|
},
|
||||||
|
async channels() {
|
||||||
|
const items = await axios
|
||||||
|
.get('https://www.rtp.pt/EPG/json/rtp-home-page/list-channels/tv')
|
||||||
|
.then(r => r.data.result)
|
||||||
|
.catch(console.error)
|
||||||
|
|
||||||
|
return items.map(i => {
|
||||||
|
return {
|
||||||
|
lang: 'pt',
|
||||||
|
site_id: i.channel_code,
|
||||||
|
name: i.channel_name
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseIcon(item) {
|
||||||
|
const last = item.image.pop()
|
||||||
|
|
||||||
|
return last?.src
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStart(item) {
|
||||||
|
return dayjs.tz(item.date, 'YYYY-MM-DD HH:mm:ss', 'Europe/Lisbon')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content) {
|
||||||
|
if (!content) return []
|
||||||
|
const data = JSON.parse(content)
|
||||||
|
|
||||||
|
return _.flatten(Object.values(data.result))
|
||||||
|
}
|
45
sites/rtp.pt/rtp.pt.test.js
Normal file
45
sites/rtp.pt/rtp.pt.test.js
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
// npm run channels:parse -- --config=./sites/rtp.pt/rtp.pt.config.js --output=./sites/rtp.pt/rtp.pt_pt.channels.xml
|
||||||
|
// npx epg-grabber --config=sites/rtp.pt/rtp.pt.config.js --channels=sites/rtp.pt/rtp.pt_pt.channels.xml --output=guide.xml --days=2
|
||||||
|
|
||||||
|
const { parser, url } = require('./rtp.pt.config.js')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
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('2022-12-02', 'YYYY-MM-DD').startOf('d')
|
||||||
|
const channel = {
|
||||||
|
site_id: '1',
|
||||||
|
xmltv_id: 'RTP1.pt'
|
||||||
|
}
|
||||||
|
|
||||||
|
it('can generate valid url', () => {
|
||||||
|
expect(url({ channel, date })).toBe(
|
||||||
|
'https://www.rtp.pt/EPG/json/rtp-channels-page/list-grid/tv/1/2-12-2022'
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can parse response', () => {
|
||||||
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||||
|
let results = parser({ content }).map(p => {
|
||||||
|
p.start = p.start.toJSON()
|
||||||
|
p.stop = p.stop.toJSON()
|
||||||
|
return p
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(results[0]).toMatchObject({
|
||||||
|
start: '2022-12-02T06:30:00.000Z',
|
||||||
|
stop: '2022-12-02T10:00:00.000Z',
|
||||||
|
title: 'Bom Dia Portugal',
|
||||||
|
description: 'E porque é de manhã que começa o dia, então inicie-o na nossa companhia!',
|
||||||
|
icon: 'https://cdn-images.rtp.pt/EPG/imagens/38084_57380_28384.png?w=384&h=216'
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can handle empty guide', () => {
|
||||||
|
const result = parser({ content: '', channel, date })
|
||||||
|
expect(result).toMatchObject([])
|
||||||
|
})
|
13
sites/rtp.pt/rtp.pt_pt.channels.xml
Normal file
13
sites/rtp.pt/rtp.pt_pt.channels.xml
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<site site="rtp.pt">
|
||||||
|
<channels>
|
||||||
|
<channel lang="pt" xmltv_id="RTP1.pt" site_id="1">RTP1</channel>
|
||||||
|
<channel lang="pt" xmltv_id="RTP2.pt" site_id="8">RTP2</channel>
|
||||||
|
<channel lang="pt" xmltv_id="RTP3.pt" site_id="7">RTP3</channel>
|
||||||
|
<channel lang="pt" xmltv_id="RTPMemoria.pt" site_id="9">RTP Memória</channel>
|
||||||
|
<channel lang="pt" xmltv_id="RTPAfrica.pt" site_id="6">RTP África</channel>
|
||||||
|
<channel lang="pt" xmltv_id="RTPInternacional.pt" site_id="5">RTP Internacional</channel>
|
||||||
|
<channel lang="pt" xmltv_id="RTPAcores.pt" site_id="3">RTP Açores</channel>
|
||||||
|
<channel lang="pt" xmltv_id="RTPMadeira.pt" site_id="4">RTP Madeira</channel>
|
||||||
|
</channels>
|
||||||
|
</site>
|
Loading…
Add table
Add a link
Reference in a new issue