forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
novacyprus.com.config.js
67 lines (58 loc) · 1.72 KB
/
novacyprus.com.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
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0
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: 'novacyprus.com',
days: 2,
url({ date }) {
return `https://www.novacyprus.com/api/v1/tvprogram/from/${date.format('YYYYMMDD')}/to/${date
.add(1, 'd')
.format('YYYYMMDD')}`
},
parser({ content, channel }) {
let programs = []
const items = parseItems(content, channel)
items.forEach(item => {
const start = parseStart(item)
const stop = start.add(item.slotDuration, 'm')
programs.push({
title: item.title,
description: item.description,
icon: parseIcon(item),
start,
stop
})
})
return programs
},
async channels() {
const channels = await axios
.get('https://www.novacyprus.com/api/v1/guide/dailychannels')
.then(r => r.data)
.catch(console.log)
return channels.map(item => {
return {
lang: 'el',
site_id: item.ChannelId,
name: item.nameEl
}
})
}
}
function parseStart(item) {
return dayjs.tz(item.datetime, 'YYYY-MM-DD HH:mm:ss', 'Asia/Nicosia')
}
function parseIcon(item) {
return item.mediaItems.length ? item.mediaItems[0].CdnUrl : null
}
function parseItems(content, channel) {
const data = JSON.parse(content)
if (!data || !Array.isArray(data.nodes)) return []
return data.nodes.filter(i => i.ChannelId === channel.site_id)
}