mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Merge pull request #2081 from iptv-org/fix-andorradifusio.ad
Fix andorradifusio.ad
This commit is contained in:
commit
e1abfe52b1
3 changed files with 4360 additions and 38 deletions
4334
sites/andorradifusio.ad/__data__/content.html
Normal file
4334
sites/andorradifusio.ad/__data__/content.html
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,13 +1,5 @@
|
||||||
const cheerio = require('cheerio')
|
const cheerio = require('cheerio')
|
||||||
const dayjs = require('dayjs')
|
const { DateTime } = require('luxon')
|
||||||
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 = {
|
module.exports = {
|
||||||
site: 'andorradifusio.ad',
|
site: 'andorradifusio.ad',
|
||||||
|
@ -22,13 +14,13 @@ module.exports = {
|
||||||
const prev = programs[programs.length - 1]
|
const prev = programs[programs.length - 1]
|
||||||
let start = parseStart(item, date)
|
let start = parseStart(item, date)
|
||||||
if (prev) {
|
if (prev) {
|
||||||
if (start.isBefore(prev.start)) {
|
if (start < prev.start) {
|
||||||
start = start.add(1, 'd')
|
start = start.plus({ days: 1 })
|
||||||
date = date.add(1, 'd')
|
date = date.add(1, 'd')
|
||||||
}
|
}
|
||||||
prev.stop = start
|
prev.stop = start
|
||||||
}
|
}
|
||||||
const stop = start.add(1, 'h')
|
const stop = start.plus({ hours: 1 })
|
||||||
programs.push({
|
programs.push({
|
||||||
title: item.title,
|
title: item.title,
|
||||||
start,
|
start,
|
||||||
|
@ -43,16 +35,17 @@ module.exports = {
|
||||||
function parseStart(item, date) {
|
function parseStart(item, date) {
|
||||||
const dateString = `${date.format('MM/DD/YYYY')} ${item.time}`
|
const dateString = `${date.format('MM/DD/YYYY')} ${item.time}`
|
||||||
|
|
||||||
return dayjs.tz(dateString, 'MM/DD/YYYY HH:mm', 'Europe/Madrid')
|
return DateTime.fromFormat(dateString, 'MM/dd/yyyy HH:mm', { zone: 'Europe/Madrid' }).toUTC()
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content, date) {
|
function parseItems(content, date) {
|
||||||
const $ = cheerio.load(content)
|
const $ = cheerio.load(content)
|
||||||
const dayOfWeek = dayjs(date).locale('ca').format('dddd').toLowerCase()
|
const day = DateTime.fromMillis(date.valueOf()).setLocale('ca').toFormat('dd LLLL').toLowerCase()
|
||||||
const column = $('.programacio-dia > h3')
|
const column = $('.programacio-dia > h3 > .dia')
|
||||||
.filter((i, el) => $(el).text().startsWith(dayOfWeek))
|
.filter((i, el) => $(el).text() === day.slice(0, 6) + '.')
|
||||||
.first()
|
.first()
|
||||||
.parent()
|
.parent()
|
||||||
|
.parent()
|
||||||
const items = []
|
const items = []
|
||||||
const titles = column.find(`p`).toArray()
|
const titles = column.find(`p`).toArray()
|
||||||
column.find(`h4`).each((i, time) => {
|
column.find(`h4`).each((i, time) => {
|
||||||
|
|
|
@ -1,13 +1,15 @@
|
||||||
// npx epg-grabber --config=sites/andorradifusio.ad/andorradifusio.ad.config.js --channels=sites/andorradifusio.ad/andorradifusio.ad.channels.xml --output=guide.xml --days=2
|
// npx epg-grabber --config=sites/andorradifusio.ad/andorradifusio.ad.config.js --channels=sites/andorradifusio.ad/andorradifusio.ad.channels.xml --output=guide.xml
|
||||||
|
|
||||||
const { parser, url } = require('./andorradifusio.ad.config.js')
|
const { parser, url } = require('./andorradifusio.ad.config.js')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
|
|
||||||
const date = dayjs.utc('2021-11-24', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2023-06-07', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: 'atv',
|
site_id: 'atv',
|
||||||
xmltv_id: 'AndorraTV.ad'
|
xmltv_id: 'AndorraTV.ad'
|
||||||
|
@ -18,36 +20,29 @@ it('can generate valid url', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content = `<!DOCTYPE html><html lang="ca"> <head></head> <body id="rtvabody"> <div class="container"> <div class="row"> <div class="col-sm-12"> <div class="programacio-dia"> <h3>dimecres <span class="dia">24 nov.</span></h3> <h4>07:00</h4> <p>Club Piolet</p><h4>23:30</h4> <p>Informatiu vespre</p><h4>01:00</h4> <p>Àrea Andorra Difusió</p></div><div class="programacio-dia"> <h3>dijous <span class="dia">25 nov.</span></h3> <h4>07:00</h4> <p>Club Piolet</p></div></div></div></div></body></html>`
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||||
const result = parser({ content, date }).map(p => {
|
const results = parser({ content, date }).map(p => {
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toMatchObject([
|
expect(results[0]).toMatchObject({
|
||||||
{
|
start: '2023-06-07T05:00:00.000Z',
|
||||||
start: '2021-11-24T06:00:00.000Z',
|
stop: '2023-06-07T06:00:00.000Z',
|
||||||
stop: '2021-11-24T22:30:00.000Z',
|
|
||||||
title: `Club Piolet`
|
title: `Club Piolet`
|
||||||
},
|
})
|
||||||
{
|
|
||||||
start: '2021-11-24T22:30:00.000Z',
|
expect(results[20]).toMatchObject({
|
||||||
stop: '2021-11-25T00:00:00.000Z',
|
start: '2023-06-07T23:00:00.000Z',
|
||||||
title: `Informatiu vespre`
|
stop: '2023-06-08T00:00:00.000Z',
|
||||||
},
|
|
||||||
{
|
|
||||||
start: '2021-11-25T00:00:00.000Z',
|
|
||||||
stop: '2021-11-25T01:00:00.000Z',
|
|
||||||
title: `Àrea Andorra Difusió`
|
title: `Àrea Andorra Difusió`
|
||||||
}
|
})
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle empty guide', () => {
|
||||||
const result = parser({
|
const result = parser({
|
||||||
date,
|
date,
|
||||||
channel,
|
|
||||||
content: `<!DOCTYPE html><html><head></head><body></body></html>`
|
content: `<!DOCTYPE html><html><head></head><body></body></html>`
|
||||||
})
|
})
|
||||||
expect(result).toMatchObject([])
|
expect(result).toMatchObject([])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue