From 38df7a8fa1cedddb299bf3ca408a35efef5295ae Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 20 Jan 2022 19:24:18 +0300 Subject: [PATCH] Update directv.com.config.js --- sites/directv.com/directv.com.config.js | 28 +++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/sites/directv.com/directv.com.config.js b/sites/directv.com/directv.com.config.js index 4b1e9e95..f5858e5e 100644 --- a/sites/directv.com/directv.com.config.js +++ b/sites/directv.com/directv.com.config.js @@ -1,3 +1,5 @@ +const { padStart } = require('lodash') +const cheerio = require('cheerio') const axios = require('axios') const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') @@ -34,6 +36,32 @@ module.exports = { } return programs + }, + async channels({ country }) { + const html = await axios + .get(`https://www.directv.com/guide`) + .then(r => r.data) + .catch(console.log) + + const $ = cheerio.load(html) + const script = $('#dtvClientData').html() + const [_, json] = script.match(/var dtvClientData = (.*);/) || [null, null] + const data = JSON.parse(json) + + let items = data.guideData.channels + + return items.map(item => { + return { + lang: 'en', + site_id: item.chNum, + name: item.chName, + logo: `https://www.directv.com/images/logos/channels/dark/large/${padStart( + item.chLogoId, + 3, + '0' + )}.png` + } + }) } }