diff --git a/sites/moji.id/moji.id.channels.xml b/sites/moji.id/moji.id.channels.xml new file mode 100644 index 00000000..2b0db07e --- /dev/null +++ b/sites/moji.id/moji.id.channels.xml @@ -0,0 +1,7 @@ + + + + Moji + + \ No newline at end of file diff --git a/sites/moji.id/moji.id.config.js b/sites/moji.id/moji.id.config.js new file mode 100644 index 00000000..882b3e23 --- /dev/null +++ b/sites/moji.id/moji.id.config.js @@ -0,0 +1,100 @@ +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.content) + + items.forEach(function(item, i) { + programs.push({ + title: item.progTitle, + description: item.progDesc, + start: item.progStart, + stop: item.progStop + }) + }) + + return programs + } +} + +function parseItems(content) { + const $ = cheerio.load(content) + let schDayMonths = $('.date-slider .slide').toArray() + let schPrograms = $('.desc-slider .list-slider .accordion').toArray() + let items = []; + schDayMonths.forEach(function(schDayMonth, i) { + schPrograms.forEach(function(program, i) { + let itemDay = { + progStart: parseStart(schDayMonth, program), + progStop: parseStop(schDayMonth, program, schPrograms[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)('.slide .month').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(' ') + + 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] + ' ' + monthDate[1] + ' 24:00', 'YYYY MMM DD HH:mm', 'Asia/Jakarta') + } +} \ No newline at end of file diff --git a/sites/moji.id/moji.id.test.js b/sites/moji.id/moji.id.test.js new file mode 100644 index 00000000..9842ff65 --- /dev/null +++ b/sites/moji.id/moji.id.test.js @@ -0,0 +1,14 @@ +// npx epg-grabber --config=sites/moji.id/moji.id.config.js --channels=sites/moji.id/moji.id.channels.xml --output=guide.xml --days=2 +// npx jest moji.id.test.js + +const { url, parser } = require('./moji.id.config.js') +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 channel = { site_id: '0', xmltv_id: 'moji.id', lang: 'en', logo: 'https://moji.id/site/uploads/logo/62f9387ce00a2-224-x-71.png' } + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe('https://moji.id/schedule') +}) \ No newline at end of file