mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update andorradifusio.ad.config.js
This commit is contained in:
parent
22b197d3f4
commit
8a963da78c
1 changed files with 47 additions and 21 deletions
|
@ -2,11 +2,14 @@ const jsdom = require('jsdom')
|
|||
const { JSDOM } = jsdom
|
||||
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)
|
||||
|
||||
let PM = false
|
||||
module.exports = {
|
||||
lang: 'ca',
|
||||
site: 'andorradifusio.ad',
|
||||
|
@ -16,36 +19,59 @@ module.exports = {
|
|||
return `https://www.andorradifusio.ad/programacio/${channel.site_id}`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const day = date.day() - 1
|
||||
const programs = []
|
||||
const dom = new JSDOM(content)
|
||||
const cols = dom.window.document.querySelectorAll('.programacio-dia')
|
||||
const colNum = day < 0 ? 6 : day
|
||||
const times = cols[colNum].querySelectorAll(`h4`)
|
||||
const titles = cols[colNum].querySelectorAll(`p`)
|
||||
|
||||
times.forEach((time, i) => {
|
||||
const title = titles[i] ? titles[i].textContent : null
|
||||
if (!time || !title) return false
|
||||
|
||||
const start = dayjs
|
||||
.utc(time.textContent, 'HH:mm')
|
||||
.set('D', date.get('D'))
|
||||
.set('M', date.get('M'))
|
||||
.set('y', date.get('y'))
|
||||
|
||||
if (!start.isValid()) return false
|
||||
|
||||
if (programs.length && !programs[programs.length - 1].stop) {
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const title = parseTitle(item)
|
||||
let start = parseStart(item, date)
|
||||
if (start.hour() > 11) PM = true
|
||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||
const stop = parseStop(item, date)
|
||||
if (programs.length) {
|
||||
programs[programs.length - 1].stop = start
|
||||
}
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
start
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStop(item, date) {
|
||||
return date.tz('Europe/Madrid').endOf('d').add(6, 'h')
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
let time = (item.time || { textContent: '' }).textContent
|
||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
||||
|
||||
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Madrid')
|
||||
}
|
||||
|
||||
function parseTitle(item) {
|
||||
return (item.title || { textContent: '' }).textContent
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
const items = []
|
||||
const dom = new JSDOM(content)
|
||||
const day = date.day() - 1
|
||||
const colNum = day < 0 ? 6 : day
|
||||
const cols = dom.window.document.querySelectorAll('.programacio-dia')
|
||||
const col = cols[colNum]
|
||||
const timeRows = col.querySelectorAll(`h4`)
|
||||
const titleRows = col.querySelectorAll(`p`)
|
||||
timeRows.forEach((time, i) => {
|
||||
items.push({
|
||||
time,
|
||||
title: titleRows[i]
|
||||
})
|
||||
})
|
||||
|
||||
return items
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue