mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-11 01:20:08 -04:00
commit
4ac569cfdf
3 changed files with 129 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
|
||||
}
|
56
sites/knr.gl/knr.gl.test.js
Normal file
56
sites/knr.gl/knr.gl.test.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
// npx epg-grabber --config=sites/knr.gl/knr.gl.config.js --channels=sites/knr.gl/knr.gl_gl.channels.xml --output=.gh-pages/guides/gl/knr.gl.epg.xml --days=2
|
||||
|
||||
const { parser, url, logo } = require('./knr.gl.config.js')
|
||||
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('2021-11-22', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '#',
|
||||
xmltv_id: 'KNRTV.gl',
|
||||
logo: 'https://knr.gl/files/knr_logo.jpg'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date })).toBe('https://knr.gl/admin/knr/TV/program/2021-11-22/gl')
|
||||
})
|
||||
|
||||
it('can get valid logo url', () => {
|
||||
expect(logo({ channel })).toBe('https://knr.gl/files/knr_logo.jpg')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `{\"program_list\":\"\\u003Cdt class=\\u0022program\\u0022\\u003E\\u003Cstrong\\u003E08:00\\u003C\\\/strong\\u003E Meeqqanut - Toqqorsivimmiit\\u003C\\\/dt\\u003E\\u003Cdt class=\\u0022knr-program-pointer knr-program-togle-program\\u0022 data-program-id=\\u0022588574\\u0022 data-module-path=\\u0022sites\\\/knr\\\/modules\\\/custom\\\/knr_site\\u0022\\u003E\\u003Cimg height=\\u00229\\u0022 width=\\u00229\\u0022 id=\\u0022icon_588574\\u0022 alt=\\u0022View description\\u0022 src=\\u0022\\\/sites\\\/knr\\\/modules\\\/custom\\\/knr_site\\\/assets\\\/img\\\/plus.gif\\u0022\\u003E\\u003Cstrong\\u003E08:30\\u003C\\\/strong\\u003E ICC 2018 Piorsarsimassutikkut pisut (1:3)\\u003C\\\/dt\\u003E\\u003Cdd id=\\u0022program_588574\\u0022 style=\\u0022display: none;\\u0022\\u003E\\u003Cdiv class=\\u0022box\\u0022\\u003E2018 ICC ataatsimersuareernerata kingorna unnukkut piorsarsimassutsikkut pisut takutinneqarput. Aammalu illoqarfik Utqiagvik ilisaritinneqarluni. Ove Heilmann, Aannguaq Nielsen, Aannguaq Reimer-Johansen\\r\\nKNR 09.12.2018\\u003C\\\/div\\u003E\\u003C\\\/dd\\u003E\"}`
|
||||
const result = parser({ content, date }).map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2021-11-22T11:00:00.000Z',
|
||||
stop: '2021-11-22T11:30:00.000Z',
|
||||
title: `Meeqqanut - Toqqorsivimmiit`
|
||||
},
|
||||
{
|
||||
start: '2021-11-22T11:30:00.000Z',
|
||||
stop: '2021-11-22T12:30:00.000Z',
|
||||
title: `ICC 2018 Piorsarsimassutikkut pisut (1:3)`,
|
||||
description:
|
||||
'2018 ICC ataatsimersuareernerata kingorna unnukkut piorsarsimassutsikkut pisut takutinneqarput. Aammalu illoqarfik Utqiagvik ilisaritinneqarluni. Ove Heilmann, Aannguaq Nielsen, Aannguaq Reimer-Johansen KNR 09.12.2018'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: `{"program_list":""}`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
6
sites/knr.gl/knr.gl_gl.channels.xml
Normal file
6
sites/knr.gl/knr.gl_gl.channels.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="knr.gl">
|
||||
<channels>
|
||||
<channel lang="kl" xmltv_id="KNRTV.gl" site_id="#" logo="https://knr.gl/files/knr_logo.jpg">KNR TV</channel>
|
||||
</channels>
|
||||
</site>
|
Loading…
Add table
Add a link
Reference in a new issue