From e3916528bc1849a3c04f70d49fa5c7d90fdbc281 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 29 May 2021 15:11:29 +0300 Subject: [PATCH] Create tv.lv.config.js --- sites/tv.lv.config.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 sites/tv.lv.config.js diff --git a/sites/tv.lv.config.js b/sites/tv.lv.config.js new file mode 100644 index 00000000..0faf560d --- /dev/null +++ b/sites/tv.lv.config.js @@ -0,0 +1,42 @@ +const dayjs = require('dayjs') + +module.exports = { + lang: 'lv', + site: 'tv.lv', + channels: 'tv.lv.channels.xml', + output: '.gh-pages/guides/tv.lv.guide.xml', + url: function ({ date, channel }) { + return `https://www.tv.lv/programme/listing/none/${date.format( + 'DD-MM-YYYY' + )}?filter=channel&subslug=${channel.site_id}` + }, + logo: function ({ content }) { + const data = JSON.parse(content) + const logo = data.schedule.programme.length ? data.schedule.programme[0].channel.logo_64 : null + + return logo ? `https://cdn.tvstart.com/img/channel/${logo}` : null + }, + parser: function ({ content }) { + const programs = [] + const data = JSON.parse(content) + const items = data.schedule.programme + if (!items.length) return programs + + items.forEach(item => { + if (item.title && item.start_unix && item.stop_unix) { + const start = dayjs.unix(item.start_unix) + const stop = dayjs.unix(item.stop_unix) + programs.push({ + title: item.title, + description: item.description_long, + category: item.categorystring, + icon: item.image, + start: start.toString(), + stop: stop.toString() + }) + } + }) + + return programs + } +}