Add RTP International Asia / America

resolves #1594
This commit is contained in:
RevGear 2023-01-02 17:43:59 +00:00
parent 65356a86f9
commit d1b90f74d6
3 changed files with 28 additions and 20 deletions

View file

@ -9,19 +9,24 @@ dayjs.extend(utc)
dayjs.extend(timezone)
dayjs.extend(customParseFormat)
const tz = {
lis: 'Europe/Lisbon',
per: 'Asia/Macau',
rja: 'America/Sao_Paulo'
}
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')}`
let [region, channelCode] = channel.site_id.split('#')
return `https://www.rtp.pt/EPG/json/rtp-channels-page/list-grid/tv/${channelCode}/${date.format('D-M-YYYY')}/${region}`
},
parser({ content }) {
parser({ content, channel }) {
let programs = []
const items = parseItems(content)
items.forEach(item => {
const prev = programs[programs.length - 1]
let start = parseStart(item)
let start = parseStart(item, channel)
if (!start) return
if (prev) {
prev.stop = start
@ -56,12 +61,13 @@ module.exports = {
function parseIcon(item) {
const last = item.image.pop()
return last?.src
if(!last) return null
return last.src
}
function parseStart(item) {
return dayjs.tz(item.date, 'YYYY-MM-DD HH:mm:ss', 'Europe/Lisbon')
function parseStart(item, channel) {
let [region] = channel.site_id.split('#')
return dayjs.tz(item.date, 'YYYY-MM-DD HH:mm:ss', tz[region])
}
function parseItems(content) {

View file

@ -12,19 +12,19 @@ dayjs.extend(utc)
const date = dayjs.utc('2022-12-02', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '4',
site_id: 'lis#4',
xmltv_id: 'RTPMadeira.pt'
}
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
'https://www.rtp.pt/EPG/json/rtp-channels-page/list-grid/tv/4/2-12-2022'
'https://www.rtp.pt/EPG/json/rtp-channels-page/list-grid/tv/4/2-12-2022/lis'
)
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
let results = parser({ content }).map(p => {
let results = parser({ content, channel }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p

View file

@ -1,13 +1,15 @@
<?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>
<channel lang="pt" xmltv_id="RTP1.pt" site_id="lis#1">RTP1</channel>
<channel lang="pt" xmltv_id="RTP2.pt" site_id="lis#8">RTP2</channel>
<channel lang="pt" xmltv_id="RTP3.pt" site_id="lis#7">RTP3</channel>
<channel lang="pt" xmltv_id="RTPMemoria.pt" site_id="lis#9">RTP Memória</channel>
<channel lang="pt" xmltv_id="RTPAfrica.pt" site_id="lis#6">RTP África</channel>
<channel lang="pt" xmltv_id="RTPInternacional.pt" site_id="lis#5">RTP Internacional</channel>
<channel lang="pt" xmltv_id="RTPiAmerica.pt" site_id="rja#5">RTP Internacional América</channel>
<channel lang="pt" xmltv_id="RTPiAsia.pt" site_id="per#5">RTP Internacional Ásia</channel>
<channel lang="pt" xmltv_id="RTPAcores.pt" site_id="lis#3">RTP Açores</channel>
<channel lang="pt" xmltv_id="RTPMadeira.pt" site_id="lis#4">RTP Madeira</channel>
</channels>
</site>