mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
Create commands/load-cluster.js
This commit is contained in:
parent
f5dbc9376e
commit
a1f0bc2d2a
10 changed files with 29683 additions and 29503 deletions
65
tests/__data__/input/site.config.js
Normal file
65
tests/__data__/input/site.config.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
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)
|
||||
|
||||
module.exports = {
|
||||
site: 'andorradifusio.ad',
|
||||
url({ channel }) {
|
||||
return `https://www.andorradifusio.ad/programacio/${channel.site_id}`
|
||||
},
|
||||
parser({ content, date }) {
|
||||
const programs = []
|
||||
const items = parseItems(content, date)
|
||||
items.forEach(item => {
|
||||
const prev = programs[programs.length - 1]
|
||||
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(1, 'h')
|
||||
programs.push({
|
||||
title: item.title,
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart(item, date) {
|
||||
const dateString = `${date.format('MM/DD/YYYY')} ${item.time}`
|
||||
|
||||
return dayjs.tz(dateString, 'MM/DD/YYYY HH:mm', 'Europe/Madrid')
|
||||
}
|
||||
|
||||
function parseItems(content, date) {
|
||||
const $ = cheerio.load(content)
|
||||
const dayOfWeek = dayjs(date).locale('ca').format('dddd').toLowerCase()
|
||||
const column = $('.programacio-dia > h3')
|
||||
.filter((i, el) => $(el).text().startsWith(dayOfWeek))
|
||||
.first()
|
||||
.parent()
|
||||
const items = []
|
||||
const titles = column.find(`p`).toArray()
|
||||
column.find(`h4`).each((i, time) => {
|
||||
items.push({
|
||||
time: $(time).text(),
|
||||
title: $(titles[i]).text()
|
||||
})
|
||||
})
|
||||
|
||||
return items
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue