From 561f905eb4d391b227645a654c7d2f99aac5124d Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 7 Nov 2021 18:52:56 +0300 Subject: [PATCH] Create mts.rs.config.js --- sites/mts.rs/mts.rs.config.js | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 sites/mts.rs/mts.rs.config.js diff --git a/sites/mts.rs/mts.rs.config.js b/sites/mts.rs/mts.rs.config.js new file mode 100644 index 00000000..a4eb30e8 --- /dev/null +++ b/sites/mts.rs/mts.rs.config.js @@ -0,0 +1,65 @@ +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const timezone = require('dayjs/plugin/timezone') + +dayjs.extend(utc) +dayjs.extend(timezone) + +module.exports = { + site: 'mts.rs', + url({ date, channel }) { + const [position] = channel.site_id.split('#') + + return `https://mts.rs/oec/epg/program?date=${date.format('YYYY-MM-DD')}&position=${position}` + }, + request: { + timeout: 10000, + headers: { + 'X-Requested-With': 'XMLHttpRequest' + } + }, + logo({ content, channel }) { + const data = parseContent(content, channel) + + return data ? data.image : null + }, + parser: function ({ content, channel, date }) { + let programs = [] + const data = parseContent(content, channel) + const items = parseItems(data) + items.forEach(item => { + const start = parseStart(item) + const stop = parseStop(item) + programs.push({ + title: item.title, + category: item.category, + description: item.description, + icon: item.image, + start: start.toJSON(), + stop: stop.toJSON() + }) + }) + + return programs + } +} + +function parseContent(content, channel) { + const [_, site_id] = channel.site_id.split('#') + const data = JSON.parse(content) + if (!data || !data.channels || !data.channels.length) return null + + return data.channels.find(c => c.id === site_id) || null +} + +function parseStart(item, date) { + return dayjs.tz(item.full_start, 'Europe/Belgrade') +} + +function parseStop(item, date) { + return dayjs.tz(item.full_end, 'Europe/Belgrade') +} + +function parseItems(data) { + return data && Array.isArray(data.items) ? data.items : [] +}