forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tvmusor.hu.config.js
81 lines (72 loc) · 2.07 KB
/
tvmusor.hu.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 axios = require('axios')
const dayjs = require('dayjs')
const _ = require('lodash')
module.exports = {
site: 'tvmusor.hu',
days: 2,
url: 'http://www.tvmusor.hu/a/get-events/',
request: {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
data({ channel, date }) {
const params = new URLSearchParams()
params.append(
'data',
JSON.stringify({
blocks: [`${channel.site_id}|${date.format('YYYY-MM-DD')}`]
})
)
return params
}
},
parser({ content, channel, date }) {
let programs = []
const items = parseItems(content, channel, date)
items.forEach(item => {
const prev = programs[programs.length - 1]
let start = dayjs(item.e)
let stop = dayjs(item.f)
if (prev) {
start = prev.stop
}
programs.push({
title: item.j,
category: item.h,
description: item.c,
icon: parseIcon(item),
start,
stop
})
})
return programs
},
async channels() {
const data = await axios
.get('http://www.tvmusor.hu/most/')
.then(r => r.data)
.catch(console.log)
const [, channelData] = data.match(/const CHANNEL_DATA = (.*);/)
const json = channelData.replace('},}', '}}').replace(/(\d+):/g, '"$1":')
const channels = JSON.parse(json)
return Object.values(channels).map(item => {
return {
lang: 'hu',
site_id: item.id,
name: item.name
}
})
}
}
function parseIcon(item) {
return item.z ? `http://www.tvmusor.hu/images/events/408/${item.z}` : null
}
function parseItems(content, channel, date) {
const data = JSON.parse(content)
if (!data || !data.data || !data.data.loadedBlocks) return []
const blocks = data.data.loadedBlocks
const blockId = `${channel.site_id}_${date.format('YYYY-MM-DD')}`
if (!Array.isArray(blocks[blockId])) return []
return _.uniqBy(_.uniqBy(blocks[blockId], 'e'), 'b')
}