From 1f2000689f110846a601bcd878d76e99bacbe64d Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 26 Nov 2021 01:23:43 +0300 Subject: [PATCH] Create tva.tv.config.js --- sites/tva.tv/tva.tv.config.js | 67 +++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 sites/tva.tv/tva.tv.config.js diff --git a/sites/tva.tv/tva.tv.config.js b/sites/tva.tv/tva.tv.config.js new file mode 100644 index 00000000..c86292a4 --- /dev/null +++ b/sites/tva.tv/tva.tv.config.js @@ -0,0 +1,67 @@ +const axios = require('axios') +const dayjs = require('dayjs') + +module.exports = { + site: 'tva.tv', + url: function ({ date, channel }) { + return `https://api.ott.tva.tv/v2/epg/program_events.json?channel_id=${ + channel.site_id + }&pivot_date=${date.format('YYYY-MM-DD')}` + }, + logo: function ({ channel }) { + return channel.logo + }, + parser: function ({ content, date, channel }) { + const programs = [] + const items = parseItems(content) + items.forEach(item => { + programs.push({ + title: item.name, + description: item.description, + start: dayjs(item.start_at), + stop: dayjs(item.end_at) + }) + }) + + return programs + }, + async channels({ country, lang }) { + const data = await axios + .get( + `https://api.ott.tva.tv/v1/channels?client_id=66797942-ff54-46cb-a109-3bae7c855370&client_version=0.0.1&expand%5Bchannel%5D=images&locale=en-GB&page%5Blimit%5D=100&page%5Boffset%5D=0&timezone=10800`, + { + headers: { + Origin: 'https://tva.tv' + } + } + ) + .then(r => r.data) + .catch(console.log) + + const channels = [] + for (let item of data.data) { + const logo = item.images + ? item.images[0].url_template + .replace('{width}', '512') + .replace('{height}', '512') + .replace('{crop}', 'c') + : null + channels.push({ + lang: 'fa', + site_id: item.id, + name: item.name, + xmltv_id: item.slug, + logo + }) + } + + return channels + } +} + +function parseItems(content) { + const data = JSON.parse(content) + if (!data || !Array.isArray(data.data)) return [] + + return data.data +}