This commit is contained in:
Ismaël Moret
2025-09-28 16:24:42 +00:00
parent 8136b4029e
commit 501cbc9017

View File

@@ -1,104 +1,104 @@
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const timezone = require('dayjs/plugin/timezone') const timezone = require('dayjs/plugin/timezone')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(utc) dayjs.extend(utc)
dayjs.extend(timezone) dayjs.extend(timezone)
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
module.exports = { module.exports = {
site: 'shahid.mbc.net', site: 'shahid.mbc.net',
days: 2, days: 2,
url({ channel, date }) { url({ channel, date }) {
return `https://api2.shahid.net/proxy/v2.1/shahid-epg-api/?csvChannelIds=${ return `https://api2.shahid.net/proxy/v2.1/shahid-epg-api/?csvChannelIds=${
channel.site_id channel.site_id
}&from=${date.format('YYYY-MM-DD')}T00:00:00.000Z&to=${date.format( }&from=${date.format('YYYY-MM-DD')}T00:00:00.000Z&to=${date.format(
'YYYY-MM-DD' 'YYYY-MM-DD'
)}T23:59:59.999Z&country=SA&language=${channel.lang}&Accept-Language=${channel.lang}` )}T23:59:59.999Z&country=SA&language=${channel.lang}&Accept-Language=${channel.lang}`
}, },
parser({ content, channel }) { parser({ content, channel }) {
const programs = parseItems(content, channel).map(item => { const programs = parseItems(content, channel).map(item => {
return { return {
title: item.title, title: item.title,
description: item.description, description: item.description,
image: parseImage(item), image: parseImage(item),
season: item.seasonNumber, season: item.seasonNumber,
episode: item.episodeNumber, episode: item.episodeNumber,
category: item.genres, category: item.genres,
start: dayjs.tz(item.actualFrom, 'UTC').toISOString(), start: dayjs.tz(item.actualFrom, 'UTC').toISOString(),
stop: dayjs.tz(item.actualTo, 'UTC').toISOString() stop: dayjs.tz(item.actualTo, 'UTC').toISOString()
} }
}) })
return programs return programs
}, },
async channels({ lang = 'en' }) { async channels({ lang = 'en' }) {
const axios = require('axios') const axios = require('axios')
const items = [] const items = []
const countryCodes = ['EG', 'SA', 'US'] const countryCodes = ['EG', 'SA', 'US']
for (let country of countryCodes) { for (let country of countryCodes) {
let page = 0 let page = 0
while (true) { while (true) {
const result = await axios const result = await axios
.get( .get(
`https://api2.shahid.net/proxy/v2.1/product/filter?filter=%7B"pageNumber":${page},"pageSize":100,"productType":"LIVESTREAM","productSubType":"LIVE_CHANNEL"%7D&country=${country}&language=${lang}&Accept-Language=${lang}` `https://api2.shahid.net/proxy/v2.1/product/filter?filter=%7B"pageNumber":${page},"pageSize":100,"productType":"LIVESTREAM","productSubType":"LIVE_CHANNEL"%7D&country=${country}&language=${lang}&Accept-Language=${lang}`
) )
.then(response => response.data) .then(response => response.data)
.catch(console.error) .catch(console.error)
if (result.productList) { if (result.productList) {
items.push(...result.productList.products) items.push(...result.productList.products)
if (result.productList.hasMore) { if (result.productList.hasMore) {
page++ page++
continue continue
} }
} }
break break
} }
} }
const uniqueItems = Array.from(new Map(items.map(item => [item.id, item])).values()) const uniqueItems = Array.from(new Map(items.map(item => [item.id, item])).values())
const channels = uniqueItems.map(channel => { const channels = uniqueItems.map(channel => {
return { return {
lang, lang,
site_id: channel.id, site_id: channel.id,
name: channel.title name: channel.title
} }
}) })
return channels return channels
} }
} }
function parseItems(content, channel) { function parseItems(content, channel) {
const items = [] const items = []
content = content ? JSON.parse(content) : [] content = content ? JSON.parse(content) : []
if (content.items) { if (content.items) {
content.items.forEach(schedules => { content.items.forEach(schedules => {
if (schedules.channelId == channel.site_id) { if (schedules.channelId == channel.site_id) {
items.push(...schedules.items) items.push(...schedules.items)
return true return true
} }
}) })
} }
return items return items
} }
function parseImage(item) { function parseImage(item) {
// image may have params such as width that needs to be substituted or removed for it load // image may have params such as width that needs to be substituted or removed for it load
return removeParameters(item.productPoster) return removeParameters(item.productPoster)
} }
function removeParameters(url) { function removeParameters(url) {
if (url) { if (url) {
try { try {
const urlObj = new URL(url) const urlObj = new URL(url)
urlObj.search = '' urlObj.search = ''
urlObj.hash = '' urlObj.hash = ''
return urlObj.toString() return urlObj.toString()
} catch { } catch {
return null return null
} }
} }
return url return url
} }