-
-
Notifications
You must be signed in to change notification settings - Fork 236
/
musor.tv.config.js
93 lines (80 loc) · 2.65 KB
/
musor.tv.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
const cheerio = require('cheerio')
const axios = require('axios')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc)
dayjs.extend(customParseFormat)
const headers = {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 OPR/115.0.0.0',
}
module.exports = {
site: 'musor.tv',
days: 2,
request: { headers },
url({ channel, date }) {
return dayjs.utc().isSame(date, 'd')
? `https://musor.tv/mai/tvmusor/${channel.site_id}`
: `https://musor.tv/napi/tvmusor/${channel.site_id}/${date.format('YYYY.MM.DD')}`
},
parser({ content }) {
const programs = []
const [$, items] = parseItems(content)
items.forEach(item => {
const prev = programs[programs.length - 1]
const $item = $(item)
let start = parseStart($item)
if (prev) prev.stop = start
const stop = start.add(30, 'm')
programs.push({
title: parseTitle($item),
description: parseDescription($item),
image: parseImage($item),
start,
stop
})
})
return programs
},
async channels() {
const html = await axios
.get('https://musor.tv/', { headers })
.then(r => r.data)
.catch(console.error)
const $ = cheerio.load(html)
const channels = $('body > div.big_content > div > nav > table > tbody > tr > td > a').toArray()
return channels
.map(item => {
const $item = $(item)
const url = $item.attr('href')
if (!url.startsWith('//musor.tv/mai/tvmusor/')) return null
const site_id = url.replace('//musor.tv/mai/tvmusor/', '')
return {
lang: 'hu',
site_id,
name: $item.text()
}
})
.filter(i => i)
}
}
function parseImage($item) {
const imgSrc = $item.find('div.smartpe_screenshot > img').attr('src')
return imgSrc ? `https:${imgSrc}` : null
}
function parseTitle($item) {
return $item.find('div:nth-child(2) > div > h3 > a').text().trim()
}
function parseDescription($item) {
return $item.find('div:nth-child(5) > div > div').text().trim()
}
function parseStart($item) {
let datetime = $item.find('div:nth-child(1) > div > div > div > div > time').attr('content')
if (!datetime) return null
return dayjs.utc(datetime.replace('GMT', 'T'), 'YYYY-MM-DDTHH:mm:ss')
}
function parseItems(content) {
const $ = cheerio.load(content)
return [$, $('div.multicolumndayprogarea > div.smartpe_progentry').toArray()]
}