mirror of
https://github.com/iptv-org/epg
synced 2026-09-10 22:06:56 -04:00
Fixes sporttv.pt parser
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
const dayjs = require('dayjs')
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
|
||||
module.exports = {
|
||||
site: 'sporttv.pt',
|
||||
days: 2,
|
||||
|
||||
url: 'https://www.sporttv.pt/guia',
|
||||
request: {
|
||||
headers: {
|
||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/149.0.0.0 Safari/537.36',
|
||||
'X-Client-Platform': 'web',
|
||||
'X-Device-Platform': 'web'
|
||||
}
|
||||
},
|
||||
url({ date, channel }) {
|
||||
const startDate = date.format('DD/MM/YYYY%20HH:mm')
|
||||
const endDate = date.add(1, 'day').format('DD/MM/YYYY%20HH:mm')
|
||||
return `https://www.sporttv.pt/api/channels/epg?dataInicio=${startDate}&dataFim=${endDate}&tipoMedia=thumbnail&idCanal=${channel.site_id}`
|
||||
},
|
||||
parser({ content, date, channel }) {
|
||||
let programs = []
|
||||
const items = parseItems(content, channel, date)
|
||||
@@ -24,20 +34,32 @@ module.exports = {
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
let access = axios.get('https://www.sporttv.pt/api/channels/live', { headers: this.request.headers })
|
||||
|
||||
let { data } = await access
|
||||
data = data.filter(item => item.id !== 0)
|
||||
return data.map(item_1 => ({
|
||||
site_id: item_1.id,
|
||||
name: item_1.nome,
|
||||
logo: item_1.logo_url
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
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 []
|
||||
if (!content) return []
|
||||
let json_data
|
||||
try {
|
||||
json_data = JSON.parse(content)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch (e) {
|
||||
return []
|
||||
}
|
||||
if (!Array.isArray(json_data)) return []
|
||||
|
||||
return epg
|
||||
return json_data
|
||||
.filter(
|
||||
item => item.canal.id === parseInt(channel.site_id) && date.isSame(dayjs(item.data), 'd')
|
||||
)
|
||||
@@ -46,19 +68,4 @@ function parseItems(content, channel, date) {
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user