forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zuragt.mn.config.js
89 lines (77 loc) · 2.24 KB
/
zuragt.mn.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
const dayjs = require('dayjs')
const axios = require('axios')
const cheerio = require('cheerio')
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: 'zuragt.mn',
days: 2,
url: function ({ channel, date }) {
return `https://m.zuragt.mn/channel/${channel.site_id}/?date=${date.format('YYYY-MM-DD')}`
},
request: {
maxRedirects: 0,
validateStatus: function (status) {
return status >= 200 && status < 303
}
},
parser: async function ({ content, date }) {
let programs = []
const items = parseItems(content)
for (let item of items) {
const prev = programs[programs.length - 1]
const $item = cheerio.load(item)
let start = parseStart($item, date)
if (prev) {
if (start.isBefore(prev.start)) {
start = start.add(1, 'd')
date = date.add(1, 'd')
}
prev.stop = start
}
const stop = start.add(30, 'm')
programs.push({
title: parseTitle($item),
start,
stop
})
}
return programs
},
async channels() {
let html = await axios
.get('https://www.zuragt.mn/')
.then(r => r.data)
.catch(console.log)
let $ = cheerio.load(html)
const items = $('.tv-box > ul > li').toArray()
return items
.map(item => {
const name = $(item).text().trim()
const link = $(item).find('a').attr('href')
if (!link) return null
const [, site_id] = link.match(/\/channel\/(.*)\//) || [null, null]
return {
lang: 'mn',
site_id,
name
}
})
.filter(Boolean)
}
}
function parseTitle($item) {
return $item('.program').text().trim()
}
function parseStart($item, date) {
const time = $item('.time')
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Asia/Ulaanbaatar')
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('body > div > div > div > ul > li').toArray()
}