-
-
Notifications
You must be signed in to change notification settings - Fork 250
/
Copy pathdigea.gr.config.js
86 lines (77 loc) · 2.06 KB
/
digea.gr.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
82
83
84
85
86
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: 'digea.gr',
days: 2,
url: 'https://www.digea.gr/el/api/epg/get-events',
request: {
method: 'POST',
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
data({ date }) {
const data = new URLSearchParams()
data.append('action', 'get_events')
data.append('date', date.format('YYYY-M-D'))
return data
}
},
parser({ content, channel }) {
let programs = []
let items = parseItems(content, channel)
items.forEach(item => {
programs.push({
title: item.title,
description: item.long_synopsis,
start: parseStart(item),
stop: parseStop(item)
})
})
return programs
},
async channels() {
const data = await axios
.post(
'https://www.digea.gr/el/api/epg/get-channels',
new URLSearchParams({
action: 'get_chanels',
lang: 'el'
}),
{
headers: {
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}
)
.then(r => r.data)
.catch(console.error)
return data.map(channel => {
return {
lang: 'el',
site_id: channel.id,
name: channel.name
}
})
}
}
function parseStart(item) {
return dayjs.tz(item.actual_time, 'YYYY-MM-DD HH:mm:ss', 'Europe/Athens')
}
function parseStop(item) {
return dayjs.tz(item.end_time, 'YYYY-MM-DD HH:mm:ss', 'Europe/Athens')
}
function parseItems(content, channel) {
try {
const data = JSON.parse(content)
if (!Array.isArray(data)) return []
return data.filter(p => p.channel_id === channel.site_id)
} catch {
return []
}
}