mirror of
https://github.com/iptv-org/epg
synced 2026-04-30 14:36:58 -04:00
Fix linter issues in sites/
This commit is contained in:
@@ -1,74 +1,79 @@
|
||||
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
|
||||
}
|
||||
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
|
||||
}
|
||||
|
||||
@@ -1,36 +1,40 @@
|
||||
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([])
|
||||
})
|
||||
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([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user