-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
tvarenasport.hr.config.js
132 lines (123 loc) · 3.62 KB
/
tvarenasport.hr.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const cheerio = require('cheerio')
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: 'tvarenasport.hr',
tz: 'Europe/Budapest',
lang: 'hr',
url: 'https://tvarenaprogram.com/live/v2/hr',
days: 2,
request: {
cache: {
ttl: 24 * 60 * 60 * 1000 // 1 day
}
},
parser({ content, channel, date }) {
const programs = []
const expectedDate = date.format('YYYY-MM-DD')
if (content) {
const dates = []
const $ = cheerio.load(content)
const parent = $(
`.tv-scheme-chanel-header img[src*="chanel-${channel.site_id}.png"]`
).parents('div')
parent
.siblings('.tv-scheme-days')
.find('a')
.toArray()
.forEach(el => {
const a = $(el)
const dt = a.find('span:nth-child(3)').text()
dates.push(dayjs(dt + date.year(), 'DD.MM.YYYY'))
})
parent
.siblings('.tv-scheme-new-slider-wrapper')
.find('.tv-scheme-new-slider-item')
.toArray()
.forEach((el, i) => {
programs.push(...parseSchedules($(el), dates[i], module.exports.tz))
})
programs.forEach((s, i) => {
if (i < programs.length - 2) {
s.stop = programs[i + 1].start
} else {
s.stop = s.start.startOf('d').add(1, 'd')
}
})
}
return programs.filter(
p =>
p.start.format('YYYY-MM-DD') === expectedDate ||
p.stop.format('YYYY-MM-DD') === expectedDate
)
},
async channels() {
const channels = []
const data = await axios
.get(this.url)
.then(r => r.data)
.catch(console.error)
if (data) {
// channel naming rule
const names = id => {
let match = id.match(/^\d+$/)
if (match) {
return `Arena Sport ${parseInt(id)}`
}
match = id.match(/^\d/)
if (match) {
return `Arena Sport ${id}`
}
match = id.match(/^a(\d+)(p)?/)
if (match) {
return `Arena ${parseInt(match[1])}${match[2] === 'p' ? ' Premium' : ''}`
}
return `Arena ${id}`
}
const $ = cheerio.load(data)
const items = $('.tv-scheme-chanel-header img').toArray()
for (const item of items) {
const [, id] = $(item)
.attr('src')
.match(/chanel-([a-z0-9]+)\.png/) || [null, null]
if (id) {
channels.push({
lang: this.lang,
site_id: id,
name: names(id)
})
}
}
}
return channels
}
}
function parseSchedules($s, date, tz) {
const schedules = []
const $ = $s._make
$s.find('.slider-content')
.toArray()
.forEach(el => {
schedules.push(parseSchedule($(el), date, tz))
})
return schedules
}
function parseSchedule($s, date, tz) {
const time = $s.find('.slider-content-top span').text()
const start = dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', tz)
const category = $s.find('.slider-content-middle span').text()
const title = $s.find('.slider-content-bottom p').text()
const description = $s.find('.slider-content-bottom span:first').text()
return {
title: description ? description : title,
description: description ? title : description,
category,
start
}
}