mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
commit
116338cb08
3 changed files with 134 additions and 0 deletions
69
sites/kvf.fo/kvf.fo.config.js
Normal file
69
sites/kvf.fo/kvf.fo.config.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
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: 'kvf.fo',
|
||||
url({ date }) {
|
||||
return `https://kvf.fo/nskra/uv?date=${date.format('YYYY-MM-DD')}`
|
||||
},
|
||||
logo({ channel }) {
|
||||
return channel.logo
|
||||
},
|
||||
parser({ content, date }) {
|
||||
let programs = []
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
const $item = cheerio.load(item)
|
||||
let start = parseStart($item, date)
|
||||
let stop = parseStop($item, date)
|
||||
if (start.isAfter(stop)) {
|
||||
stop = stop.add(1, 'd')
|
||||
date = date.add(1, 'd')
|
||||
}
|
||||
programs.push({
|
||||
title: parseTitle($item),
|
||||
start,
|
||||
stop
|
||||
})
|
||||
})
|
||||
|
||||
return programs
|
||||
}
|
||||
}
|
||||
|
||||
function parseStart($item, date) {
|
||||
const string = $item('.s-normal > .s-time1').text().trim()
|
||||
let [time] = string.match(/^(\d{2}:\d{2})/g) || [null]
|
||||
if (!time) return null
|
||||
time = `${date.format('YYYY-MM-DD')} ${time}`
|
||||
|
||||
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Atlantic/Faroe')
|
||||
}
|
||||
|
||||
function parseStop($item, date) {
|
||||
const string = $item('.s-normal > .s-time1').text().trim()
|
||||
let [time] = string.match(/(\d{2}:\d{2})$/g) || [null]
|
||||
if (!time) return null
|
||||
time = `${date.format('YYYY-MM-DD')} ${time}`
|
||||
|
||||
return dayjs.tz(time, 'YYYY-MM-DD HH:mm', 'Atlantic/Faroe')
|
||||
}
|
||||
|
||||
function parseTitle($item) {
|
||||
return $item('.s-normal > .s-heiti').text()
|
||||
}
|
||||
|
||||
function parseItems(content) {
|
||||
const $ = cheerio.load(content)
|
||||
|
||||
return $(
|
||||
'#block-system-main > div > div > div.panels-flexible-row.panels-flexible-row-339-main-row.panels-flexible-row-last.clearfix > div > div.panels-flexible-region.panels-flexible-region-339-center.panels-flexible-region-first > div > div > div > div > div.view-content > div.views-row'
|
||||
).toArray()
|
||||
}
|
59
sites/kvf.fo/kvf.fo.test.js
Normal file
59
sites/kvf.fo/kvf.fo.test.js
Normal file
|
@ -0,0 +1,59 @@
|
|||
// npx epg-grabber --config=sites/kvf.fo/kvf.fo.config.js --channels=sites/kvf.fo/kvf.fo_fo.channels.xml --output=.gh-pages/guides/fo/kvf.fo.epg.xml --days=2
|
||||
|
||||
const { parser, url, logo } = require('./kvf.fo.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-21', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '#',
|
||||
xmltv_id: 'KVFSjonvarp.fo',
|
||||
logo: 'https://kvf.fo/sites/all/themes/bootstrap_subtheme/logo.png'
|
||||
}
|
||||
|
||||
it('can generate valid url', () => {
|
||||
expect(url({ date })).toBe('https://kvf.fo/nskra/uv?date=2021-11-21')
|
||||
})
|
||||
|
||||
it('can get logo url', () => {
|
||||
expect(logo({ channel })).toBe('https://kvf.fo/sites/all/themes/bootstrap_subtheme/logo.png')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
const content = `<!DOCTYPE html><html> <head></head> <body class="html not-front not-logged-in no-sidebars page-nskra page-nskra-uv"> <body> <div class="main-container container"> <div class="row"> <section class="col-sm-12"> <a id="main-content"></a> <div class="region region-content"> <section id="block-system-main" class="block block-system clearfix"> <div class="panel-flexible panels-flexible-339 clearfix"> <div class="panel-flexible-inside panels-flexible-339-inside"> <div class=" panels-flexible-row panels-flexible-row-339-main-row panels-flexible-row-last clearfix " > <div class=" inside panels-flexible-row-inside panels-flexible-row-339-main-row-inside panels-flexible-row-inside-last clearfix " > <div class=" panels-flexible-region panels-flexible-region-339-center panels-flexible-region-first " > <div class=" inside panels-flexible-region-inside panels-flexible-region-339-center-inside panels-flexible-region-inside-first " > <div class="panel-pane pane-views pane-ws-skr-ir"> <div class="pane-content"> <div class=" view view-ws-skr-ir view-id-ws_skr_ir view-display-id-page_uv s-pane view-dom-id-3dc4c119f4c633d65e7ed8b3c167d7a2 " > <div class="view-content"> <div class="views-row views-row-1"> <div class="s-normal"> <div class="s-time1"> <div class="s-time">00:00 - 02:00</div></div><div class="s-player"></div><div class="s-heiti">Plátubarrin</div><div class="s-option"> <div class="s-expand"> <img src="/sites/all/themes/bootstrap_subtheme/images/skra/plus.png"/> </div></div><div class="s-timer-notimer"></div></div><div class="s-sub" style="display: none"> <table class="s-insider"> <tr> <td class="c1"> <div class="s-imgsending"> <img typeof="foaf:Image" class="img-responsive" src="https://kvf.fo/sites/default/files/styles/nvf-very-small/public/platubarrin_1.jpg?itok=5kwClG66" width="116" height="65" alt=""/> </div></td><td class="c2"> <div class="s-subtitle"> Beinleiðis leygarkvøldssending við temaplátu og lurtaraynskjum. </div><div class="s-text"></div><div class="s-producer"> Jákup Magnussen er vertur. </div><div> <div class="s-sending"> <a href="/node/18941">Far til sendingasíðu</a> </div></div></td></tr></table> </div></div><div class="views-row views-row-26"> <div class="s-normal"> <div class="s-time1"> <div class="s-time">23:00 - 00:00</div></div><div class="s-player"></div><div class="s-heiti">Tónleikur</div><div class="s-option"> <div class="s-expand"> <img src="/sites/all/themes/bootstrap_subtheme/images/skra/plus.png"/> </div></div><div class="s-timer-notimer"></div></div><div class="s-sub" style="display: none"> <table class="s-insider"> <tbody> <tr> <td class="c1"></td><td class="c2"> <div class="s-subtitle"></div><div class="s-text"></div><div class="s-producer"></div><div></div></td></tr></tbody> </table> </div></div><div class="views-row views-row-26"> <div class="s-normal"> <div class="s-time1"> <div class="s-time">00:00 - 01:00</div></div><div class="s-player"></div><div class="s-heiti">Náttarrásin</div><div class="s-option"> <div class="s-expand"> <img src="/sites/all/themes/bootstrap_subtheme/images/skra/plus.png"/> </div></div><div class="s-timer-notimer"></div></div><div class="s-sub" style="display: none"> <table class="s-insider"> <tbody> <tr> <td class="c1"></td><td class="c2"> <div class="s-subtitle"></div><div class="s-text"></div><div class="s-producer"></div><div></div></td></tr></tbody> </table> </div></div></div></div></div></div></div></div></div></div></div></div></section> </div></section> </div></div></body> </body></html>`
|
||||
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-21T00:00:00.000Z',
|
||||
stop: '2021-11-21T02:00:00.000Z',
|
||||
title: `Plátubarrin`
|
||||
},
|
||||
{
|
||||
start: '2021-11-21T23:00:00.000Z',
|
||||
stop: '2021-11-22T00:00:00.000Z',
|
||||
title: `Tónleikur`
|
||||
},
|
||||
{
|
||||
start: '2021-11-22T00:00:00.000Z',
|
||||
stop: '2021-11-22T01:00:00.000Z',
|
||||
title: `Náttarrásin`
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
const result = parser({
|
||||
date,
|
||||
channel,
|
||||
content: `<!DOCTYPE html><html> <head></head> <body></body></html>`
|
||||
})
|
||||
expect(result).toMatchObject([])
|
||||
})
|
6
sites/kvf.fo/kvf.fo_fo.channels.xml
Normal file
6
sites/kvf.fo/kvf.fo_fo.channels.xml
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="kvf.fo">
|
||||
<channels>
|
||||
<channel lang="fo" xmltv_id="KVFSjonvarp.fo" site_id="#" logo="https://kvf.fo/sites/all/themes/bootstrap_subtheme/logo.png">KVF Sjónvarp</channel>
|
||||
</channels>
|
||||
</site>
|
Loading…
Add table
Add a link
Reference in a new issue