mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 10:26:41 -05:00
Fixes linter errors
This commit is contained in:
@@ -1,55 +1,55 @@
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'sky.co.nz',
|
||||
days: 2,
|
||||
url({ date, channel }) {
|
||||
return `https://web-epg.sky.co.nz/prod/epgs/v1?channelNumber=${
|
||||
channel.site_id
|
||||
}&start=${date.valueOf()}&end=${date.add(1, 'day').valueOf()}&limit=20000`
|
||||
},
|
||||
parser({ content }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.synopsis,
|
||||
category: item.genres,
|
||||
rating: parseRating(item),
|
||||
start: dayjs(parseInt(item.start)),
|
||||
stop: dayjs(parseInt(item.end))
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://skywebconfig.msl-prod.skycloud.co.nz/sky/json/channels.prod.json')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.channels.map(item => {
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id: parseInt(item.number).toString(),
|
||||
name: item.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const data = JSON.parse(content)
|
||||
return data && data.events && Array.isArray(data.events) ? data.events : []
|
||||
}
|
||||
|
||||
function parseRating(item) {
|
||||
if (!item.rating) return null
|
||||
return {
|
||||
system: 'OFLC',
|
||||
value: item.rating
|
||||
}
|
||||
}
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
|
||||
module.exports = {
|
||||
site: 'sky.co.nz',
|
||||
days: 2,
|
||||
url({ date, channel }) {
|
||||
return `https://web-epg.sky.co.nz/prod/epgs/v1?channelNumber=${
|
||||
channel.site_id
|
||||
}&start=${date.valueOf()}&end=${date.add(1, 'day').valueOf()}&limit=20000`
|
||||
},
|
||||
parser({ content }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.synopsis,
|
||||
category: item.genres,
|
||||
rating: parseRating(item),
|
||||
start: dayjs(parseInt(item.start)),
|
||||
stop: dayjs(parseInt(item.end))
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://skywebconfig.msl-prod.skycloud.co.nz/sky/json/channels.prod.json')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return data.channels.map(item => {
|
||||
return {
|
||||
lang: 'en',
|
||||
site_id: parseInt(item.number).toString(),
|
||||
name: item.name
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const data = JSON.parse(content)
|
||||
return data && data.events && Array.isArray(data.events) ? data.events : []
|
||||
}
|
||||
|
||||
function parseRating(item) {
|
||||
if (!item.rating) return null
|
||||
return {
|
||||
system: 'OFLC',
|
||||
value: item.rating
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,62 +1,62 @@
|
||||
// npm run grab -- --site=sky.co.nz
|
||||
|
||||
const { parser, url } = require('./sky.co.nz.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2023-01-21', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '36',
|
||||
xmltv_id: 'SkyMoviesFamily.nz'
|
||||
}
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://web-epg.sky.co.nz/prod/epgs/v1?channelNumber=36&start=1674259200000&end=1674345600000&limit=20000'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const result = parser({ content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result[0]).toMatchObject({
|
||||
title: 'Sing 2',
|
||||
description:
|
||||
"Animated: Buster Moon and his friends must persuade the world's most reclusive rock star to help launch their most dazzling extravaganza yet. Voices Of: Matthew McConaughey, Reese Witherspoon (2021)",
|
||||
category: ['Animated'],
|
||||
rating: { system: 'OFLC', value: 'PG' },
|
||||
start: '2023-01-20T23:41:00.000Z',
|
||||
stop: '2023-01-21T01:28:00.000Z'
|
||||
})
|
||||
|
||||
expect(result[5]).toMatchObject({
|
||||
title: 'Harry Potter and the Goblet of Fire',
|
||||
description:
|
||||
'Adventure: Harry is selected to represent Hogwarts at a legendary and dangerous wizardry competition between three schools of magic. Stars: Daniel Radcliffe, Rupert Grint (2005)',
|
||||
category: ['Action/Adventure'],
|
||||
rating: { system: 'OFLC', value: 'M-V' },
|
||||
start: '2023-01-21T07:42:00.000Z',
|
||||
stop: '2023-01-21T10:13:00.000Z'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser(
|
||||
{
|
||||
content: `{
|
||||
"code": "DATE_FORMAT_ERROR",
|
||||
"description": "DateFormat error",
|
||||
"message": "Unparseable date: x"
|
||||
}`
|
||||
},
|
||||
channel
|
||||
)
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
// npm run grab -- --site=sky.co.nz
|
||||
|
||||
const { parser, url } = require('./sky.co.nz.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2023-01-21', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '36',
|
||||
xmltv_id: 'SkyMoviesFamily.nz'
|
||||
}
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://web-epg.sky.co.nz/prod/epgs/v1?channelNumber=36&start=1674259200000&end=1674345600000&limit=20000'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const result = parser({ content }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result[0]).toMatchObject({
|
||||
title: 'Sing 2',
|
||||
description:
|
||||
"Animated: Buster Moon and his friends must persuade the world's most reclusive rock star to help launch their most dazzling extravaganza yet. Voices Of: Matthew McConaughey, Reese Witherspoon (2021)",
|
||||
category: ['Animated'],
|
||||
rating: { system: 'OFLC', value: 'PG' },
|
||||
start: '2023-01-20T23:41:00.000Z',
|
||||
stop: '2023-01-21T01:28:00.000Z'
|
||||
})
|
||||
|
||||
expect(result[5]).toMatchObject({
|
||||
title: 'Harry Potter and the Goblet of Fire',
|
||||
description:
|
||||
'Adventure: Harry is selected to represent Hogwarts at a legendary and dangerous wizardry competition between three schools of magic. Stars: Daniel Radcliffe, Rupert Grint (2005)',
|
||||
category: ['Action/Adventure'],
|
||||
rating: { system: 'OFLC', value: 'M-V' },
|
||||
start: '2023-01-21T07:42:00.000Z',
|
||||
stop: '2023-01-21T10:13:00.000Z'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser(
|
||||
{
|
||||
content: `{
|
||||
"code": "DATE_FORMAT_ERROR",
|
||||
"description": "DateFormat error",
|
||||
"message": "Unparseable date: x"
|
||||
}`
|
||||
},
|
||||
channel
|
||||
)
|
||||
expect(result).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user