From 6dc7f35aaa71cf5dd62d0a83a0c0c9ef90346f28 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 29 Oct 2021 10:46:17 +0300 Subject: [PATCH 1/3] Create tv.trueid.net.test.js --- sites/tv.trueid.net/tv.trueid.net.test.js | 45 +++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sites/tv.trueid.net/tv.trueid.net.test.js diff --git a/sites/tv.trueid.net/tv.trueid.net.test.js b/sites/tv.trueid.net/tv.trueid.net.test.js new file mode 100644 index 00000000..b99a270f --- /dev/null +++ b/sites/tv.trueid.net/tv.trueid.net.test.js @@ -0,0 +1,45 @@ +// npx epg-grabber --config=sites/tv.trueid.net/tv.trueid.net.config.js --channels=sites/tv.trueid.net/tv.trueid.net_th.channels.xml --days=1 --output=guide.xml + +const { parser, url, logo } = require('./tv.trueid.net.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-10-28', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'tv-nfl-nba', + xmltv_id: 'NFLNBATV.us', + name: 'NFL & NBA TV' +} +const content = `` + +it('can generate valid url', () => { + const result = url({ channel, date }) + expect(result).toBe('https://tv.trueid.net/tvguide/all/tv-nfl-nba/2021-10-28') +}) + +it('can get logo url', () => { + const result = logo({ content, channel }) + expect(result).toBe( + 'https://cms.dmpcdn.com/livetv/2021/09/28/2c9c41c0-203b-11ec-9346-6f50de6452df_webp_original.png' + ) +}) + +it('can parse response', () => { + const result = parser({ date, channel, content }) + expect(result).toMatchObject([ + { + start: dayjs.utc('Thu, 28 Oct 2021 19:00:00 GMT'), + stop: dayjs.utc('Thu, 28 Oct 2021 21:00:00 GMT'), + title: 'NBA 2021/22', + icon: 'https://epgthumb.dmpcdn.com/thumbnail_large/t513/20211029/20211029_020000.jpg' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ date, channel, content: `{}` }) + expect(result).toMatchObject([]) +}) From 7ba78abe1abd60c2a93201091b911d105c39a42e Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 29 Oct 2021 10:47:12 +0300 Subject: [PATCH 2/3] Create tv.trueid.net.config.js --- sites/tv.trueid.net/tv.trueid.net.config.js | 70 +++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 sites/tv.trueid.net/tv.trueid.net.config.js diff --git a/sites/tv.trueid.net/tv.trueid.net.config.js b/sites/tv.trueid.net/tv.trueid.net.config.js new file mode 100644 index 00000000..d98137e5 --- /dev/null +++ b/sites/tv.trueid.net/tv.trueid.net.config.js @@ -0,0 +1,70 @@ +const jsdom = require('jsdom') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') + +dayjs.extend(utc) + +module.exports = { + request: { + timeout: 90000, + jar: null + }, + site: 'tv.trueid.net', + channels: 'tv.trueid.net.channels.xml', + url: function ({ channel, date }) { + return `https://tv.trueid.net/tvguide/all/${channel.site_id}/${date.format('YYYY-MM-DD')}` + }, + logo: function ({ content, channel }) { + const data = parseContent(content, channel) + + return data ? data.logo : null + }, + parser: function ({ content, channel }) { + 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, + icon: parseIcon(item), + start, + stop + }) + }) + + return programs + } +} + +function parseIcon(item) { + return item.detail ? item.detail.thumb : null +} + +function parseStart(item) { + return item.detail ? dayjs.utc(item.detail.start_date) : null +} + +function parseStop(item) { + return item.detail ? dayjs.utc(item.detail.end_date) : null +} + +function parseContent(content, channel) { + const virtualConsole = new jsdom.VirtualConsole() + virtualConsole.sendTo(console, { omitJSDOMErrors: true }) + const dom = new jsdom.JSDOM(content, { virtualConsole }) + const elem = dom.window.document.getElementById('__NEXT_DATA__') || { textContent: '' } + if (!elem.textContent) return null + const data = JSON.parse(elem.textContent) + const channels = data.props?.pageProps?.listEPG?.data || [] + + return channels.find(ch => ch.slug === channel.site_id) +} + +function parseItems(data) { + if (!data) return [] + + return data.programList || [] +} From f8a95c8324adbe6448ffa31369f1c2bf90ab3bbc Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 29 Oct 2021 10:47:17 +0300 Subject: [PATCH 3/3] Create tv.trueid.net_th.channels.xml --- .../tv.trueid.net_th.channels.xml | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 sites/tv.trueid.net/tv.trueid.net_th.channels.xml diff --git a/sites/tv.trueid.net/tv.trueid.net_th.channels.xml b/sites/tv.trueid.net/tv.trueid.net_th.channels.xml new file mode 100644 index 00000000..fba55089 --- /dev/null +++ b/sites/tv.trueid.net/tv.trueid.net_th.channels.xml @@ -0,0 +1,88 @@ + + + + Amarin 34 HD + Animal Planet Southeast Asia + Asian Food Network + AXN East Asia + BBC Earth Asia + BBC Lifestyle Asia + BBC World News Asia Pacific + BBTV Channel 7 + BeIn Sports 1 Thailand + BeIn Sports 2 Thailand + Cartoon Network Asia + CCTV 4 Asia + Channel 3 + CNBC Asia-Pacific + CNN International Asia Pacific + Discovery Asia + Discovery Channel Southeast Asia + DreamWorks TV Asia + FashionTV Asia + Food Network Asia + Gem + GMM 25 + History 2 Asia + History Asia + JKN 18 + KBS World + KMTV Asia + Lifetime Asia + Love Nature + MCOT HD + Mono 29 + Motorvision TV + Nation TV + NBA TV + NBT 2 + NFL Network + NHK World Premium + Nickelodeon South East Asia + Nick Jr Asia + One 31 + Outdoor Channel International + Paramount Network Asia + Phoenix InfoNews Channel + PPTV HD 36 + Rama Channel + Rock Entertainment + Rock Extreme + SpoTV 2 + Thai Channel 8 + Thai PBS 3 + Thairath TV 32 + Thai TV 5 HD1 + TLC Southeast Asia + TNN 2 + TNN 16 + True 4U + True Explore Life + True Explore Sci + True Explore Wild + True Film HD + True Film HD 2 + True Inside + True Movie Hits + True Plookpanya + True Select + True Series + True Shopping + True Spark Jump + True Spark Play + TrueSport 5 + TrueSport 7 + TrueSport HD + TrueSport HD 2 + TrueSport HD 3 + TrueSport HD 4 + True Tennis + True Thai Film + True X-Zyte + TV5Monde Asie + TVB Xing He + TVN Asia + Warner TV Southeast Asia + Workpoint 23 + + \ No newline at end of file