wip
This commit is contained in:
71
sites/programme-tv.net.config.js
Normal file
71
sites/programme-tv.net.config.js
Normal file
@@ -0,0 +1,71 @@
|
||||
const jsdom = require('jsdom')
|
||||
const { JSDOM } = jsdom
|
||||
const dayjs = require('dayjs')
|
||||
var customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
var duration = require('dayjs/plugin/duration')
|
||||
dayjs.extend(duration)
|
||||
dayjs.extend(customParseFormat)
|
||||
const { htmlToText } = require('html-to-text')
|
||||
var parse = require('parse-duration')
|
||||
|
||||
module.exports = {
|
||||
lang: 'fr',
|
||||
output: '../../.gh-pages/guides/programme-tv.net.xml',
|
||||
channels: '../../sites/programme-tv.net.channels.xml',
|
||||
url: function ({ date, channel }) {
|
||||
return `https://www.programme-tv.net/programme/chaine/${date.format('YYYY-MM-DD')}/programme-${
|
||||
channel.site_id
|
||||
}.html`
|
||||
},
|
||||
parser: function ({ channel, content, date, lang }) {
|
||||
const programs = []
|
||||
const dom = new JSDOM(content)
|
||||
const broadcastCards = dom.window.document.querySelectorAll('.singleBroadcastCard')
|
||||
broadcastCards.forEach(card => {
|
||||
const hour = (
|
||||
card.getElementsByClassName('singleBroadcastCard-hour')[0] || { textContent: '' }
|
||||
).textContent
|
||||
.toString()
|
||||
.trim()
|
||||
const durationContent = (
|
||||
card.getElementsByClassName('singleBroadcastCard-durationContent')[0] || { textContent: '' }
|
||||
).textContent
|
||||
.toString()
|
||||
.trim()
|
||||
const title = (
|
||||
card.getElementsByClassName('singleBroadcastCard-title')[0] || { textContent: '' }
|
||||
).textContent
|
||||
.toString()
|
||||
.trim()
|
||||
const category = (
|
||||
card.getElementsByClassName('singleBroadcastCard-genre')[0] || { textContent: '' }
|
||||
).textContent
|
||||
.toString()
|
||||
.trim()
|
||||
|
||||
if (hour && title) {
|
||||
const start = dayjs
|
||||
.utc(hour.replace('h', '-'), 'HH-mm')
|
||||
.set('D', date.get('D'))
|
||||
.set('M', date.get('M'))
|
||||
.set('y', date.get('y'))
|
||||
|
||||
const durationInMilliseconds = parse(durationContent)
|
||||
const stop = start.add(dayjs.duration(durationInMilliseconds))
|
||||
|
||||
programs.push({
|
||||
title,
|
||||
lang,
|
||||
category,
|
||||
start: start.toString(),
|
||||
stop: stop.toString(),
|
||||
channel: channel['xmltv_id']
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
// console.log(programs)
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user