Make code prettier

This commit is contained in:
Aleksandr Statciuk 2022-12-29 23:50:36 +03:00
parent 268d150cc5
commit dd6d694491
31 changed files with 1079 additions and 1051 deletions

View file

@ -1,45 +1,45 @@
const dayjs = require('dayjs')
module.exports = {
site: 'sky.de',
skip: true, // server returns error 403 (https://github.com/iptv-org/epg/runs/5435899744?check_suite_focus=true)
url: `https://www.sky.de/sgtvg/service/getBroadcastsForGrid`,
request: {
method: 'POST',
data: function ({ channel, date }) {
return {
cil: [channel.site_id],
d: date.valueOf()
}
}
},
parser: function ({ content, channel }) {
const programs = []
const items = parseItems(content, channel)
items.forEach(item => {
programs.push({
title: item.et,
description: item.epit,
category: item.ec,
start: dayjs(item.bsdt),
stop: dayjs(item.bedt),
season: item.sn,
episode: item.en,
icon: item.pu ? `http://sky.de${item.pu}` : null
})
})
return programs
}
}
function parseContent(content, channel) {
const json = JSON.parse(content)
if (!Array.isArray(json.cl)) return null
return json.cl.find(i => i.ci == channel.site_id)
}
function parseItems(content, channel) {
const data = parseContent(content, channel)
return data && Array.isArray(data.el) ? data.el : []
}
const dayjs = require('dayjs')
module.exports = {
site: 'sky.de',
skip: true, // server returns error 403 (https://github.com/iptv-org/epg/runs/5435899744?check_suite_focus=true)
url: `https://www.sky.de/sgtvg/service/getBroadcastsForGrid`,
request: {
method: 'POST',
data: function ({ channel, date }) {
return {
cil: [channel.site_id],
d: date.valueOf()
}
}
},
parser: function ({ content, channel }) {
const programs = []
const items = parseItems(content, channel)
items.forEach(item => {
programs.push({
title: item.et,
description: item.epit,
category: item.ec,
start: dayjs(item.bsdt),
stop: dayjs(item.bedt),
season: item.sn,
episode: item.en,
icon: item.pu ? `http://sky.de${item.pu}` : null
})
})
return programs
}
}
function parseContent(content, channel) {
const json = JSON.parse(content)
if (!Array.isArray(json.cl)) return null
return json.cl.find(i => i.ci == channel.site_id)
}
function parseItems(content, channel) {
const data = parseContent(content, channel)
return data && Array.isArray(data.el) ? data.el : []
}

View file

@ -1,67 +1,67 @@
// npx epg-grabber --config=sites/sky.de/sky.de.config.js --channels=sites/sky.de/sky.de_de.channels.xml --output=guide.xml --days=2
const { parser, url, request } = require('./sky.de.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
const date = dayjs.utc('2022-02-28', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '522',
xmltv_id: 'WarnerTVComedyHD.de'
}
const content = `{"cl":[{"ci":522,"el":[{"ei":122309300,"bsdt":1645916700000,"bst":"00:05","bedt":1645918200000,"len":25,"et":"King of Queens","ec":"Comedyserie","cop":"USA","yop":2001,"fsk":"ab 0 Jahre","epit":"Der Experte","sn":"4","en":"11","pu":"/static/img/program_guide/1522936_s.jpg"},{"ei":122309301,"bsdt":1645918200000,"bst":"00:30","bedt":1645919700000,"len":25,"et":"King of Queens","ec":"Comedyserie","cop":"USA","yop":2001,"fsk":"ab 0 Jahre","epit":"Speedy Gonzales","sn":"4","en":"12","pu":"/static/img/program_guide/1522937_s.jpg"}]}]}`
it('can generate valid url', () => {
expect(url).toBe('https://www.sky.de/sgtvg/service/getBroadcastsForGrid')
})
it('can generate valid request method', () => {
expect(request.method).toBe('POST')
})
it('can generate valid request data', () => {
expect(request.data({ channel, date })).toMatchObject({
cil: [channel.site_id],
d: date.valueOf()
})
})
it('can parse response', () => {
const result = parser({ content, channel }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
title: 'King of Queens',
description: 'Der Experte',
category: 'Comedyserie',
start: '2022-02-26T23:05:00.000Z',
stop: '2022-02-26T23:30:00.000Z',
season: '4',
episode: '11',
icon: 'http://sky.de/static/img/program_guide/1522936_s.jpg'
},
{
title: 'King of Queens',
description: 'Speedy Gonzales',
category: 'Comedyserie',
start: '2022-02-26T23:30:00.000Z',
stop: '2022-02-26T23:55:00.000Z',
season: '4',
episode: '12',
icon: 'http://sky.de/static/img/program_guide/1522937_s.jpg'
}
])
})
it('can handle empty guide', () => {
const result = parser({
content: `[]`
})
expect(result).toMatchObject([])
})
// npx epg-grabber --config=sites/sky.de/sky.de.config.js --channels=sites/sky.de/sky.de_de.channels.xml --output=guide.xml --days=2
const { parser, url, request } = require('./sky.de.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
const date = dayjs.utc('2022-02-28', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '522',
xmltv_id: 'WarnerTVComedyHD.de'
}
const content = `{"cl":[{"ci":522,"el":[{"ei":122309300,"bsdt":1645916700000,"bst":"00:05","bedt":1645918200000,"len":25,"et":"King of Queens","ec":"Comedyserie","cop":"USA","yop":2001,"fsk":"ab 0 Jahre","epit":"Der Experte","sn":"4","en":"11","pu":"/static/img/program_guide/1522936_s.jpg"},{"ei":122309301,"bsdt":1645918200000,"bst":"00:30","bedt":1645919700000,"len":25,"et":"King of Queens","ec":"Comedyserie","cop":"USA","yop":2001,"fsk":"ab 0 Jahre","epit":"Speedy Gonzales","sn":"4","en":"12","pu":"/static/img/program_guide/1522937_s.jpg"}]}]}`
it('can generate valid url', () => {
expect(url).toBe('https://www.sky.de/sgtvg/service/getBroadcastsForGrid')
})
it('can generate valid request method', () => {
expect(request.method).toBe('POST')
})
it('can generate valid request data', () => {
expect(request.data({ channel, date })).toMatchObject({
cil: [channel.site_id],
d: date.valueOf()
})
})
it('can parse response', () => {
const result = parser({ content, channel }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
title: 'King of Queens',
description: 'Der Experte',
category: 'Comedyserie',
start: '2022-02-26T23:05:00.000Z',
stop: '2022-02-26T23:30:00.000Z',
season: '4',
episode: '11',
icon: 'http://sky.de/static/img/program_guide/1522936_s.jpg'
},
{
title: 'King of Queens',
description: 'Speedy Gonzales',
category: 'Comedyserie',
start: '2022-02-26T23:30:00.000Z',
stop: '2022-02-26T23:55:00.000Z',
season: '4',
episode: '12',
icon: 'http://sky.de/static/img/program_guide/1522937_s.jpg'
}
])
})
it('can handle empty guide', () => {
const result = parser({
content: `[]`
})
expect(result).toMatchObject([])
})