forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meo.pt.config.js
81 lines (74 loc) · 2 KB
/
meo.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const { DateTime } = require('luxon')
module.exports = {
site: 'meo.pt',
days: 2,
url: 'https://authservice.apps.meo.pt/Services/GridTv/GridTvMng.svc/getProgramsFromChannels',
request: {
method: 'POST',
headers: {
Origin: 'https://www.meo.pt'
},
data: function ({ channel, date }) {
return {
service: 'channelsguide',
channels: [channel.site_id],
dateStart: date.format('YYYY-MM-DDT00:00:00-00:00'),
dateEnd: date.add(1, 'd').format('YYYY-MM-DDT00:00:00-00:00'),
accountID: ''
}
}
},
parser({ content }) {
let programs = []
const items = parseItems(content)
items.forEach(item => {
const start = parseStart(item)
let stop = parseStop(item)
if (stop < start) {
stop = stop.plus({ days: 1 })
}
programs.push({
title: item.name,
start,
stop
})
})
return programs
},
async channels() {
const axios = require('axios')
const data = await axios
.post(`https://authservice.apps.meo.pt/Services/GridTv/GridTvMng.svc/getGridAnon`, null, {
headers: {
Origin: 'https://www.meo.pt'
}
})
.then(r => r.data)
.catch(console.log)
return data.d.channels
.map(item => {
return {
lang: 'pt',
site_id: item.sigla,
name: item.name
}
})
.filter(channel => channel.site_id)
}
}
function parseStart(item) {
return DateTime.fromFormat(`${item.date} ${item.timeIni}`, 'd-M-yyyy HH:mm', {
zone: 'Europe/Lisbon'
}).toUTC()
}
function parseStop(item) {
return DateTime.fromFormat(`${item.date} ${item.timeEnd}`, 'd-M-yyyy HH:mm', {
zone: 'Europe/Lisbon'
}).toUTC()
}
function parseItems(content) {
if (!content) return []
const data = JSON.parse(content)
const programs = data?.d?.channels?.[0]?.programs
return Array.isArray(programs) ? programs : []
}