From 242abc6ad3d69653d4dd3cca17f32a12d00252b3 Mon Sep 17 00:00:00 2001 From: Toha Date: Sat, 11 Nov 2023 22:14:38 +0700 Subject: [PATCH] Add shahid.mbc.net. Signed-off-by: Toha --- sites/shahid.mbc.net/shahid.mbc.net.config.js | 74 +++++++++++++ sites/shahid.mbc.net/shahid.mbc.net.test.js | 36 ++++++ .../shahid.mbc.net_ar.channels.xml | 104 ++++++++++++++++++ .../shahid.mbc.net_en.channels.xml | 104 ++++++++++++++++++ 4 files changed, 318 insertions(+) create mode 100644 sites/shahid.mbc.net/shahid.mbc.net.config.js create mode 100644 sites/shahid.mbc.net/shahid.mbc.net.test.js create mode 100644 sites/shahid.mbc.net/shahid.mbc.net_ar.channels.xml create mode 100644 sites/shahid.mbc.net/shahid.mbc.net_en.channels.xml diff --git a/sites/shahid.mbc.net/shahid.mbc.net.config.js b/sites/shahid.mbc.net/shahid.mbc.net.config.js new file mode 100644 index 00000000..0e31cbc2 --- /dev/null +++ b/sites/shahid.mbc.net/shahid.mbc.net.config.js @@ -0,0 +1,74 @@ +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) + +module.exports = { + site: 'shahid.mbc.net', + days: 2, + url({ channel, date}) { + return `https://api2.shahid.net/proxy/v2.1/shahid-epg-api/?csvChannelIds=${channel.site_id}&from=${date.format('YYYY-MM-DD')}T00:00:00.000Z&to=${date.format('YYYY-MM-DD')}T23:59:59.999Z&country=SA&language=${channel.lang}&Accept-Language=${channel.lang}` + }, + parser({ content, channel }) { + const programs = parseItems(content, channel) + .map(item => { + return { + title: item.title, + description: item.description, + session: item.seasonNumber, + episode: item.episodeNumber, + start: dayjs.tz(item.actualFrom, 'Asia/Riyadh').toISOString(), + stop: dayjs.tz(item.actualTo, 'Asia/Riyadh').toISOString() + } + }) + + return programs + }, + async channels({lang = 'en'}) { + const axios = require('axios') + const items = [] + let page = 0 + while (true) { + const result = await axios + .get(`https://api2.shahid.net/proxy/v2.1/product/filter?filter=%7B"pageNumber":${page},"pageSize":100,"productType":"LIVESTREAM","productSubType":"LIVE_CHANNEL"%7D&country=SA&language=${lang}&Accept-Language=${lang}`) + .then(response => response.data) + .catch(console.error) + if (result.productList) { + items.push(...result.productList.products) + if (result.productList.hasMore) { + page++ + continue + } + } + break; + } + const channels = items.map(channel => { + return { + lang, + site_id: channel.id, + name: channel.title + } + }) + + return channels + } +} + +function parseItems(content, channel) { + const items = [] + content = content ? JSON.parse(content) : [] + if (content.items) { + content.items.forEach(schedules => { + if (schedules.channelId == channel.site_id) { + items.push(...schedules.items) + return true + } + }) + } + + return items +} diff --git a/sites/shahid.mbc.net/shahid.mbc.net.test.js b/sites/shahid.mbc.net/shahid.mbc.net.test.js new file mode 100644 index 00000000..920fff1e --- /dev/null +++ b/sites/shahid.mbc.net/shahid.mbc.net.test.js @@ -0,0 +1,36 @@ +const { url, parser } = require('./shahid.mbc.net.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') + +dayjs.extend(utc) + +const date = dayjs.utc('2023-11-11').startOf('d') +const channel = { site_id: '996520', xmltv_id: 'AlAanTV.ae', lang: 'en' } + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + `https://api2.shahid.net/proxy/v2.1/shahid-epg-api/?csvChannelIds=${channel.site_id}&from=${date.format('YYYY-MM-DD')}T00:00:00.000Z&to=${date.format('YYYY-MM-DD')}T23:59:59.999Z&country=SA&language=${channel.lang}&Accept-Language=${channel.lang}` + ) +}) + +it('can parse response', () => { + const content = + '{"items":[{"channelId":"996520","items":[{"actualFrom":"2023-11-11T00:00:00.000+00:00","actualTo":"2023-11-11T00:30:00.000+00:00","description":"The presenter reviews the most prominent episodes of news programs produced by the channel\'s team on a weekly basis, which include the most important global updates and developments at all levels.","duration":null,"emptySlot":false,"episodeNumber":194,"from":"2023-11-11T00:00:00.000+00:00","genres":["TV Show"],"productId":null,"productionYear":null,"productPoster":"https://imagesmbc.whatsonindia.com/dasimages/landscape/1920x1080/F968D4A39DB25793E9EED1BDAFBAD2EA8A8F9B30Z.jpg","productSubType":null,"productType":null,"replay":false,"restritectContent":null,"seasonId":null,"seasonNumber":"1","showId":null,"streamInfo":null,"title":"Menassaatona Fi Osboo\'","to":"2023-11-11T00:30:00.000+00:00"}]}]}' + const result = parser({ content, channel, date }) + + expect(result).toMatchObject([ + { + start: '2023-11-10T21:00:00.000Z', + stop: '2023-11-10T21:30:00.000Z', + title: 'Menassaatona Fi Osboo\'', + description: + 'The presenter reviews the most prominent episodes of news programs produced by the channel\'s team on a weekly basis, which include the most important global updates and developments at all levels.' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ content: '' }) + + expect(result).toMatchObject([]) +}) diff --git a/sites/shahid.mbc.net/shahid.mbc.net_ar.channels.xml b/sites/shahid.mbc.net/shahid.mbc.net_ar.channels.xml new file mode 100644 index 00000000..f973d8c3 --- /dev/null +++ b/sites/shahid.mbc.net/shahid.mbc.net_ar.channels.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + الآن + العربية + العربية Business + الحدث + الإخبارية + القرآن الكريم + السعودية + السعودية الآن + السنة النبوية + الشرق + الشرق ديسكفري + الشرق الوثائقية + euronews english + euronews french + Fashion TV + FIGHT Sports + GULLI BIL ARABI + Just For Laughs + M6 INTERNATIONAL + MBC1 + MBC3 + MBC4 + MBC5 + MBC Bollywood + MBC Drama + MBC FM + MBC Iraq + MBC Masr2 + MBC Masr + MBC Persia + MBC Plus Drama + Nature Time + Rotana Cinema EGY + Rotana Cinema KSA + Rotana Classic + Rotana Drama + Rotana Khalijia + Rotana Kids + Rotana+ + SBC + Spacetoon + SSC1 HD + SSC2 HD + SSC3 HD + SSC4 HD + SSC5 HD + SSC Extra 1 HD + SSC Extra 2 HD + SSC Extra 3 HD + SSC News + ذكريات + TIJI in French + BBC’S Top Gear + وناسه + diff --git a/sites/shahid.mbc.net/shahid.mbc.net_en.channels.xml b/sites/shahid.mbc.net/shahid.mbc.net_en.channels.xml new file mode 100644 index 00000000..1b78980b --- /dev/null +++ b/sites/shahid.mbc.net/shahid.mbc.net_en.channels.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Al Aan TV + Al Arabiya + Al Arabiya Business + Al Hadath + Alikhbariya + Al Quraan al Kareem + AlSaudia + KSA Now + Al Sunnah al Nabawiyah + Asharq + Asharq Discovery + Asharq Documentary + euronews english + euronews french + Fashion TV + FIGHT Sports + GULLI BIL ARABI + Just_For_Laughs_ + M6 INTERNATIONAL + MBC1 + MBC3 + MBC4 + MBC5 + MBC Bollywood + MBC Drama + MBC FM + MBC Iraq + MBC Masr2 + MBC Masr + MBC Persia + MBC Plus Drama + Nature Time + Rotana Cinema EGY + Rotana Cinema KSA + Rotana Classic + Rotana Drama + Rotana Khalijia + Rotana Kids + Rotana+ + SBC + Spacetoon + SSC1 HD + SSC2 HD + SSC3 HD + SSC4 HD + SSC5 HD + SSC Extra 1 HD + SSC Extra 2 HD + SSC Extra 3 HD + SSC News + Thikrayat + TIJI in French + BBC’S_Top_Gear + Wanasa +