From 602a4d7956baa7f354457060fb3118e5371fa7c7 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 6 Nov 2021 12:50:12 +0300 Subject: [PATCH 1/3] Create mbc.net.test.js --- sites/mbc.net/mbc.net.test.js | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 sites/mbc.net/mbc.net.test.js 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([]) +}) From b0835d26126a01de1f7d2587ba857fb28554f465 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 6 Nov 2021 12:50:17 +0300 Subject: [PATCH 2/3] Create mbc.net.config.js --- sites/mbc.net/mbc.net.config.js | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sites/mbc.net/mbc.net.config.js 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 +} From 966a30fc5543ad23e6502b3253243b6600a52df8 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 6 Nov 2021 12:50:23 +0300 Subject: [PATCH 3/3] Create mbc.net_ae.channels.xml --- sites/mbc.net/mbc.net_ae.channels.xml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 sites/mbc.net/mbc.net_ae.channels.xml 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