mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 17:40:07 -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 cheerio = require('cheerio')
|
||||||
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 timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
require('dayjs/locale/ca')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(timezone)
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
let PM = false
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
lang: 'ca',
|
lang: 'ca',
|
||||||
|
days: 7,
|
||||||
site: 'andorradifusio.ad',
|
site: 'andorradifusio.ad',
|
||||||
channels: 'andorradifusio.ad.channels.xml',
|
channels: 'andorradifusio.ad.channels.xml',
|
||||||
output: '.gh-pages/guides/andorradifusio.ad.guide.xml',
|
output: '.gh-pages/guides/andorradifusio.ad.guide.xml',
|
||||||
|
@ -19,10 +19,11 @@ 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 }) {
|
||||||
|
let PM = false
|
||||||
const programs = []
|
const programs = []
|
||||||
const items = parseItems(content, date)
|
const items = parseItems(content, date)
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
const title = parseTitle(item)
|
const title = item.title
|
||||||
let start = parseStart(item, date)
|
let start = parseStart(item, date)
|
||||||
if (start.hour() > 11) PM = true
|
if (start.hour() > 11) PM = true
|
||||||
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
if (start.hour() < 12 && PM) start = start.add(1, 'd')
|
||||||
|
@ -47,29 +48,24 @@ function parseStop(item, date) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseStart(item, date) {
|
function parseStart(item, date) {
|
||||||
let time = (item.time || { textContent: '' }).textContent
|
time = `${date.format('MM/DD/YYYY')} ${item.time}`
|
||||||
time = `${date.format('MM/DD/YYYY')} ${time}`
|
|
||||||
|
|
||||||
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Madrid')
|
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Madrid')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseTitle(item) {
|
|
||||||
return (item.title || { textContent: '' }).textContent
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseItems(content, date) {
|
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 items = []
|
||||||
const dom = new JSDOM(content)
|
const titles = column.find(`p`).toArray()
|
||||||
const day = date.day() - 1
|
column.find(`h4`).each((i, time) => {
|
||||||
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({
|
items.push({
|
||||||
time,
|
time: $(time).text(),
|
||||||
title: titleRows[i]
|
title: $(titles[i]).text()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue