-
-
Notifications
You must be signed in to change notification settings - Fork 236
/
awilime.com.config.js
86 lines (73 loc) · 2.27 KB
/
awilime.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const cheerio = require('cheerio')
const axios = require('axios')
const { DateTime } = require('luxon')
module.exports = {
site: 'awilime.com',
days: 2,
url({ channel, date }) {
return `https://www.awilime.com/tv/napi_musor/${channel.site_id}/${date.format('YYYY_MM_DD')}`
},
parser({ content, date }) {
const programs = []
const items = parseItems(content)
items.forEach(item => {
const prev = programs[programs.length - 1]
const $item = cheerio.load(item)
let start = parseStart($item, date)
if (!start) return
if (prev) {
prev.stop = start
}
const stop = start.plus({ minute: 30 })
programs.push({
title: parseTitle($item),
sub_title: parseSubTitle($item),
description: parseDescription($item),
start,
stop
})
})
return programs
},
async channels() {
const html = await axios
.get('https://www.awilime.com/tv/napi_musor')
.then(r => r.data)
.catch(console.log)
const $ = cheerio.load(html)
const items = $('#body > div.tk > div > div').toArray()
const channels = []
items.forEach(item => {
const name = $(item).find('a').text().trim()
const url = $(item).find('a').attr('href')
const [, site_id] = url.match(/\/tv\/napi_musor\/(.*)/) || [null, null]
if (!site_id) return
if (channels.find(channel => channel.site_id === site_id)) return
channels.push({
lang: 'hu',
site_id,
name
})
})
return channels
}
}
function parseTitle($item) {
return $item('b > a').text().trim()
}
function parseSubTitle($item) {
return $item('i').clone().children().remove('s').end().text().trim()
}
function parseDescription($item) {
return $item('p').text().trim()
}
function parseStart($item, date) {
let time = $item('b').clone().children().remove().end().text().trim()
if (!time || !/^\d/.test(time)) return null
time = `${date.format('YYYY-MM-DD')} ${time}`
return DateTime.fromFormat(time, 'yyyy-MM-dd HH:mm', { zone: 'Europe/Budapest' }).toUTC()
}
function parseItems(content) {
const $ = cheerio.load(content)
return $('#body > div.tdc > div.td2 > div').toArray()
}