From 9830ed79a812c0ddb77d6cd2171172cccbdfb702 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 3 Oct 2022 19:19:01 +0300 Subject: [PATCH] Create watchyour.tv.config.js --- sites/watchyour.tv/watchyour.tv.config.js | 54 +++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 sites/watchyour.tv/watchyour.tv.config.js diff --git a/sites/watchyour.tv/watchyour.tv.config.js b/sites/watchyour.tv/watchyour.tv.config.js new file mode 100644 index 00000000..6a0afc29 --- /dev/null +++ b/sites/watchyour.tv/watchyour.tv.config.js @@ -0,0 +1,54 @@ +const dayjs = require('dayjs') +const axios = require('axios') + +module.exports = { + site: 'watchyour.tv', + url: `https://www.watchyour.tv/guide.json`, + request: { + cache: { + ttl: 60 * 60 * 1000 // 1 hour + } + }, + parser: function ({ content, date, channel }) { + let programs = [] + const items = parseItems(content, date, channel) + items.forEach(item => { + const start = parseStart(item) + const stop = start.add(parseInt(item.duration), 'm') + programs.push({ + title: item.name, + icon: item.icon, + category: item.category, + start, + stop + }) + }) + + return programs + }, + async channels() { + const data = await axios + .get(`https://www.watchyour.tv/guide.json`) + .then(r => r.data) + .catch(console.log) + + return data.map(item => ({ + site_id: item.id, + name: item.name + })) + } +} + +function parseStart(item) { + return dayjs.unix(parseInt(item.tms)) +} + +function parseItems(content, date, channel) { + if (!content) return [] + const data = JSON.parse(content) + if (!Array.isArray(data)) return [] + const channelData = data.find(i => i.id == channel.site_id) + if (!channelData || !Array.isArray(channelData.shows)) return [] + + return channelData.shows.filter(i => i.start_day === date.format('YYYY-MM-DD')) +}