mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 08:30:06 -04:00
Create tvi.iol.pt.config.js
This commit is contained in:
parent
504398f079
commit
50dddecfe8
1 changed files with 76 additions and 0 deletions
76
sites/tvi.iol.pt/tvi.iol.pt.config.js
Normal file
76
sites/tvi.iol.pt/tvi.iol.pt.config.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
const cheerio = require('cheerio')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
module.exports = {
|
||||
site: 'tvi.iol.pt',
|
||||
url({ channel, date }) {
|
||||
return `https://tvi.iol.pt/emissao/dia/${channel.site_id}?data=${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let programs = []
|
||||
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
const $item = cheerio.load(item)
|
||||
|
||||
let start = parseStart($item, date)
|
||||
if (prev) {
|
||||
if (start.isBefore(prev.start)) {
|
||||
start = start.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
prev.stop = start
|
||||
}
|
||||
|
||||
const stop = start.add(30, 'm')
|
||||
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.guiatv-programa > h2').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.guiatv-programa > .texto, .guiatv-programa > .texto2').text().trim() || null
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
const backgroundImage = $item('.picture16x9').css('background-image')
|
||||
if (!backgroundImage) return null
|
||||
const [, imageUrl] = backgroundImage.match(/url\((.*)\)/) || [null, null]
|
||||
if (!imageUrl) return null
|
||||
|
||||
return imageUrl
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const timezone = 'Europe/Madrid'
|
||||
const time = $item('.hora').text().trim()
|
||||
|
||||
return dayjs.tz(`${date.tz(timezone).format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', timezone)
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.guiatv-linha').toArray()
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue