mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-12 01:50:07 -04:00
Update programme-tv.net.config.js
This commit is contained in:
parent
a62afcb855
commit
79940e2845
1 changed files with 56 additions and 53 deletions
|
@ -1,17 +1,18 @@
|
||||||
const jsdom = require('jsdom')
|
const durationParser = require('parse-duration')
|
||||||
const { JSDOM } = jsdom
|
const cheerio = require('cheerio')
|
||||||
const parseDuration = require('parse-duration')
|
const srcset = require('srcset')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const duration = require('dayjs/plugin/duration')
|
const timezone = require('dayjs/plugin/timezone')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
|
||||||
dayjs.extend(utc)
|
dayjs.extend(utc)
|
||||||
dayjs.extend(duration)
|
dayjs.extend(timezone)
|
||||||
dayjs.extend(customParseFormat)
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
lang: 'fr',
|
lang: 'fr',
|
||||||
|
days: 3,
|
||||||
site: 'programme-tv.net',
|
site: 'programme-tv.net',
|
||||||
channels: 'programme-tv.net.channels.xml',
|
channels: 'programme-tv.net.channels.xml',
|
||||||
output: '.gh-pages/guides/programme-tv.net.guide.xml',
|
output: '.gh-pages/guides/programme-tv.net.guide.xml',
|
||||||
|
@ -21,61 +22,63 @@ module.exports = {
|
||||||
}.html`
|
}.html`
|
||||||
},
|
},
|
||||||
logo: function ({ content }) {
|
logo: function ({ content }) {
|
||||||
const dom = new JSDOM(content)
|
const $ = cheerio.load(content)
|
||||||
const img = dom.window.document.querySelector(
|
const img = $('.gridChannel-logo').first().find('img')
|
||||||
'#corps > div > div.page.channel > div.gridChannel > div.gridChannel-leftColumn > div.gridChannel-epgGrid > div.gridChannel-header > div > div > div > img'
|
const value = img.attr('srcset') || img.data('srcset')
|
||||||
)
|
const obj = value ? srcset.parse(value).find(i => i.width === 80) : {}
|
||||||
|
|
||||||
return img ? img.dataset.src : null
|
return obj.url
|
||||||
},
|
},
|
||||||
parser: function ({ content, date }) {
|
parser: function ({ content, date }) {
|
||||||
const programs = []
|
const programs = []
|
||||||
const dom = new JSDOM(content)
|
const items = parseItems(content)
|
||||||
const broadcastCards = dom.window.document.querySelectorAll('.mainBroadcastCard')
|
items.forEach(item => {
|
||||||
broadcastCards.forEach(card => {
|
const $item = cheerio.load(item)
|
||||||
const hour = (
|
const title = parseTitle($item)
|
||||||
card.getElementsByClassName('mainBroadcastCard-startingHour')[0] || { textContent: '' }
|
const icon = parseIcon($item)
|
||||||
).textContent
|
const category = parseCategory($item)
|
||||||
.toString()
|
const start = parseStart($item, date)
|
||||||
.trim()
|
const duration = parseDuration($item)
|
||||||
const durationContent = (
|
const stop = start.add(duration, 'ms')
|
||||||
card.getElementsByClassName('mainBroadcastCard-durationContent')[0] || { textContent: '' }
|
|
||||||
).textContent
|
|
||||||
.toString()
|
|
||||||
.trim()
|
|
||||||
const title = (
|
|
||||||
card.getElementsByClassName('mainBroadcastCard-title')[0] || { textContent: '' }
|
|
||||||
).textContent
|
|
||||||
.toString()
|
|
||||||
.trim()
|
|
||||||
const category = (
|
|
||||||
card.getElementsByClassName('mainBroadcastCard-genre')[0] || { textContent: '' }
|
|
||||||
).textContent
|
|
||||||
.toString()
|
|
||||||
.trim()
|
|
||||||
|
|
||||||
if (hour && title) {
|
programs.push({ title, icon, category, start, stop })
|
||||||
const start = dayjs
|
|
||||||
.utc(hour.replace('h', '-'), 'HH-mm')
|
|
||||||
.set('D', date.get('D'))
|
|
||||||
.set('M', date.get('M'))
|
|
||||||
.set('y', date.get('y'))
|
|
||||||
|
|
||||||
let stop = null
|
|
||||||
if (durationContent) {
|
|
||||||
const durationInMilliseconds = parseDuration(durationContent)
|
|
||||||
stop = start.add(dayjs.duration(durationInMilliseconds)).toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
programs.push({
|
|
||||||
title,
|
|
||||||
category,
|
|
||||||
start: start.toString(),
|
|
||||||
stop
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return programs
|
return programs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseStart($item, date) {
|
||||||
|
let time = $item('.mainBroadcastCard-startingHour').first().text().trim()
|
||||||
|
time = `${date.format('MM/DD/YYYY')} ${time.replace('h', ':')}`
|
||||||
|
|
||||||
|
return dayjs.tz(time, 'MM/DD/YYYY HH:mm', 'Europe/Paris')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseDuration($item) {
|
||||||
|
const duration = $item('.mainBroadcastCard-durationContent').first().text().trim()
|
||||||
|
|
||||||
|
return durationParser(duration)
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseIcon($item) {
|
||||||
|
const img = $item('.mainBroadcastCard-imageContent').first().find('img')
|
||||||
|
const value = img.attr('srcset') || img.data('srcset')
|
||||||
|
const obj = value ? srcset.parse(value).find(i => i.width === 128) : {}
|
||||||
|
|
||||||
|
return obj.url
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseCategory($item) {
|
||||||
|
return $item('.mainBroadcastCard-genre').first().text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseTitle($item) {
|
||||||
|
return $item('.mainBroadcastCard-title').first().text().trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content) {
|
||||||
|
const $ = cheerio.load(content)
|
||||||
|
|
||||||
|
return $('.mainBroadcastCard').toArray()
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue