mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update knr.gl
This commit is contained in:
parent
e4fad111e6
commit
785099e918
5 changed files with 87 additions and 39 deletions
1
sites/knr.gl/__data__/content.json
Normal file
1
sites/knr.gl/__data__/content.json
Normal file
File diff suppressed because one or more lines are too long
16
sites/knr.gl/__data__/no_content.json
Normal file
16
sites/knr.gl/__data__/no_content.json
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,4 +1,4 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<channels>
|
<channels>
|
||||||
<channel site="knr.gl" lang="kl" xmltv_id="KNR1.gl" site_id="#">KNR TV</channel>
|
<channel site="knr.gl" lang="kl" xmltv_id="KNR1.gl" site_id="#">KNR</channel>
|
||||||
</channels>
|
</channels>
|
|
@ -11,8 +11,20 @@ dayjs.extend(customParseFormat)
|
||||||
module.exports = {
|
module.exports = {
|
||||||
site: 'knr.gl',
|
site: 'knr.gl',
|
||||||
days: 2,
|
days: 2,
|
||||||
url({ date }) {
|
url: 'https://knr.gl/kl/tv/aallakaatitassat?ajax_form=1',
|
||||||
return `https://knr.gl/admin/knr/TV/program/${date.format('YYYY-MM-DD')}/gl`
|
request: {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'
|
||||||
|
},
|
||||||
|
data({ date }) {
|
||||||
|
const params = new URLSearchParams()
|
||||||
|
params.append('list_date', date.format('YYYY-MM-DD'))
|
||||||
|
params.append('form_id', 'knr_radio_tv_program_overview_form')
|
||||||
|
params.append('_triggering_element_name', 'list_date')
|
||||||
|
|
||||||
|
return params
|
||||||
|
}
|
||||||
},
|
},
|
||||||
parser({ content, date }) {
|
parser({ content, date }) {
|
||||||
let programs = []
|
let programs = []
|
||||||
|
@ -37,27 +49,29 @@ module.exports = {
|
||||||
function parseStart(item, date) {
|
function parseStart(item, date) {
|
||||||
const time = `${date.format('YYYY-MM-DD')} ${item.time}`
|
const time = `${date.format('YYYY-MM-DD')} ${item.time}`
|
||||||
|
|
||||||
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'America/Godthab')
|
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'America/Nuuk')
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseItems(content) {
|
function parseItems(content) {
|
||||||
const data = JSON.parse(content)
|
const data = JSON.parse(content)
|
||||||
if (!data.program_list) return []
|
if (data.length !== 1 || !data[0].data) return []
|
||||||
const $ = cheerio.load(data.program_list)
|
const $ = cheerio.load(data[0].data)
|
||||||
|
|
||||||
const items = []
|
const items = []
|
||||||
$('dt').each(function () {
|
$('.overview-program__list__item').each((i, el) => {
|
||||||
const titleElem = $(this)
|
const title = $(el).find('.overview-program__text').text().trim()
|
||||||
.contents()
|
const description = $(el)
|
||||||
.filter(function () {
|
.find('.overview-program__sublist__item')
|
||||||
return this.nodeType === 3
|
.first()
|
||||||
})[0]
|
|
||||||
items.push({
|
|
||||||
title: titleElem.nodeValue.trim(),
|
|
||||||
description: $(this)
|
|
||||||
.next('dd')
|
|
||||||
.text()
|
.text()
|
||||||
.replace(/(\r\n|\n|\r)/gm, ' '),
|
.trim()
|
||||||
time: $(this, 'strong').text().trim()
|
.replace(/(\r\n|\n|\r)/gm, ' ')
|
||||||
|
const time = $(el).find('.overview-program__time').text().trim()
|
||||||
|
|
||||||
|
items.push({
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
time
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// npm run grab -- --site=knr.gl
|
// npm run grab -- --site=knr.gl
|
||||||
|
|
||||||
const { parser, url } = require('./knr.gl.config.js')
|
const { parser, url, request } = require('./knr.gl.config.js')
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
const dayjs = require('dayjs')
|
const dayjs = require('dayjs')
|
||||||
const utc = require('dayjs/plugin/utc')
|
const utc = require('dayjs/plugin/utc')
|
||||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||||
|
@ -10,43 +12,58 @@ dayjs.extend(utc)
|
||||||
const date = dayjs.utc('2021-11-22', 'YYYY-MM-DD').startOf('d')
|
const date = dayjs.utc('2021-11-22', 'YYYY-MM-DD').startOf('d')
|
||||||
const channel = {
|
const channel = {
|
||||||
site_id: '#',
|
site_id: '#',
|
||||||
xmltv_id: 'KNRTV.gl'
|
xmltv_id: 'KNR.gl'
|
||||||
}
|
}
|
||||||
|
|
||||||
it('can generate valid url', () => {
|
it('can generate valid url', () => {
|
||||||
expect(url({ date })).toBe('https://knr.gl/admin/knr/TV/program/2021-11-22/gl')
|
expect(url).toBe('https://knr.gl/kl/tv/aallakaatitassat?ajax_form=1')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can generate valid request method', () => {
|
||||||
|
expect(request.method).toBe('POST')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can generate valid request headers', () => {
|
||||||
|
expect(request.headers).toMatchObject({})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('can generate valid request data', () => {
|
||||||
|
const params = request.data({ date })
|
||||||
|
|
||||||
|
expect(params.get('list_date')).toBe('2021-11-22')
|
||||||
|
expect(params.get('form_id')).toBe('knr_radio_tv_program_overview_form')
|
||||||
|
expect(params.get('_triggering_element_name')).toBe('list_date')
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can parse response', () => {
|
it('can parse response', () => {
|
||||||
const content =
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||||
'{"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 results = parser({ content, date }).map(p => {
|
||||||
const result = parser({ content, date }).map(p => {
|
|
||||||
p.start = p.start.toJSON()
|
p.start = p.start.toJSON()
|
||||||
p.stop = p.stop.toJSON()
|
p.stop = p.stop.toJSON()
|
||||||
return p
|
return p
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(result).toMatchObject([
|
expect(results[0]).toMatchObject({
|
||||||
{
|
|
||||||
start: '2021-11-22T11:00:00.000Z',
|
start: '2021-11-22T11:00:00.000Z',
|
||||||
stop: '2021-11-22T11:30:00.000Z',
|
stop: '2021-11-22T11:30:00.000Z',
|
||||||
title: 'Meeqqanut - Toqqorsivimmiit'
|
title: 'Issittormiuaqqat'
|
||||||
},
|
})
|
||||||
{
|
|
||||||
start: '2021-11-22T11:30:00.000Z',
|
expect(results[4]).toMatchObject({
|
||||||
stop: '2021-11-22T12:30:00.000Z',
|
start: '2021-11-22T13:00:00.000Z',
|
||||||
title: 'ICC 2018 Piorsarsimassutikkut pisut (1:3)',
|
stop: '2021-11-22T13:30:00.000Z',
|
||||||
|
title: 'KNR2: Tusagassiortunik katersortitsineq - Erik Jensen',
|
||||||
description:
|
description:
|
||||||
'2018 ICC ataatsimersuareernerata kingorna unnukkut piorsarsimassutsikkut pisut takutinneqarput. Aammalu illoqarfik Utqiagvik ilisaritinneqarluni. Ove Heilmann, Aannguaq Nielsen, Aannguaq Reimer-Johansen KNR 09.12.2018'
|
'Naalakkersuisoq Erik Jensen tusagassiortunut 21.november nal. 10.00-11.00 katersortitsissaaq attassisinnaanermut siuariartornermullu pilersaarut pillugu (holdbarheds- og vækstplan).'
|
||||||
}
|
})
|
||||||
])
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it('can handle empty guide', () => {
|
it('can handle empty guide', () => {
|
||||||
|
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
|
||||||
const result = parser({
|
const result = parser({
|
||||||
date,
|
date,
|
||||||
channel,
|
channel,
|
||||||
content: '{"program_list":""}'
|
content
|
||||||
})
|
})
|
||||||
expect(result).toMatchObject([])
|
expect(result).toMatchObject([])
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue