mirror of
https://github.com/iptv-org/epg
synced 2026-04-28 05:26:59 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,101 +1,101 @@
|
||||
const axios = require('axios')
|
||||
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)
|
||||
|
||||
const API_ENDPOINT = 'https://www.dstv.com/umbraco/api/TvGuide'
|
||||
|
||||
module.exports = {
|
||||
site: 'dstv.com',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 3 * 60 * 60 * 1000, // 3h
|
||||
interpretHeader: false
|
||||
}
|
||||
},
|
||||
url: function ({ channel, date }) {
|
||||
const [region] = channel.site_id.split('#')
|
||||
const packageName = region === 'nga' ? '&package=DStv%20Premium' : ''
|
||||
|
||||
return `${API_ENDPOINT}/GetProgrammes?d=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}${packageName}&country=${region}`
|
||||
},
|
||||
async parser({ content, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
for (const item of items) {
|
||||
const details = await loadProgramDetails(item)
|
||||
programs.push({
|
||||
title: item.Title,
|
||||
description: parseDescription(details),
|
||||
icon: parseIcon(details),
|
||||
category: parseCategory(details),
|
||||
start: parseTime(item.StartTime, channel),
|
||||
stop: parseTime(item.EndTime, channel)
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ country }) {
|
||||
const data = await axios
|
||||
.get(`${API_ENDPOINT}/GetProgrammes?d=2022-03-10&package=DStv%20Premium&country=${country}`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.Channels.map(item => {
|
||||
return {
|
||||
site_id: `${country}#${item.Number}`,
|
||||
name: item.Name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseTime(time, channel) {
|
||||
const [region] = channel.site_id.split('#')
|
||||
const tz = {
|
||||
zaf: 'Africa/Johannesburg',
|
||||
nga: 'Africa/Lagos'
|
||||
}
|
||||
|
||||
return dayjs.tz(time, 'YYYY-MM-DDTHH:mm:ss', tz[region])
|
||||
}
|
||||
|
||||
function parseDescription(details) {
|
||||
return details ? details.Synopsis : null
|
||||
}
|
||||
|
||||
function parseIcon(details) {
|
||||
return details ? details.ThumbnailUri : null
|
||||
}
|
||||
|
||||
function parseCategory(details) {
|
||||
return details ? details.SubGenres : null
|
||||
}
|
||||
|
||||
async function loadProgramDetails(item) {
|
||||
const url = `${API_ENDPOINT}/GetProgramme?id=${item.Id}`
|
||||
|
||||
return axios
|
||||
.get(url)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
const [, channelId] = channel.site_id.split('#')
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data.Channels)) return []
|
||||
const channelData = data.Channels.find(c => c.Number === channelId)
|
||||
if (!channelData || !Array.isArray(channelData.Programmes)) return []
|
||||
|
||||
return channelData.Programmes
|
||||
}
|
||||
const axios = require('axios')
|
||||
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)
|
||||
|
||||
const API_ENDPOINT = 'https://www.dstv.com/umbraco/api/TvGuide'
|
||||
|
||||
module.exports = {
|
||||
site: 'dstv.com',
|
||||
days: 2,
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 3 * 60 * 60 * 1000, // 3h
|
||||
interpretHeader: false
|
||||
}
|
||||
},
|
||||
url: function ({ channel, date }) {
|
||||
const [region] = channel.site_id.split('#')
|
||||
const packageName = region === 'nga' ? '&package=DStv%20Premium' : ''
|
||||
|
||||
return `${API_ENDPOINT}/GetProgrammes?d=${date.format(
|
||||
'YYYY-MM-DD'
|
||||
)}${packageName}&country=${region}`
|
||||
},
|
||||
async parser({ content, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel)
|
||||
for (const item of items) {
|
||||
const details = await loadProgramDetails(item)
|
||||
programs.push({
|
||||
title: item.Title,
|
||||
description: parseDescription(details),
|
||||
icon: parseIcon(details),
|
||||
category: parseCategory(details),
|
||||
start: parseTime(item.StartTime, channel),
|
||||
stop: parseTime(item.EndTime, channel)
|
||||
})
|
||||
}
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels({ country }) {
|
||||
const data = await axios
|
||||
.get(`${API_ENDPOINT}/GetProgrammes?d=2022-03-10&package=DStv%20Premium&country=${country}`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.Channels.map(item => {
|
||||
return {
|
||||
site_id: `${country}#${item.Number}`,
|
||||
name: item.Name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseTime(time, channel) {
|
||||
const [region] = channel.site_id.split('#')
|
||||
const tz = {
|
||||
zaf: 'Africa/Johannesburg',
|
||||
nga: 'Africa/Lagos'
|
||||
}
|
||||
|
||||
return dayjs.tz(time, 'YYYY-MM-DDTHH:mm:ss', tz[region])
|
||||
}
|
||||
|
||||
function parseDescription(details) {
|
||||
return details ? details.Synopsis : null
|
||||
}
|
||||
|
||||
function parseIcon(details) {
|
||||
return details ? details.ThumbnailUri : null
|
||||
}
|
||||
|
||||
function parseCategory(details) {
|
||||
return details ? details.SubGenres : null
|
||||
}
|
||||
|
||||
async function loadProgramDetails(item) {
|
||||
const url = `${API_ENDPOINT}/GetProgramme?id=${item.Id}`
|
||||
|
||||
return axios
|
||||
.get(url)
|
||||
.then(r => r.data)
|
||||
.catch(console.error)
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
const [, channelId] = channel.site_id.split('#')
|
||||
const data = JSON.parse(content)
|
||||
if (!data || !Array.isArray(data.Channels)) return []
|
||||
const channelData = data.Channels.find(c => c.Number === channelId)
|
||||
if (!channelData || !Array.isArray(channelData.Programmes)) return []
|
||||
|
||||
return channelData.Programmes
|
||||
}
|
||||
|
||||
@@ -1,112 +1,112 @@
|
||||
// npm run channels:parse -- --config=./sites/dstv.com/dstv.com.config.js --output=./sites/dstv.com/dstv.com.channels.xml --set=country:zaf
|
||||
// npm run grab -- --site=dstv.com
|
||||
|
||||
const { parser, url } = require('./dstv.com.config.js')
|
||||
const axios = require('axios')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const API_ENDPOINT = 'https://www.dstv.com/umbraco/api/TvGuide'
|
||||
|
||||
const date = dayjs.utc('2022-11-22', 'YYYY-MM-DD').startOf('d')
|
||||
const channelZA = {
|
||||
site_id: 'zaf#201',
|
||||
xmltv_id: 'SuperSportGrandstand.za'
|
||||
}
|
||||
const channelNG = {
|
||||
site_id: 'nga#201',
|
||||
xmltv_id: 'SuperSportGrandstand.za'
|
||||
}
|
||||
|
||||
it('can generate valid url for zaf', () => {
|
||||
expect(url({ channel: channelZA, date })).toBe(
|
||||
`${API_ENDPOINT}/GetProgrammes?d=2022-11-22&country=zaf`
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for nga', () => {
|
||||
expect(url({ channel: channelNG, date })).toBe(
|
||||
`${API_ENDPOINT}/GetProgrammes?d=2022-11-22&package=DStv%20Premium&country=nga`
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response for ZA', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_zaf.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (url === `${API_ENDPOINT}/GetProgramme?id=8b237235-aa17-4bb8-9ea6-097e7a813336`) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program_zaf.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, channel: channelZA })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2022-11-21T23:00:00.000Z',
|
||||
stop: '2022-11-22T00:00:00.000Z',
|
||||
title: 'UFC FN HL: Nzechukwu v Cutelaba',
|
||||
description:
|
||||
"'UFC Fight Night Highlights - Heavyweight Bout: Kennedy Nzechukwu vs Ion Cutelaba'. From The UFC APEX Center - Las Vegas, USA.",
|
||||
icon: 'https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/271546_UFC Fight Night.png',
|
||||
category: ['All Sport', 'Mixed Martial Arts']
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response for NG', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_nga.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (url === `${API_ENDPOINT}/GetProgramme?id=6d58931e-2192-486a-a202-14720136d204`) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program_nga.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, channel: channelNG })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-21T23:00:00.000Z',
|
||||
stop: '2022-11-22T00:00:00.000Z',
|
||||
title: 'UFC FN HL: Nzechukwu v Cutelaba',
|
||||
description:
|
||||
"'UFC Fight Night Highlights - Heavyweight Bout: Kennedy Nzechukwu vs Ion Cutelaba'. From The UFC APEX Center - Las Vegas, USA.",
|
||||
icon: 'https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/271546_UFC Fight Night.png',
|
||||
category: ['All Sport', 'Mixed Martial Arts']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', done => {
|
||||
parser({
|
||||
content: '{"Total":0,"Channels":[]}',
|
||||
channel: channelZA
|
||||
})
|
||||
.then(result => {
|
||||
expect(result).toMatchObject([])
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/dstv.com/dstv.com.config.js --output=./sites/dstv.com/dstv.com.channels.xml --set=country:zaf
|
||||
// npm run grab -- --site=dstv.com
|
||||
|
||||
const { parser, url } = require('./dstv.com.config.js')
|
||||
const axios = require('axios')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const API_ENDPOINT = 'https://www.dstv.com/umbraco/api/TvGuide'
|
||||
|
||||
const date = dayjs.utc('2022-11-22', 'YYYY-MM-DD').startOf('d')
|
||||
const channelZA = {
|
||||
site_id: 'zaf#201',
|
||||
xmltv_id: 'SuperSportGrandstand.za'
|
||||
}
|
||||
const channelNG = {
|
||||
site_id: 'nga#201',
|
||||
xmltv_id: 'SuperSportGrandstand.za'
|
||||
}
|
||||
|
||||
it('can generate valid url for zaf', () => {
|
||||
expect(url({ channel: channelZA, date })).toBe(
|
||||
`${API_ENDPOINT}/GetProgrammes?d=2022-11-22&country=zaf`
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for nga', () => {
|
||||
expect(url({ channel: channelNG, date })).toBe(
|
||||
`${API_ENDPOINT}/GetProgrammes?d=2022-11-22&package=DStv%20Premium&country=nga`
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response for ZA', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_zaf.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (url === `${API_ENDPOINT}/GetProgramme?id=8b237235-aa17-4bb8-9ea6-097e7a813336`) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program_zaf.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, channel: channelZA })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2022-11-21T23:00:00.000Z',
|
||||
stop: '2022-11-22T00:00:00.000Z',
|
||||
title: 'UFC FN HL: Nzechukwu v Cutelaba',
|
||||
description:
|
||||
"'UFC Fight Night Highlights - Heavyweight Bout: Kennedy Nzechukwu vs Ion Cutelaba'. From The UFC APEX Center - Las Vegas, USA.",
|
||||
icon: 'https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/271546_UFC Fight Night.png',
|
||||
category: ['All Sport', 'Mixed Martial Arts']
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response for NG', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_nga.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (url === `${API_ENDPOINT}/GetProgramme?id=6d58931e-2192-486a-a202-14720136d204`) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program_nga.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, channel: channelNG })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-21T23:00:00.000Z',
|
||||
stop: '2022-11-22T00:00:00.000Z',
|
||||
title: 'UFC FN HL: Nzechukwu v Cutelaba',
|
||||
description:
|
||||
"'UFC Fight Night Highlights - Heavyweight Bout: Kennedy Nzechukwu vs Ion Cutelaba'. From The UFC APEX Center - Las Vegas, USA.",
|
||||
icon: 'https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/271546_UFC Fight Night.png',
|
||||
category: ['All Sport', 'Mixed Martial Arts']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', done => {
|
||||
parser({
|
||||
content: '{"Total":0,"Channels":[]}',
|
||||
channel: channelZA
|
||||
})
|
||||
.then(result => {
|
||||
expect(result).toMatchObject([])
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user