Fix linter issues in sites/

This commit is contained in:
freearhey
2025-01-01 12:27:22 +03:00
parent d6d20b6413
commit 5df982bb7c
129 changed files with 3316 additions and 3226 deletions

View File

@@ -1,81 +1,81 @@
const parser = require('epg-parser')
module.exports = {
site: 'nzxmltv.com',
days: 2,
request: {
cache: {
ttl: 3600000 // 1 hour
},
maxContentLength: 104857600 // 100 MB
},
url({ channel }) {
const [path] = channel.site_id.split('#')
return `https://nzxmltv.com/${path}.xml`
},
parser({ content, channel, date }) {
const programs = []
parseItems(content, channel, date).forEach(item => {
const program = {
title: item.title?.[0]?.value,
description: item.desc?.[0]?.value,
icon: item.icon?.[0],
start: item.start,
stop: item.stop
}
if (item.episodeNum) {
item.episodeNum.forEach(ep => {
if (ep.system === 'xmltv_ns') {
const [season, episode, _] = ep.value.split('.')
program.season = parseInt(season) + 1
program.episode = parseInt(episode) + 1
return true
}
})
}
programs.push(program)
})
return programs
},
async channels({ provider }) {
const axios = require('axios')
const cheerio = require('cheerio')
const providers = {
freeview: 'xmltv/guide',
sky: 'sky/guide',
redbull: 'iptv/redbull',
pluto: 'iptv/plutotv'
}
const channels = []
const path = providers[provider]
const xml = await axios
.get(`https://nzxmltv.com/${path}.xml`)
.then(r => r.data)
.catch(console.error)
const $ = cheerio.load(xml)
$('tv channel').each((i, el) => {
const disp = $(el).find('display-name')
const channelId = $(el).attr('id')
channels.push({
lang: disp.attr('lang').substr(0, 2),
site_id: `${path}#${channelId}`,
name: disp.text().trim()
})
})
return channels
}
}
function parseItems(content, channel, date) {
const { programs } = parser.parse(content)
const [, channelId] = channel.site_id.split('#')
return programs.filter(p => p.channel === channelId && date.isSame(p.start, 'day'))
}
const parser = require('epg-parser')
module.exports = {
site: 'nzxmltv.com',
days: 2,
request: {
cache: {
ttl: 3600000 // 1 hour
},
maxContentLength: 104857600 // 100 MB
},
url({ channel }) {
const [path] = channel.site_id.split('#')
return `https://nzxmltv.com/${path}.xml`
},
parser({ content, channel, date }) {
const programs = []
parseItems(content, channel, date).forEach(item => {
const program = {
title: item.title?.[0]?.value,
description: item.desc?.[0]?.value,
icon: item.icon?.[0],
start: item.start,
stop: item.stop
}
if (item.episodeNum) {
item.episodeNum.forEach(ep => {
if (ep.system === 'xmltv_ns') {
const [season, episode] = ep.value.split('.')
program.season = parseInt(season) + 1
program.episode = parseInt(episode) + 1
return true
}
})
}
programs.push(program)
})
return programs
},
async channels({ provider }) {
const axios = require('axios')
const cheerio = require('cheerio')
const providers = {
freeview: 'xmltv/guide',
sky: 'sky/guide',
redbull: 'iptv/redbull',
pluto: 'iptv/plutotv'
}
const channels = []
const path = providers[provider]
const xml = await axios
.get(`https://nzxmltv.com/${path}.xml`)
.then(r => r.data)
.catch(console.error)
const $ = cheerio.load(xml)
$('tv channel').each((i, el) => {
const disp = $(el).find('display-name')
const channelId = $(el).attr('id')
channels.push({
lang: disp.attr('lang').substr(0, 2),
site_id: `${path}#${channelId}`,
name: disp.text().trim()
})
})
return channels
}
}
function parseItems(content, channel, date) {
const { programs } = parser.parse(content)
const [, channelId] = channel.site_id.split('#')
return programs.filter(p => p.channel === channelId && date.isSame(p.start, 'day'))
}

View File

@@ -1,40 +1,40 @@
const { parser, url } = require('./nzxmltv.com.config.js')
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)
const date = dayjs.utc('2023-11-21').startOf('d')
const channel = {
site_id: 'xmltv/guide#1',
xmltv_id: 'TVNZ1.nz'
}
it('can generate valid url', () => {
expect(url({ channel })).toBe('https://nzxmltv.com/xmltv/guide.xml')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.xml'))
const results = parser({ content, channel, date })
expect(results[0]).toMatchObject({
start: '2023-11-21T10:30:00.000Z',
stop: '2023-11-21T11:25:00.000Z',
title: 'Sunday',
description:
'On Sunday, an unmissable show with stories about divorce, weight loss, and the incomprehensible devastation of Gaza.',
season: 2023,
episode: 37,
icon: 'https://www.thetvdb.com/banners/posters/5dbebff2986f2.jpg'
})
})
it('can handle empty guide', () => {
const result = parser({ content: '', channel, date })
expect(result).toMatchObject([])
})
const { parser, url } = require('./nzxmltv.com.config.js')
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)
const date = dayjs.utc('2023-11-21').startOf('d')
const channel = {
site_id: 'xmltv/guide#1',
xmltv_id: 'TVNZ1.nz'
}
it('can generate valid url', () => {
expect(url({ channel })).toBe('https://nzxmltv.com/xmltv/guide.xml')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.xml'))
const results = parser({ content, channel, date })
expect(results[0]).toMatchObject({
start: '2023-11-21T10:30:00.000Z',
stop: '2023-11-21T11:25:00.000Z',
title: 'Sunday',
description:
'On Sunday, an unmissable show with stories about divorce, weight loss, and the incomprehensible devastation of Gaza.',
season: 2023,
episode: 37,
icon: 'https://www.thetvdb.com/banners/posters/5dbebff2986f2.jpg'
})
})
it('can handle empty guide', () => {
const result = parser({ content: '', channel, date })
expect(result).toMatchObject([])
})