diff --git a/sites/moji.id/moji.id.config.js b/sites/moji.id/moji.id.config.js index bf8b3f6c..926b0f97 100644 --- a/sites/moji.id/moji.id.config.js +++ b/sites/moji.id/moji.id.config.js @@ -35,8 +35,7 @@ module.exports = { parser: function (context) { const programs = [] - - const items = parseItems(context.content) + const items = parseItems(context) items.forEach(function(item, i) { programs.push({ @@ -51,23 +50,26 @@ module.exports = { } } -function parseItems(content) { - const $ = cheerio.load(content) - const schDayMonths = $('.date-slider .slide').toArray() +function parseItems(context) { + const $ = cheerio.load(context.content) + const schDayMonths = $('.date-slider .month').toArray() const schPrograms = $('.desc-slider .list-slider').toArray() - let items = []; + const monthDate = dayjs(context.date).format('MMM D') + const items = []; + schDayMonths.forEach(function(schDayMonth, i) { - let schDayPrograms = $(schPrograms[i]).find('.accordion').toArray() - //let schDayPrograms = $('.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) - }) + 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 @@ -82,14 +84,14 @@ function parseDescription(item) { } function parseStart(schDayMonth, item) { - let monthDate = cheerio.load(schDayMonth)('.slide .month').text().split(' ') + 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)('.slide .month').text().split(' ') + let monthDate = cheerio.load(schDayMonth).text().split(' ') if (itemNext) { let stopTime = cheerio.load(itemNext)('.pkl').text() diff --git a/sites/moji.id/moji.id.test.js b/sites/moji.id/moji.id.test.js index d3db597b..b579aa37 100644 --- a/sites/moji.id/moji.id.test.js +++ b/sites/moji.id/moji.id.test.js @@ -6,11 +6,16 @@ const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') dayjs.extend(utc) -const date = dayjs.utc('2023-04-29', 'YYYY-MM-DD').startOf('d') +const date = dayjs.utc('2023-08-18', 'YYYY-MM-DD').startOf('d') const channel = { site_id: '0', xmltv_id: 'moji.id', lang: 'en', logo: 'https://moji.id/site/uploads/logo/62f9387ce00a2-224-x-71.png' } const content = `

schedule

FriAug 18
SatAug 19
SunAug 20
Jam TayangProgram
00:00TRUST
Informasi seputar menjaga vitalitas pria
00:302023 AVC CHALLENGE CUP FOR WOMEN (RECORDED)
India Vs. Vietnam
02:30ONE CHAMPIONSHIP 2021
Siaran laga-laga pertandingan tinju gaya bebas internasional. Meyuguhkan pertarungan sengit dari para petarung profeisional kelas dunia.
03:30VOLLEYBALL NATION'S LEAGUE 2023 (RECORDED)
TURKI vs BRAZIL
05:00MOJI SPORT
MOJI SPORT
06:15LIPUTAN 6 PAGI MOJI
Kompilasi ragam berita hard news dan soft news baik dari dalam negeri maupun internasional juga info prediksi cuaca di wilayah Indonesia
07:00UNGKAP
Liputan investigasi seputar berbagai topik dan peristiwa hangat serta kontroversial yang terjadi di Indonesia
08:00PIALA KAPOLRI 2023 PUTRI (LIVE)
PIALA KAPOLRI 2023 PUTRI (LIVE)
10:30SERIES PAGI
GANTENG GANTENG SERIGALA
12:30DIAM-DIAM SUKA
DIAM-DIAM SUKA
13:30PIALA KAPOLRI 2023 PUTRA (LIVE)
PIALA KAPOLRI 2023 PUTRA (LIVE)
16:00PIALA KAPOLRI 2023 PUTRI (LIVE)
PIALA KAPOLRI 2023 PUTRI (LIVE)
18:00PIALA KAPOLRI 2023 PUTRA (LIVE)
PIALA KAPOLRI 2023 PUTRA (LIVE)
20:00MOJI DRAMA (CHHOTI SARDARNI)
CHHOTI SARDARNI
21:30SINEMA MALAM (BIDADARI CANTIK DI RUMAH KOST)
(BIDADARI CANTIK DI RUMAH KOST
23:00TRUST
Informasi seputar menjaga vitalitas pria
23:30TRUST
Informasi seputar menjaga vitalitas pria
` +const context = { + 'content': content, + 'date': date +} + it('can generate valid url', () => { expect(url({ channel, date })).toBe('https://moji.id/schedule') }) @@ -21,7 +26,7 @@ it('can handle empty guide', () => { }) it('can parse response', () => { - const results = parser({ content }) + const results = parser({ content: content, date: date }) expect(results[0]).toMatchObject( {