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 +} diff --git a/sites/tva.tv/tva.tv.test.js b/sites/tva.tv/tva.tv.test.js new file mode 100644 index 00000000..afb648cd --- /dev/null +++ b/sites/tva.tv/tva.tv.test.js @@ -0,0 +1,55 @@ +// node ./scripts/channels.js --config=./sites/tva.tv/tva.tv.config.js --output=./sites/tva.tv/tva.tv_ir.channels.xml +// npx epg-grabber --config=sites/tva.tv/tva.tv.config.js --channels=sites/tva.tv/tva.tv_ir.channels.xml --output=.gh-pages/guides/ir/tva.tv.epg.xml --timeout=30000 --days=2 + +const { parser, url, logo } = require('./tva.tv.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +const customParseFormat = require('dayjs/plugin/customParseFormat') +dayjs.extend(customParseFormat) +dayjs.extend(utc) + +const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '6fcc0a2e-1135-482c-b054-08a96e68b758', + xmltv_id: 'IRIB2.ir', + logo: 'https://s3.ott.tva.tv/rosing-tva-production/bec73f72f63958fc6998_512x512c.png' +} +const content = `{"data":[{"id":"c0667229-eaf8-472f-8ba7-ad4417348baf","start_at":"2021-11-24T00:20:39.000Z","end_at":"2021-11-24T00:32:11.000Z","description":"تلفن های شبکه 5 سیما: تلفن: 23511000 -تلفن گویا:2786500 نمابر:23511289","name":"میان برنامه","subtitle":"","season_number":null,"episode_number":null,"channel_id":"6fcc0a2e-1135-482c-b054-08a96e68b758","program_id":"e495c06e-80de-46ee-9120-619631f554d9","competition_id":null,"object":"program_event","cast_members":[],"genres":[],"images":[],"program_type":null,"certification_ratings":[]}]}` + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://api.ott.tva.tv/v2/epg/program_events.json?channel_id=6fcc0a2e-1135-482c-b054-08a96e68b758&pivot_date=2021-11-25' + ) +}) + +it('can generate valid logo url', () => { + expect(logo({ channel })).toBe( + 'https://s3.ott.tva.tv/rosing-tva-production/bec73f72f63958fc6998_512x512c.png' + ) +}) + +it('can parse response', () => { + const result = parser({ content, channel, date }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2021-11-24T00:20:39.000Z', + stop: '2021-11-24T00:32:11.000Z', + title: `میان برنامه`, + description: 'تلفن های شبکه 5 سیما: تلفن: 23511000 -تلفن گویا:2786500 نمابر:23511289' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `{"errors":[{"id":"ebbebfb7-ffb0-4e0b-bcfb-1d9cd3e6c03c","code":"not_found","links":{"about":{"href":"https://app.bugsnag.com/jeytv/API/errors?filters[event.since][]=30d&filters[user.name][]=ebbebfb7-ffb0-4e0b-bcfb-1d9cd3e6c03c"}},"title":"Requested resource was not found","fallback_message":null,"object":"error"}],"meta":{"status":404}}` + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/tva.tv/tva.tv_ir.channels.xml b/sites/tva.tv/tva.tv_ir.channels.xml new file mode 100644 index 00000000..62c5108d --- /dev/null +++ b/sites/tva.tv/tva.tv_ir.channels.xml @@ -0,0 +1,34 @@ + + + + Azarbayjan-e Gharbi TV + Doc TV + Hamedan TV + IRIB 1 + IRIB 2 + IRIB 3 + IRIB 4 + IRIB 5 + IRINN + Irkala TV + Jame-Jam TV Network 1 + Khorasan Razavi TV + Namayesh TV + Nasim + Omid TV + Salaam TV + Sepehr + Taban TV + TVA 1 + TVA 2 + TVA Avand + TVA Bourse + TVA Film + TVA Kids + TVA Mahfel + TVA Nava + TVA Sport + TVA Sport 2 + Velayat TV Network + + \ No newline at end of file