forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tvgids.nl.config.js
87 lines (75 loc) · 2.22 KB
/
tvgids.nl.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
87
const cheerio = require('cheerio')
const axios = require('axios')
const { DateTime } = require('luxon')
module.exports = {
site: 'tvgids.nl',
days: 2,
url: function ({ date, channel }) {
const path =
DateTime.utc().day === DateTime.fromMillis(date.valueOf()).day
? ''
: `${date.format('DD-MM-YYYY')}/`
return `https://www.tvgids.nl/gids/${path}${channel.site_id}`
},
parser: function ({ content, date }) {
date = date.subtract(1, 'd')
let programs = []
const items = parseItems(content)
items.forEach(item => {
const $item = cheerio.load(item)
const prev = programs[programs.length - 1]
let start = parseStart($item, date)
if (prev) {
if (start < prev.start) {
start = start.plus({ days: 1 })
date = date.add(1, 'd')
}
prev.stop = start
}
const stop = start.plus({ minutes: 30 })
programs.push({
title: parseTitle($item),
description: parseDescription($item),
icon: parseIcon($item),
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
.get('https://www.tvgids.nl/gids/')
.then(r => r.data)
.catch(console.log)
const $ = cheerio.load(data)
const channels = []
$('.guide__channel-logo-container').each((i, el) => {
channels.push({
site_id: $(el).find('a').attr('id'),
name: $(el).find('img').attr('title'),
lang: 'nl'
})
})
return channels
}
}
function parseTitle($item) {
return $item('.program__title').text().trim()
}
function parseDescription($item) {
return $item('.program__text').text().trim()
}
function parseIcon($item) {
return $item('.program__thumbnail').data('src')
}
function parseStart($item, date) {
const time = $item('.program__starttime').clone().children().remove().end().text().trim()
return DateTime.fromFormat(`${date.format('YYYY-MM-DD')} ${time}`, 'yyyy-MM-dd HH:mm', {
zone: 'Europe/Amsterdam'
}).toUTC()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('.guide__guide .program').toArray()
}