mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
Create sporttv.pt.config.js
This commit is contained in:
parent
eb10f8207b
commit
a7bd3204be
1 changed files with 63 additions and 0 deletions
63
sites/sporttv.pt/sporttv.pt.config.js
Normal file
63
sites/sporttv.pt/sporttv.pt.config.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
|
||||
module.exports = {
|
||||
site: 'sporttv.pt',
|
||||
days: 2,
|
||||
url: 'https://www.sporttv.pt/guia',
|
||||
parser({ content, date, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel, date)
|
||||
items.forEach(item => {
|
||||
const start = dayjs(item.data)
|
||||
const stop = start.add(item.duracao, 'ms')
|
||||
|
||||
programs.push({
|
||||
title: item.descricao,
|
||||
description: item?.evento?.nome,
|
||||
image: item.imagem,
|
||||
category: item?.modalidade?.nomeModalidade,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseItems(content, channel, date) {
|
||||
const $ = cheerio.load(content)
|
||||
const nuxtData = $('#__NUXT_DATA__').html()
|
||||
if (!nuxtData) return []
|
||||
const parsed = JSON.parse(nuxtData)
|
||||
const dataIndex = parsed[1].data
|
||||
const epgIndex = Object.values(parsed[dataIndex])[3] // 1611
|
||||
const epg = parsed[epgIndex].map(i => parsed[i]).map(obj => dataMapper(obj, parsed))
|
||||
if (!Array.isArray(epg)) return []
|
||||
|
||||
return epg
|
||||
.filter(
|
||||
item => item.canal.id === parseInt(channel.site_id) && date.isSame(dayjs(item.data), 'd')
|
||||
)
|
||||
.sort((a, b) => {
|
||||
if (a < b) return -1
|
||||
if (a > b) return 1
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
||||
function dataMapper(object, parsed) {
|
||||
let output = {}
|
||||
|
||||
for (let key in object) {
|
||||
const value = parsed[object[key]]
|
||||
if (typeof value === 'object') {
|
||||
output[key] = dataMapper(value, parsed)
|
||||
} else {
|
||||
output[key] = value
|
||||
}
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue