From a1c170072e9dec235dd23995c75f079573ccbfad Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 5 Mar 2022 19:45:20 +0300 Subject: [PATCH] Create tv.nu.config.js --- sites/tv.nu/tv.nu.config.js | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sites/tv.nu/tv.nu.config.js diff --git a/sites/tv.nu/tv.nu.config.js b/sites/tv.nu/tv.nu.config.js new file mode 100644 index 00000000..098d6c59 --- /dev/null +++ b/sites/tv.nu/tv.nu.config.js @@ -0,0 +1,45 @@ +const dayjs = require('dayjs') + +module.exports = { + site: 'tv.nu', + url: function ({ channel, date }) { + return `https://web-api.tv.nu/channels/${channel.site_id}/schedule?date=${date.format( + 'YYYY-MM-DD' + )}&fullDay=true` + }, + parser: function ({ content }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + programs.push({ + title: item.title, + description: item.description, + icon: item.imageLandscape, + category: item.genres, + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + } +} + +function parseStart(item) { + if (!item.broadcast || !item.broadcast.startTime) return null + + return dayjs(item.broadcast.startTime) +} + +function parseStop(item) { + if (!item.broadcast || !item.broadcast.endTime) return null + + return dayjs(item.broadcast.endTime) +} + +function parseItems(content) { + const data = JSON.parse(content) + if (!data || !data.data || !Array.isArray(data.data.broadcasts)) return [] + + return data.data.broadcasts +}