diff --git a/sites/mbc.net/mbc.net.config.js b/sites/mbc.net/mbc.net.config.js new file mode 100644 index 00000000..9bb86374 --- /dev/null +++ b/sites/mbc.net/mbc.net.config.js @@ -0,0 +1,42 @@ +const dayjs = require('dayjs') + +module.exports = { + site: 'mbc.net', + url({ date, channel }) { + return `https://www.mbc.net/.rest/api/channel/grids?from=${date.valueOf()}&to=${date + .add(1, 'd') + .valueOf()}&channel=${channel.site_id}` + }, + logo({ channel }) { + return channel.logo + }, + parser: function ({ content, channel, date }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + programs.push({ + title: item.showPageTitle, + category: item.showPageGenreInArabic, + description: item.showPageAboutInArabic, + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + } +} + +function parseStart(item) { + return dayjs(item.startTime).toJSON() +} + +function parseStop(item) { + return dayjs(item.endTime).toJSON() +} + +function parseItems(content) { + const data = JSON.parse(content) + + return data +} diff --git a/sites/mbc.net/mbc.net.test.js b/sites/mbc.net/mbc.net.test.js new file mode 100644 index 00000000..cc9f8c68 --- /dev/null +++ b/sites/mbc.net/mbc.net.test.js @@ -0,0 +1,53 @@ +// npx epg-grabber --config=sites/mbc.net/mbc.net.config.js --channels=sites/mbc.net/mbc.net_ae.channels.xml --output=.gh-pages/guides/ae/mbc.net.epg.xml --days=2 + +const { parser, url, logo } = require('./mbc.net.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const customParseFormat = require('dayjs/plugin/customParseFormat') +dayjs.extend(customParseFormat) +dayjs.extend(utc) + +const date = dayjs.utc('2021-11-06', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'mbc1', + xmltv_id: 'MBC.ae', + logo: 'https://www.mbc.net/dam/jcr:e5e1ffbc-89b8-4400-951e-624ded8eb350/invalid-name_12@3x.png' +} +const content = `[{"id":3140240,"channelBCMId":"1","channelLabel":"MBC1","showPageTitle":"اختطاف","showPageGenreInArabic":" دراما","showPageAboutInArabic":".يستضيف برنامج تلفزيوني والدة لينا وشقيقتها، ولدى مشاهدتها الحلقة، تكتشف والدة ماجد الحقيقة، بينما تتعرض العنود لحادث سير مروع","startTime":1636155131000,"endTime":1636157806000,"startTimeInMilliseconds":1636155131000,"endTimeInMilliseconds":1636157806200,"premiereMode":"Fast Repeat","showingNow":false}]` + +it('can generate valid url', () => { + const result = url({ date, channel }) + expect(result).toBe( + 'https://www.mbc.net/.rest/api/channel/grids?from=1636156800000&to=1636243200000&channel=mbc1' + ) +}) + +it('can get logo url', () => { + const result = logo({ channel }) + expect(result).toBe( + 'https://www.mbc.net/dam/jcr:e5e1ffbc-89b8-4400-951e-624ded8eb350/invalid-name_12@3x.png' + ) +}) + +it('can parse response', () => { + const result = parser({ date, channel, content }) + expect(result).toMatchObject([ + { + start: '2021-11-05T23:32:11.000Z', + stop: '2021-11-06T00:16:46.000Z', + title: 'اختطاف', + category: ' دراما', + description: + '.يستضيف برنامج تلفزيوني والدة لينا وشقيقتها، ولدى مشاهدتها الحلقة، تكتشف والدة ماجد الحقيقة، بينما تتعرض العنود لحادث سير مروع' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `[]` + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/mbc.net/mbc.net_ae.channels.xml b/sites/mbc.net/mbc.net_ae.channels.xml new file mode 100644 index 00000000..fcb35f30 --- /dev/null +++ b/sites/mbc.net/mbc.net_ae.channels.xml @@ -0,0 +1,22 @@ + + + + MBC + MBC 2 + MBC 4 + MBC 5 + MBC Action + MBC Bollywood + MBC Drama + MBC Drama + + MBC Drama USA + MBC Iraq + MBC Maser + MBC Maser 2 + MBC Maser USA + MBC Max + MBC + Power + MBC USA + Wanasah + + \ No newline at end of file