From e8b135f71d71ccd7c325ce13ddf3b2640d6ae6a4 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 13 Nov 2021 11:40:27 +0300 Subject: [PATCH] Create delta.nl.config.js --- sites/delta.nl/delta.nl.config.js | 60 +++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 sites/delta.nl/delta.nl.config.js diff --git a/sites/delta.nl/delta.nl.config.js b/sites/delta.nl/delta.nl.config.js new file mode 100644 index 00000000..b08ac61a --- /dev/null +++ b/sites/delta.nl/delta.nl.config.js @@ -0,0 +1,60 @@ +const axios = require('axios') +const dayjs = require('dayjs') + +module.exports = { + site: 'delta.nl', + url: function ({ channel, date }) { + return `https://clientapi.tv.delta.nl/guide/channels/list?start=${date.unix()}&end=${date + .add(1, 'd') + .unix()}&includeDetails=true&channels=${channel.site_id}` + }, + logo({ channel }) { + return channel.logo + }, + parser: function ({ content, channel }) { + let programs = [] + const items = parseItems(content, channel) + items.forEach(item => { + programs.push({ + title: item.title, + icon: item.images.thumbnail.url, + start: parseStart(item).toJSON(), + stop: parseStop(item).toJSON() + }) + }) + + return programs + }, + async channels() { + const items = await axios + .get('https://clientapi.tv.delta.nl/channels/list') + .then(r => r.data) + .catch(console.log) + + return items + .filter(i => i.type === 'TV') + .map(item => { + return { + lang: 'nl', + site_id: item['ID'], + name: item.name, + logo: item.images.logo + } + }) + } +} + +function parseStart(item) { + return dayjs.unix(item.start) +} + +function parseStop(item) { + return dayjs.unix(item.end) +} + +function parseItems(content, channel) { + const data = JSON.parse(content) + if (!data) return [] + + return data[channel.site_id] || [] +}