skylink.au
Updated config and tests
This commit is contained in:
@@ -2,11 +2,11 @@ const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const timezone = require('dayjs/plugin/timezone')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
var convert = require('xml-js');
|
||||
|
||||
dayjs.extend(utc)
|
||||
dayjs.extend(timezone)
|
||||
dayjs.extend(customParseFormat)
|
||||
const tz = 'Europe/Prague'
|
||||
|
||||
module.exports = {
|
||||
site: 'skylink.cz',
|
||||
@@ -19,12 +19,12 @@ module.exports = {
|
||||
const items = parseItems(content)
|
||||
items.forEach(item => {
|
||||
programs.push({
|
||||
title: item.name,
|
||||
start: parseTime(item.startDate),
|
||||
stop: parseTime(item.endDate),
|
||||
description: item.longDescription || item.shortDescription,
|
||||
title: item.name._text,
|
||||
start: parseTime(item.startDate._text),
|
||||
stop: parseTime(item.endDate._text),
|
||||
description: parseDescription(item),
|
||||
category: parseCategory(item),
|
||||
date: item.year || null,
|
||||
date: item.year._text || null,
|
||||
director: parseList(item.directors),
|
||||
actor: parseList(item.actors)
|
||||
})
|
||||
@@ -35,23 +35,31 @@ module.exports = {
|
||||
|
||||
function parseItems(content) {
|
||||
try {
|
||||
const data = JSON.parse(content)
|
||||
const data = convert.xml2js(content, {compact: true, ignoreDeclaration: true, ignoreAttributes:true})
|
||||
if (!data) return []
|
||||
const programmes = data['tv-program-programmes']
|
||||
const programmes = data['tv-program-programmes'].programme
|
||||
return programmes && Array.isArray(programmes) ? programmes : []
|
||||
} catch (err) {
|
||||
return []
|
||||
}
|
||||
}
|
||||
function parseDescription(item) {
|
||||
if (item.longDescription) return item.longDescription._text
|
||||
if (item.shortDescription) return item.shortDescription._text
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
function parseList(list) {
|
||||
return typeof list === 'string' ? list.split(',') : []
|
||||
if (!list) return []
|
||||
if (!list._text) return []
|
||||
return typeof list._text === 'string' ? list._text.split(', ') : []
|
||||
}
|
||||
function parseTime(time) {
|
||||
return dayjs(time, 'DD.MM.YYYY HH.mm').tz(tz)
|
||||
return dayjs.tz(time, 'DD.MM.YYYY HH.mm', 'Europe/Prague')
|
||||
}
|
||||
|
||||
function parseCategory(item) {
|
||||
if (!item['programme-type']) return null
|
||||
return item['programme-type'].name
|
||||
return item['programme-type'].name._text
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user