mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update programacion-tv.elpais.com.config.js
This commit is contained in:
parent
165a34c382
commit
1f93d62d72
1 changed files with 86 additions and 18 deletions
|
@ -1,3 +1,4 @@
|
|||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
@ -7,30 +8,97 @@ dayjs.extend(timezone)
|
|||
|
||||
module.exports = {
|
||||
site: 'programacion-tv.elpais.com',
|
||||
request: {
|
||||
cache: {
|
||||
ttl: 60 * 60 * 1000 // 1 hour
|
||||
}
|
||||
},
|
||||
url: function ({ date }) {
|
||||
return `https://programacion-tv.elpais.com/data/parrilla_${date.format('DDMMYYYY')}.json`
|
||||
},
|
||||
parser: function ({ content, date, channel }) {
|
||||
parser: async function ({ content, channel }) {
|
||||
const programs = []
|
||||
const data = JSON.parse(content)
|
||||
const channelData = data.find(i => i.idCanal === channel.site_id)
|
||||
if (!channelData) return programs
|
||||
channelData.programas.forEach(item => {
|
||||
if (item.title && item.iniDate && item.endDate) {
|
||||
const startLocal = dayjs.utc(item.iniDate).toString()
|
||||
const start = dayjs.tz(startLocal.toString(), 'Europe/Madrid')
|
||||
const stopLocal = dayjs.utc(item.endDate).toString()
|
||||
const stop = dayjs.tz(stopLocal.toString(), 'Europe/Madrid')
|
||||
programs.push({
|
||||
title: item.title,
|
||||
description: item.description,
|
||||
category: item.txtSection,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
}
|
||||
const items = parseItems(content, channel)
|
||||
if (!items.length) return programs
|
||||
const programsData = await loadProgramsData(channel)
|
||||
items.forEach(item => {
|
||||
const start = parseStart(item)
|
||||
const stop = parseStop(item)
|
||||
const details = programsData.find(p => p.id_programa === item.id_programa) || {}
|
||||
programs.push({
|
||||
title: item.title,
|
||||
sub_title: details.episode_title,
|
||||
description: details.episode_description || item.description,
|
||||
category: parseCategory(details),
|
||||
icon: parseIcon(details),
|
||||
director: parseList(details.director),
|
||||
actors: parseList(details.actors),
|
||||
writer: parseList(details.script),
|
||||
producer: parseList(details.producer),
|
||||
presenter: parseList(details.presented_by),
|
||||
composer: parseList(details.music),
|
||||
guest: parseList(details.guest_actors),
|
||||
season: parseNumber(details.season),
|
||||
episode: parseNumber(details.episode),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get(`https://programacion-tv.elpais.com/data/canales.json`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
|
||||
return Object.values(data).map(item => ({
|
||||
lang: 'es',
|
||||
site_id: item.id,
|
||||
name: item.nombre
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
function parseNumber(str) {
|
||||
return typeof str === 'string' ? parseInt(str) : null
|
||||
}
|
||||
|
||||
function parseList(str) {
|
||||
return typeof str === 'string' ? str.split(', ') : []
|
||||
}
|
||||
|
||||
function parseIcon(details) {
|
||||
const url = new URL(details.image, 'https://programacion-tv.elpais.com/')
|
||||
|
||||
return url.href
|
||||
}
|
||||
|
||||
function parseCategory(details) {
|
||||
return [details.txt_genre, details.txt_subgenre].filter(Boolean).join('/')
|
||||
}
|
||||
|
||||
async function loadProgramsData(channel) {
|
||||
return await axios
|
||||
.get(`https://programacion-tv.elpais.com/data/programas/${channel.site_id}.json`)
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
}
|
||||
|
||||
function parseStart(item) {
|
||||
return dayjs.tz(item.iniDate, 'YYYY-MM-DD HH:mm:ss', 'Europe/Madrid')
|
||||
}
|
||||
|
||||
function parseStop(item) {
|
||||
return dayjs.tz(item.endDate, 'YYYY-MM-DD HH:mm:ss', 'Europe/Madrid')
|
||||
}
|
||||
|
||||
function parseItems(content, channel) {
|
||||
if (!content) return []
|
||||
const data = JSON.parse(content)
|
||||
const channelData = data.find(i => i.idCanal === channel.site_id)
|
||||
if (!channelData || !Array.isArray(channelData.programas)) return []
|
||||
|
||||
return channelData.programas
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue