mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -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 dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const timezone = require('dayjs/plugin/timezone')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
|
@ -7,30 +8,97 @@ dayjs.extend(timezone)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'programacion-tv.elpais.com',
|
site: 'programacion-tv.elpais.com',
|
||||||
|
request: {
|
||||||
|
cache: {
|
||||||
|
ttl: 60 * 60 * 1000 // 1 hour
|
||||||
|
}
|
||||||
|
},
|
||||||
url: function ({ date }) {
|
url: function ({ date }) {
|
||||||
return `https://programacion-tv.elpais.com/data/parrilla_${date.format('DDMMYYYY')}.json`
|
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 programs = []
|
||||||
const data = JSON.parse(content)
|
const items = parseItems(content, channel)
|
||||||
const channelData = data.find(i => i.idCanal === channel.site_id)
|
if (!items.length) return programs
|
||||||
if (!channelData) return programs
|
const programsData = await loadProgramsData(channel)
|
||||||
channelData.programas.forEach(item => {
|
items.forEach(item => {
|
||||||
if (item.title && item.iniDate && item.endDate) {
|
const start = parseStart(item)
|
||||||
const startLocal = dayjs.utc(item.iniDate).toString()
|
const stop = parseStop(item)
|
||||||
const start = dayjs.tz(startLocal.toString(), 'Europe/Madrid')
|
const details = programsData.find(p => p.id_programa === item.id_programa) || {}
|
||||||
const stopLocal = dayjs.utc(item.endDate).toString()
|
programs.push({
|
||||||
const stop = dayjs.tz(stopLocal.toString(), 'Europe/Madrid')
|
title: item.title,
|
||||||
programs.push({
|
sub_title: details.episode_title,
|
||||||
title: item.title,
|
description: details.episode_description || item.description,
|
||||||
description: item.description,
|
category: parseCategory(details),
|
||||||
category: item.txtSection,
|
icon: parseIcon(details),
|
||||||
start,
|
director: parseList(details.director),
|
||||||
stop
|
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
|
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