From df7e6b7b875ecb586054b1db862a49c741529c6b Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 4 Oct 2022 20:03:34 +0300 Subject: [PATCH] Create tapdmv.com.config.js --- sites/tapdmv.com/tapdmv.com.config.js | 60 +++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 sites/tapdmv.com/tapdmv.com.config.js diff --git a/sites/tapdmv.com/tapdmv.com.config.js b/sites/tapdmv.com/tapdmv.com.config.js new file mode 100644 index 00000000..9d1c3c1f --- /dev/null +++ b/sites/tapdmv.com/tapdmv.com.config.js @@ -0,0 +1,60 @@ +const axios = require('axios') +const dayjs = require('dayjs') + +module.exports = { + site: 'tapdmv.com', + url({ channel, date }) { + return `https://epg.tapdmv.com/calendar/${ + channel.site_id + }?%24limit=10000&%24sort%5BcreatedAt%5D=-1&start=${date.toJSON()}&end=${date + .add(1, 'd') + .toJSON()}` + }, + parser: function ({ content, date }) { + let programs = [] + const items = parseItems(content, date) + items.forEach(item => { + programs.push({ + title: item.program.trim(), + description: item.description, + category: item.genre, + icon: item.thumbnailImage, + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + }, + async channels() { + const items = await axios + .get(`https://epg.tapdmv.com/calendar?$limit=10000&$sort[createdAt]=-1`) + .then(r => r.data.data) + .catch(console.log) + + return items.map(item => { + const [_, name] = item.name.match(/epg-tapgo-([^\.]+).json/) + return { + site_id: item.id, + name + } + }) + } +} + +function parseStart(item) { + return dayjs(item.startTime) +} + +function parseStop(item) { + return dayjs(item.endTime) +} + +function parseItems(content, date) { + if (!content) return [] + const data = JSON.parse(content) + if (!Array.isArray(data)) return [] + const d = date.format('YYYY-MM-DD') + + return data.filter(i => i.startTime.includes(d)) +}