mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Create knr.gl.config.js
This commit is contained in:
parent
78911f437a
commit
488437d4d1
1 changed files with 67 additions and 0 deletions
67
sites/knr.gl/knr.gl.config.js
Normal file
67
sites/knr.gl/knr.gl.config.js
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
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')
|
||||||
|
|
||||||
|
dayjs.extend(utc)
|
||||||
|
dayjs.extend(timezone)
|
||||||
|
dayjs.extend(customParseFormat)
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
site: 'knr.gl',
|
||||||
|
url({ date }) {
|
||||||
|
return `https://knr.gl/admin/knr/TV/program/${date.format('YYYY-MM-DD')}/gl`
|
||||||
|
},
|
||||||
|
logo({ channel }) {
|
||||||
|
return channel.logo
|
||||||
|
},
|
||||||
|
parser({ content, date }) {
|
||||||
|
let programs = []
|
||||||
|
const items = parseItems(content)
|
||||||
|
items.forEach(item => {
|
||||||
|
const prev = programs[programs.length - 1]
|
||||||
|
const start = parseStart(item, date)
|
||||||
|
const stop = start.add(1, 'h')
|
||||||
|
if (prev) prev.stop = start
|
||||||
|
programs.push({
|
||||||
|
title: item.title,
|
||||||
|
description: item.description,
|
||||||
|
start,
|
||||||
|
stop
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return programs
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseStart(item, date) {
|
||||||
|
const time = `${date.format('YYYY-MM-DD')} ${item.time}`
|
||||||
|
|
||||||
|
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'America/Godthab')
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseItems(content, date) {
|
||||||
|
const data = JSON.parse(content)
|
||||||
|
if (!data.program_list) return []
|
||||||
|
const $ = cheerio.load(data.program_list)
|
||||||
|
const items = []
|
||||||
|
$('dt').each(function () {
|
||||||
|
const titleElem = $(this)
|
||||||
|
.contents()
|
||||||
|
.filter(function () {
|
||||||
|
return this.nodeType === 3
|
||||||
|
})[0]
|
||||||
|
items.push({
|
||||||
|
title: titleElem.nodeValue.trim(),
|
||||||
|
description: $(this)
|
||||||
|
.next('dd')
|
||||||
|
.text()
|
||||||
|
.replace(/(\r\n|\n|\r)/gm, ' '),
|
||||||
|
time: $(this, 'strong').text().trim()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return items
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue