mirror of
https://github.com/iptv-org/epg
synced 2026-04-29 14:06:59 -04:00
Fixes linter errors
This commit is contained in:
@@ -1,100 +1,100 @@
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
module.exports = {
|
||||
site: 'mon-programme-tv.be',
|
||||
days: 2,
|
||||
url({ date, channel }) {
|
||||
return `https://www.mon-programme-tv.be/chaine/${date.format('DDMMYYYY')}/${
|
||||
channel.site_id
|
||||
}.html`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(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(30, 'm')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
category: parseCategory($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://www.mon-programme-tv.be/chaine/toutes-les-chaines-television.html')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(data)
|
||||
|
||||
const channels = []
|
||||
$('.list-chaines > ul > li').each((i, el) => {
|
||||
const [, site_id] = $(el)
|
||||
.find('a')
|
||||
.attr('href')
|
||||
.match(/\/chaine\/(.*).html/) || [null, null]
|
||||
const [, name] = $(el)
|
||||
.find('a')
|
||||
.attr('title')
|
||||
.match(/Programme TV ce soir (.*)/) || [null, null]
|
||||
|
||||
channels.push({
|
||||
site_id,
|
||||
name,
|
||||
lang: 'fr'
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.title').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.episode').text().trim()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('.type').text().trim()
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item('.image img').data('src')
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('.hour').text().trim()
|
||||
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Europe/Brussels')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.box').toArray()
|
||||
}
|
||||
const cheerio = require('cheerio')
|
||||
const axios = require('axios')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
|
||||
module.exports = {
|
||||
site: 'mon-programme-tv.be',
|
||||
days: 2,
|
||||
url({ date, channel }) {
|
||||
return `https://www.mon-programme-tv.be/chaine/${date.format('DDMMYYYY')}/${
|
||||
channel.site_id
|
||||
}.html`
|
||||
},
|
||||
parser: function ({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(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(30, 'm')
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
description: parseDescription($item),
|
||||
category: parseCategory($item),
|
||||
icon: parseIcon($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
},
|
||||
async channels() {
|
||||
const data = await axios
|
||||
.get('https://www.mon-programme-tv.be/chaine/toutes-les-chaines-television.html')
|
||||
.then(r => r.data)
|
||||
.catch(console.log)
|
||||
const $ = cheerio.load(data)
|
||||
|
||||
const channels = []
|
||||
$('.list-chaines > ul > li').each((i, el) => {
|
||||
const [, site_id] = $(el)
|
||||
.find('a')
|
||||
.attr('href')
|
||||
.match(/\/chaine\/(.*).html/) || [null, null]
|
||||
const [, name] = $(el)
|
||||
.find('a')
|
||||
.attr('title')
|
||||
.match(/Programme TV ce soir (.*)/) || [null, null]
|
||||
|
||||
channels.push({
|
||||
site_id,
|
||||
name,
|
||||
lang: 'fr'
|
||||
})
|
||||
})
|
||||
|
||||
return channels
|
||||
}
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.title').text().trim()
|
||||
}
|
||||
|
||||
function parseDescription($item) {
|
||||
return $item('.episode').text().trim()
|
||||
}
|
||||
|
||||
function parseCategory($item) {
|
||||
return $item('.type').text().trim()
|
||||
}
|
||||
|
||||
function parseIcon($item) {
|
||||
return $item('.image img').data('src')
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const time = $item('.hour').text().trim()
|
||||
|
||||
return dayjs.tz(`${date.format('YYYY-MM-DD')} ${time}`, 'YYYY-MM-DD HH:mm', 'Europe/Brussels')
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $('.box').toArray()
|
||||
}
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
// npm run channels:parse -- --config=./sites/mon-programme-tv.be/mon-programme-tv.be.config.js --output=./sites/mon-programme-tv.be/mon-programme-tv.be.channels.xml
|
||||
// npm run grab -- --site=mon-programme-tv.be
|
||||
|
||||
const { parser, url } = require('./mon-programme-tv.be.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2023-01-19', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1873/programme-television-ln24',
|
||||
xmltv_id: 'LN24.be'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://www.mon-programme-tv.be/chaine/19012023/1873/programme-television-ln24.html'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-01-19T05:30:00.000Z',
|
||||
stop: '2023-01-19T05:55:00.000Z',
|
||||
title: 'LN Matin',
|
||||
category: 'Magazine Actualité',
|
||||
icon: 'https://dnsmptv-img.pragma-consult.be/imgs/picto/132/Reportage_1.jpg'
|
||||
})
|
||||
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2023-01-19T05:55:00.000Z',
|
||||
stop: '2023-01-19T06:00:00.000Z',
|
||||
title: 'Météo',
|
||||
category: 'Météo',
|
||||
icon: 'https://dnsmptv-img.pragma-consult.be/imgs/picto/132/Meteo.jpg'
|
||||
})
|
||||
|
||||
expect(results[8]).toMatchObject({
|
||||
start: '2023-01-19T08:00:00.000Z',
|
||||
stop: '2023-01-19T08:05:00.000Z',
|
||||
title: 'Le journal',
|
||||
description: "L'information de la mi-journée avec des JT...",
|
||||
category: 'Journal',
|
||||
icon: 'https://dnsmptv-img.pragma-consult.be/imgs/picto/132/journal.jpg'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html')),
|
||||
date
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
// npm run channels:parse -- --config=./sites/mon-programme-tv.be/mon-programme-tv.be.config.js --output=./sites/mon-programme-tv.be/mon-programme-tv.be.channels.xml
|
||||
// npm run grab -- --site=mon-programme-tv.be
|
||||
|
||||
const { parser, url } = require('./mon-programme-tv.be.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
dayjs.extend(customParseFormat)
|
||||
dayjs.extend(utc)
|
||||
|
||||
const date = dayjs.utc('2023-01-19', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '1873/programme-television-ln24',
|
||||
xmltv_id: 'LN24.be'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date, channel })).toBe(
|
||||
'https://www.mon-programme-tv.be/chaine/19012023/1873/programme-television-ln24.html'
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
|
||||
const results = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2023-01-19T05:30:00.000Z',
|
||||
stop: '2023-01-19T05:55:00.000Z',
|
||||
title: 'LN Matin',
|
||||
category: 'Magazine Actualité',
|
||||
icon: 'https://dnsmptv-img.pragma-consult.be/imgs/picto/132/Reportage_1.jpg'
|
||||
})
|
||||
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2023-01-19T05:55:00.000Z',
|
||||
stop: '2023-01-19T06:00:00.000Z',
|
||||
title: 'Météo',
|
||||
category: 'Météo',
|
||||
icon: 'https://dnsmptv-img.pragma-consult.be/imgs/picto/132/Meteo.jpg'
|
||||
})
|
||||
|
||||
expect(results[8]).toMatchObject({
|
||||
start: '2023-01-19T08:00:00.000Z',
|
||||
stop: '2023-01-19T08:05:00.000Z',
|
||||
title: 'Le journal',
|
||||
description: "L'information de la mi-journée avec des JT...",
|
||||
category: 'Journal',
|
||||
icon: 'https://dnsmptv-img.pragma-consult.be/imgs/picto/132/journal.jpg'
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const results = parser({
|
||||
content: fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html')),
|
||||
date
|
||||
})
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user