From 108ca49c29fb8c317e04e595aa347833aaafefcb Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 30 Mar 2022 19:58:30 +0300 Subject: [PATCH] Create startv.com.config.js --- sites/startv.com/startv.com.config.js | 87 +++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 sites/startv.com/startv.com.config.js diff --git a/sites/startv.com/startv.com.config.js b/sites/startv.com/startv.com.config.js new file mode 100644 index 00000000..7369eabd --- /dev/null +++ b/sites/startv.com/startv.com.config.js @@ -0,0 +1,87 @@ +const axios = require('axios') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const timezone = require('dayjs/plugin/timezone') +const customParseFormat = require('dayjs/plugin/customParseFormat') + +dayjs.extend(utc) +dayjs.extend(timezone) +dayjs.extend(customParseFormat) + +const API_ENDPOINT = 'https://www.startv.com/umbraco/api/startvguideproxy' + +module.exports = { + site: 'startv.com', + url: `${API_ENDPOINT}/GetTvGuideSchedule`, + request: { + method: 'POST', + headers: { + 'Content-Type': 'application/json; charset=UTF-8' + }, + data({ channel, date }) { + return { + Channels: channel.site_id, + Start: date.format('YYYYMMDDHHmm'), + Stop: date.add(1, 'd').format('YYYYMMDDHHmm') + } + } + }, + parser: function ({ content, channel }) { + let programs = [] + const items = parseItems(content, channel) + items.forEach(item => { + programs.push({ + title: item.title, + description: item.desc, + icon: item.programmeurl, + category: item.subgenre, + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + }, + async channels() { + const data = await axios + .post( + `${API_ENDPOINT}/GetChannelResult`, + { Genre: 'All Channels' }, + { + headers: { + 'Content-Type': 'application/json; charset=UTF-8' + } + } + ) + .then(r => JSON.parse(r.data)) + .catch(console.log) + + const channels = data.channelsbygenreandlanguage.channellist.channelnames.split(',') + return channels.map(item => { + return { + lang: 'hi', + site_id: item, + name: item + } + }) + } +} + +function parseStart(item) { + return dayjs.tz(item.start, 'YYYYMMDDHHmm', 'Asia/Kolkata') +} + +function parseStop(item) { + return dayjs.tz(item.stop, 'YYYYMMDDHHmm', 'Asia/Kolkata') +} + +function parseItems(content, channel) { + if (!content.length) return [] + const json = JSON.parse(content) + if (!json.length) return [] + const data = JSON.parse(json) + if (!data || !data.ScheduleGrid || !Array.isArray(data.ScheduleGrid.channel)) return [] + const channelData = data.ScheduleGrid.channel.find(c => c.channeldisplayname === channel.site_id) + + return channelData && Array.isArray(channelData.programme) ? channelData.programme : [] +}