forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
moji.id.config.js
122 lines (105 loc) · 3.15 KB
/
moji.id.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
const cheerio = require('cheerio')
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)
const currentYear = new Date().getFullYear()
module.exports = {
site: 'moji.id',
days: 4,
output: 'moji.id.guide.xml',
channels: 'moji.id.channels.xml',
lang: 'en',
delay: 5000,
url: function () {
return 'https://moji.id/schedule'
},
request: {
method: 'GET',
timeout: 5000,
cache: { ttl: 60 * 60 * 1000 },
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36'
}
},
logo: function (context) {
return context.channel.logo
},
parser: function (context) {
const programs = []
const items = parseItems(context)
items.forEach(item => {
programs.push({
title: item.progTitle,
description: item.progDesc,
start: item.progStart,
stop: item.progStop
})
})
return programs
}
}
function parseItems(context) {
const $ = cheerio.load(context.content)
const schDayMonths = $('.date-slider .month').toArray()
const schPrograms = $('.desc-slider .list-slider').toArray()
const monthDate = dayjs(context.date).format('MMM DD')
const items = []
schDayMonths.forEach(function (schDayMonth, i) {
if (monthDate == $(schDayMonth).text()) {
let schDayPrograms = $(schPrograms[i]).find('.accordion').toArray()
schDayPrograms.forEach(function (program, i) {
let itemDay = {
progStart: parseStart(schDayMonth, program),
progStop: parseStop(schDayMonth, program, schDayPrograms[i + 1]),
progTitle: parseTitle(program),
progDesc: parseDescription(program)
}
items.push(itemDay)
})
}
})
return items
}
function parseTitle(item) {
return cheerio.load(item)('.name-prog').text()
}
function parseDescription(item) {
return cheerio.load(item)('.content-acc span').text()
}
function parseStart(schDayMonth, item) {
let monthDate = cheerio.load(schDayMonth).text().split(' ')
let startTime = cheerio.load(item)('.pkl').text()
let progStart = dayjs.tz(
currentYear + ' ' + monthDate[0] + ' ' + monthDate[1] + ' ' + startTime,
'YYYY MMM DD HH:mm',
'Asia/Jakarta'
)
return progStart
}
function parseStop(schDayMonth, itemCurrent, itemNext) {
let monthDate = cheerio.load(schDayMonth).text().split(' ')
if (itemNext) {
let stopTime = cheerio.load(itemNext)('.pkl').text()
return dayjs.tz(
currentYear + ' ' + monthDate[0] + ' ' + monthDate[1] + ' ' + stopTime,
'YYYY MMM DD HH:mm',
'Asia/Jakarta'
)
} else {
return dayjs.tz(
currentYear +
' ' +
monthDate[0] +
' ' +
(parseInt(monthDate[1]) + 1).toString().padStart(2, '0') +
' 00:00',
'YYYY MMM DD HH:mm',
'Asia/Jakarta'
)
}
}