mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -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 { JSDOM } = jsdom
|
||||||
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 customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
|
let PM = false
|
||||||
module.exports = {
|
module.exports = {
|
||||||
lang: 'ca',
|
lang: 'ca',
|
||||||
site: 'andorradifusio.ad',
|
site: 'andorradifusio.ad',
|
||||||
|
@ -16,36 +19,59 @@ module.exports = {
|
||||||
return `https://www.andorradifusio.ad/programacio/${channel.site_id}`
|
return `https://www.andorradifusio.ad/programacio/${channel.site_id}`
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date }) {
|
||||||
const day = date.day() - 1
|
|
||||||
const programs = []
|
const programs = []
|
||||||
const dom = new JSDOM(content)
|
const items = parseItems(content, date)
|
||||||
const cols = dom.window.document.querySelectorAll('.programacio-dia')
|
items.forEach(item => {
|
||||||
const colNum = day < 0 ? 6 : day
|
const title = parseTitle(item)
|
||||||
const times = cols[colNum].querySelectorAll(`h4`)
|
let start = parseStart(item, date)
|
||||||
const titles = cols[colNum].querySelectorAll(`p`)
|
if (start.hour() > 11) PM = true
|
||||||
|
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||||
times.forEach((time, i) => {
|
const stop = parseStop(item, date)
|
||||||
const title = titles[i] ? titles[i].textContent : null
|
if (programs.length) {
|
||||||
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) {
|
|
||||||
programs[programs.length - 1].stop = start
|
programs[programs.length - 1].stop = start
|
||||||
}
|
}
|
||||||
|
|
||||||
programs.push({
|
programs.push({
|
||||||
title,
|
title,
|
||||||
start
|
start,
|
||||||
|
stop
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
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