Update moji.id guide.

Change site language to id and fix test.

Signed-off-by: Toha <tohenk@yahoo.com>
This commit is contained in:
Toha 2024-11-23 22:48:33 +07:00
parent 7610f7b9f5
commit dd5e3aa18a
No known key found for this signature in database
GPG key ID: 2D7AA6389D44DCAB
3 changed files with 39 additions and 61 deletions

View file

@ -1,4 +1,4 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<channels> <channels>
<channel site="moji.id" lang="en" xmltv_id="Moji.id" site_id="0">Moji</channel> <channel site="moji.id" lang="id" xmltv_id="Moji.id" site_id="0">Moji</channel>
</channels> </channels>

View file

@ -9,33 +9,15 @@ dayjs.extend(timezone)
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
const currentYear = new Date().getFullYear() const currentYear = new Date().getFullYear()
const tz = 'Asia/Jakarta'
module.exports = { module.exports = {
site: 'moji.id', site: 'moji.id',
days: 4, days: 2,
output: 'moji.id.guide.xml', url: 'https://moji.id/schedule',
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) { logo: function (context) {
return context.channel.logo return context.channel.logo
}, },
parser: function (context) { parser: function (context) {
const programs = [] const programs = []
const items = parseItems(context) const items = parseItems(context)
@ -60,15 +42,16 @@ function parseItems(context) {
const monthDate = dayjs(context.date).format('MMM DD') const monthDate = dayjs(context.date).format('MMM DD')
const items = [] const items = []
schDayMonths.forEach(function (schDayMonth, i) { schDayMonths.forEach((schDayMonth, i) => {
if (monthDate == $(schDayMonth).text()) { if (monthDate == $(schDayMonth).text()) {
let schDayPrograms = $(schPrograms[i]).find('.accordion').toArray() const schDayPrograms = $(schPrograms[i]).find('.accordion').toArray()
schDayPrograms.forEach(function (program, i) { schDayPrograms.forEach((program, i) => {
let itemDay = { const itemDay = {
progStart: parseStart(schDayMonth, program), progStart: parseStart($(schDayMonth), $(program)),
progStop: parseStop(schDayMonth, program, schDayPrograms[i + 1]), progStop: parseStop($(schDayMonth), schDayPrograms[i + 1] ?
progTitle: parseTitle(program), $(schDayPrograms[i + 1]) : null),
progDesc: parseDescription(program) progTitle: parseTitle($(program)),
progDesc: parseDescription($(program))
} }
items.push(itemDay) items.push(itemDay)
}) })
@ -79,44 +62,38 @@ function parseItems(context) {
} }
function parseTitle(item) { function parseTitle(item) {
return cheerio.load(item)('.name-prog').text() return item.find('.name-prog').text()
} }
function parseDescription(item) { function parseDescription(item) {
return cheerio.load(item)('.content-acc span').text() return item.find('.content-acc span').text()
} }
function parseStart(schDayMonth, item) { function parseStart(schDayMonth, item) {
let monthDate = cheerio.load(schDayMonth).text().split(' ') const monthDate = schDayMonth.text().split(' ')
let startTime = cheerio.load(item)('.pkl').text() const startTime = item.find('.pkl').text()
let progStart = dayjs.tz(
currentYear + ' ' + monthDate[0] + ' ' + monthDate[1] + ' ' + startTime, return dayjs.tz(
'YYYY MMM DD HH:mm', `${currentYear}-${monthDate[0]}-${monthDate[1]} ${startTime}`,
'Asia/Jakarta' 'YYYY-MMM-DD HH:mm',
tz
) )
return progStart
} }
function parseStop(schDayMonth, itemCurrent, itemNext) { function parseStop(schDayMonth, itemNext) {
let monthDate = cheerio.load(schDayMonth).text().split(' ') const monthDate = schDayMonth.text().split(' ')
if (itemNext) { if (itemNext) {
let stopTime = cheerio.load(itemNext)('.pkl').text() const stopTime = itemNext.find('.pkl').text()
return dayjs.tz( return dayjs.tz(
currentYear + ' ' + monthDate[0] + ' ' + monthDate[1] + ' ' + stopTime, `${currentYear}-${monthDate[0]}-${monthDate[1]} ${stopTime}`,
'YYYY MMM DD HH:mm', 'YYYY-MMM-DD HH:mm',
'Asia/Jakarta' tz
) )
} else { } else {
return dayjs.tz( return dayjs.tz(
currentYear + `${currentYear}-${monthDate[0]}-${(parseInt(monthDate[1]) + 1).toString().padStart(2, '0')} 00:00`,
' ' + 'YYYY-MMM-DD HH:mm',
monthDate[0] + tz
' ' +
(parseInt(monthDate[1]) + 1).toString().padStart(2, '0') +
' 00:00',
'YYYY MMM DD HH:mm',
'Asia/Jakarta'
) )
} }
} }

File diff suppressed because one or more lines are too long