forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtp.pt.config.js
67 lines (59 loc) · 1.63 KB
/
rtp.pt.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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)
const tz = {
lis: 'Europe/Lisbon',
per: 'Asia/Macau',
rja: 'America/Sao_Paulo'
}
module.exports = {
site: 'rtp.pt',
days: 2,
url({ channel, date }) {
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, channel }) {
let programs = []
const items = parseItems(content)
items.forEach(item => {
const prev = programs[programs.length - 1]
let start = parseStart(item, channel)
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
}
}
function parseIcon(item) {
const last = item.image.pop()
if (!last) return null
return last.src
}
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) {
if (!content) return []
const data = JSON.parse(content)
return _.flatten(Object.values(data.result))
}