mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
Update andorradifusio.ad.config.js
This commit is contained in:
parent
9e928c1b87
commit
ba68a9cec8
1 changed files with 16 additions and 20 deletions
|
@ -1,17 +1,17 @@
|
|||
const jsdom = require('jsdom')
|
||||
const { JSDOM } = jsdom
|
||||
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')
|
||||
require('dayjs/locale/ca')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
|
||||
let PM = false
|
||||
module.exports = {
|
||||
lang: 'ca',
|
||||
days: 7,
|
||||
site: 'andorradifusio.ad',
|
||||
channels: 'andorradifusio.ad.channels.xml',
|
||||
output: '.gh-pages/guides/andorradifusio.ad.guide.xml',
|
||||
|
@ -19,10 +19,11 @@ module.exports = {
|
|||
return `https://www.andorradifusio.ad/programacio/${channel.site_id}`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let PM = false
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const title = parseTitle(item)
|
||||
const title = item.title
|
||||
let start = parseStart(item, date)
|
||||
if (start.hour() > 11) PM = true
|
||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||
|
@ -47,29 +48,24 @@ function parseStop(item, date) {
|
|||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
let time = (item.time || { textContent: '' }).textContent
|
||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
||||
time = `${date.format('MM/DD/YYYY')} ${item.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 $ = cheerio.load(content)
|
||||
const dayOfWeek = date.locale('ca').format('dddd').toLowerCase()
|
||||
const column = $('.programacio-dia > h3')
|
||||
.filter((i, el) => $(el).text().startsWith(dayOfWeek))
|
||||
.first()
|
||||
.parent()
|
||||
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) => {
|
||||
const titles = column.find(`p`).toArray()
|
||||
column.find(`h4`).each((i, time) => {
|
||||
items.push({
|
||||
time,
|
||||
title: titleRows[i]
|
||||
time: $(time).text(),
|
||||
title: $(titles[i]).text()
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue