From d60483e85883088a0de021e8632b877fcba00e47 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 24 Nov 2021 00:52:10 +0300 Subject: [PATCH 1/4] Create nowplayer.now.com.test.js --- .../nowplayer.now.com.test.js | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 sites/nowplayer.now.com/nowplayer.now.com.test.js diff --git a/sites/nowplayer.now.com/nowplayer.now.com.test.js b/sites/nowplayer.now.com/nowplayer.now.com.test.js new file mode 100644 index 00000000..c5c557bb --- /dev/null +++ b/sites/nowplayer.now.com/nowplayer.now.com.test.js @@ -0,0 +1,67 @@ +// node ./scripts/channels.js --config=./sites/nowplayer.now.com/nowplayer.now.com.config.js --output=./sites/nowplayer.now.com/nowplayer.now.com_hk-zh.channels.xml --set=lang:zh +// node ./scripts/channels.js --config=./sites/nowplayer.now.com/nowplayer.now.com.config.js --output=./sites/nowplayer.now.com/nowplayer.now.com_hk-en.channels.xml --set=lang:en +// npx epg-grabber --config=sites/nowplayer.now.com/nowplayer.now.com.config.js --channels=sites/nowplayer.now.com/nowplayer.now.com_hk-zh.channels.xml --output=.gh-pages/guides/hk-zh/nowplayer.now.com.epg.xml --days=2 +// npx epg-grabber --config=sites/nowplayer.now.com/nowplayer.now.com.config.js --channels=sites/nowplayer.now.com/nowplayer.now.com_hk-en.channels.xml --output=.gh-pages/guides/hk-en/nowplayer.now.com.epg.xml --days=2 + +const { parser, url, request, logo } = require('./nowplayer.now.com.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 channel = { + lang: 'zh', + site_id: '096', + xmltv_id: 'ViuTVsix.hk' +} + +it('can generate valid url for today', () => { + const date = dayjs.utc().startOf('d') + expect(url({ channel, date })).toBe( + 'https://nowplayer.now.com/tvguide/epglist?channelIdList[]=096&day=1' + ) +}) + +it('can generate valid url for tomorrow', () => { + const date = dayjs.utc().startOf('d').add(1, 'd') + expect(url({ channel, date })).toBe( + 'https://nowplayer.now.com/tvguide/epglist?channelIdList[]=096&day=2' + ) +}) + +it('can generate valid request headers', () => { + expect(request.headers({ channel })).toMatchObject({ + Cookie: `LANG=zh; Expires=null; Path=/; Domain=nowplayer.now.com` + }) +}) + +fit('can get logo url', () => { + expect(logo({ channel })).toBe( + 'https://images.now-tv.com/shares/channelPreview/img/en_hk/color/ch96_160_115' + ) +}) + +it('can parse response', () => { + const content = `[[{"key":"key_202111174524739","vimProgramId":"202111174524739","name":"ViuTVsix Station Closing","start":1637690400000,"end":1637715600000,"date":"20211124","startTime":"02:00AM","endTime":"09:00AM","duration":420,"recordable":false,"restartTv":false,"npvrProg":false,"npvrStartTime":0,"npvrEndTime":0,"cid":"viutvsix station closing","cc":"","isInWatchlist":false}]]` + const result = parser({ content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2021-11-23T18:00:00.000Z', + stop: '2021-11-24T01:00:00.000Z', + title: 'ViuTVsix Station Closing' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: `[[]]` + }) + expect(result).toMatchObject([]) +}) From b41f9993671516377d9db9f1f02f44275b81d8ba Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 24 Nov 2021 00:52:18 +0300 Subject: [PATCH 2/4] Create nowplayer.now.com.config.js --- .../nowplayer.now.com.config.js | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 sites/nowplayer.now.com/nowplayer.now.com.config.js diff --git a/sites/nowplayer.now.com/nowplayer.now.com.config.js b/sites/nowplayer.now.com/nowplayer.now.com.config.js new file mode 100644 index 00000000..b99ab680 --- /dev/null +++ b/sites/nowplayer.now.com/nowplayer.now.com.config.js @@ -0,0 +1,70 @@ +const axios = require('axios') +const cheerio = require('cheerio') +const dayjs = require('dayjs') + +module.exports = { + site: 'nowplayer.now.com', + url: function ({ channel, date }) { + const diff = date.diff(dayjs.utc().startOf('d'), 'd') + 1 + + return `https://nowplayer.now.com/tvguide/epglist?channelIdList[]=${channel.site_id}&day=${diff}` + }, + request: { + headers({ channel }) { + return { + Cookie: `LANG=${channel.lang}; Expires=null; Path=/; Domain=nowplayer.now.com` + } + } + }, + logo({ channel }) { + const channelId = channel.site_id.replace(/^0/, '') + + return `https://images.now-tv.com/shares/channelPreview/img/en_hk/color/ch${channelId}_160_115` + }, + parser: function ({ content }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + programs.push({ + title: item.name, + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + }, + async channels({ lang }) { + const html = await axios + .get(`https://nowplayer.now.com/channels`, { headers: { Accept: 'text/html' } }) + .then(r => r.data) + .catch(console.log) + + const $ = cheerio.load(html) + const channels = $('body > div.container > .tv-guide-s-g > div > div').toArray() + + return channels.map(item => { + const $item = cheerio.load(item) + return { + lang, + site_id: $item('.guide-g-play > p.channel').text().replace('CH', ''), + name: $item('.thumbnail > a > span.image > p').text() + } + }) + } +} + +function parseStart(item) { + return dayjs(item.start) +} + +function parseStop(item) { + return dayjs(item.end) +} + +function parseItems(content) { + const data = JSON.parse(content) + if (!data || !Array.isArray(data)) return [] + + return Array.isArray(data[0]) ? data[0] : [] +} From c34770f78964dcc0a642ee3d41cbb334863c314b Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 24 Nov 2021 00:52:21 +0300 Subject: [PATCH 3/4] Create nowplayer.now.com_hk-en.channels.xml --- .../nowplayer.now.com_hk-en.channels.xml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 sites/nowplayer.now.com/nowplayer.now.com_hk-en.channels.xml diff --git a/sites/nowplayer.now.com/nowplayer.now.com_hk-en.channels.xml b/sites/nowplayer.now.com/nowplayer.now.com_hk-en.channels.xml new file mode 100644 index 00000000..30745f88 --- /dev/null +++ b/sites/nowplayer.now.com/nowplayer.now.com_hk-en.channels.xml @@ -0,0 +1,137 @@ + + + + ABC Australia Asia + Aljazeera English + Animal Planet Southeast Asia + Animax Asia + Asian Food Network + Astro Cricket + AXN East Asia + BBC Earth Asia + BBC Lifestyle Asia + BBC World News Asia Pacific + BeIn Sports 1 Hong Kong + BeIn Sports 2 Hong Kong + BeIn Sports Max 1 + BeIn Sports Max 2 + BeIn Sports Max 3 + Bloomberg TV Asia + Boomerang South East Asia + Cartoon Network Asia + CBeebies Asia + CCTV 1 + CCTV 4 Asia + Channel Adult + Cinemax Asia + CNA + CNBC Asia-Pacific + CNN International Asia Pacific + Colors Asia Pacific + CTI TV Asia + Da Vinci Asia + Discovery Asia + Discovery Channel Southeast Asia + Discovery Science Southeast Asia + DMAX Southeast Asia + DreamWorks TV Asia + DW Deutsch + DW English + EBC News Asia + ETTV Asia News + EuroNews English + Fight Sports + Food Network Asia + France 24 English + France 24 Français + GMA Life TV + GMA News TV International + GMA Pinoy TV Asia-Pacific + HBO Asia + HBO Family Asia + HBO Hits + HBO Signature Asia + HGTV Asia + History Asia + HKS TV + Ice Fire + KBS World + Lifetime Asia + Macau Asia Satellite TV + MOOV Concert/MV + Movie Movie + MTV India + MUTV + National Geographic Asia + National Geographic Wild Asia + NHK World Japan + NHK World Premium + Nickelodeon South East Asia + Nick Jr Asia + Now 668 + Now Baogu Movies + Now Baogu Superstars + Now Business News Channel + Now Chinese Drama Channel + Now Data Channel + Now Direct + Now Drama Channel + Now Golf 2 + Now Golf 3 + Now Jelli + Now News + Now News Channel + Now Sports 1 + Now Sports 2 + Now Sports 3 + Now Sports 4 + Now Sports 4K + Now Sports 5 + Now Sports 6 + Now Sports 7 + Now Sports Plus + Now Sports Premier League 1 + Now Sports Premier League 2 + Now Sports Premier League 3 + Now Sports Premier League 4 + Now Sports Premier League 5 + Now Sports Premier League 6 + Now Sports Premier League TV + Now Sports Prime + Now Video Express + Outdoor Channel International + Phoenix Chinese Channel + Phoenix Hong Kong + Phoenix InfoNews Channel + Rock Entertainment + RT News + RugbyPass TV + Sansha TV + SET India + Shenzhen Satellite TV + Sky News UK + Sony Max Asia + Sony SAB TV Asia + Star Bharat India + Star Chinese Movies South East Asia + Star Gold + Star Plus Southeast Asia + TFC Asia-Pacific + Thrill + TLC Southeast Asia + Travel Channel Asia + TV5Monde Asie + TV5Monde Style HD + TVBS Asia + TVN Asia + TVS 2 Southern TV + ViuTV + ViuTVsix + Warner TV Southeast Asia + Yicai TV + Zee Cinema Asia + Zee News + Zee TV Asia Pacific + Zhejiang Satellite TV + + \ No newline at end of file From d5872d018f4fa8e57b59018e48dea9dbdbe9115a Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Wed, 24 Nov 2021 00:52:24 +0300 Subject: [PATCH 4/4] Create nowplayer.now.com_hk-zh.channels.xml --- .../nowplayer.now.com_hk-zh.channels.xml | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) create mode 100644 sites/nowplayer.now.com/nowplayer.now.com_hk-zh.channels.xml diff --git a/sites/nowplayer.now.com/nowplayer.now.com_hk-zh.channels.xml b/sites/nowplayer.now.com/nowplayer.now.com_hk-zh.channels.xml new file mode 100644 index 00000000..e462b02a --- /dev/null +++ b/sites/nowplayer.now.com/nowplayer.now.com_hk-zh.channels.xml @@ -0,0 +1,137 @@ + + + + ABC Australia Asia + Aljazeera English + Animal Planet Southeast Asia + Animax Asia + Asian Food Network + Astro Cricket + AXN East Asia + BBC Earth Asia + BBC Lifestyle Asia + BBC World News Asia Pacific + BeIn Sports 1 Hong Kong + BeIn Sports 2 Hong Kong + BeIn Sports Max 1 + BeIn Sports Max 2 + BeIn Sports Max 3 + Bloomberg TV Asia + Boomerang South East Asia + Cartoon Network Asia + CBeebies Asia + CCTV 1 + CCTV 4 Asia + Channel Adult + Cinemax Asia + CNA + CNBC Asia-Pacific + CNN International Asia Pacific + Colors Asia Pacific + CTI TV Asia + Da Vinci Asia + Discovery Asia + Discovery Channel Southeast Asia + Discovery Science Southeast Asia + DMAX Southeast Asia + DreamWorks TV Asia + DW Deutsch + DW English + EBC News Asia + ETTV Asia News + EuroNews English + Fight Sports + Food Network Asia + France 24 English + France 24 Français + GMA Life TV + GMA News TV International + GMA Pinoy TV Asia-Pacific + HBO Asia + HBO Family Asia + HBO Hits + HBO Signature Asia + HGTV Asia + History Asia + HKS TV + Ice Fire + KBS World + Lifetime Asia + Macau Asia Satellite TV + MOOV Concert/MV + Movie Movie + MTV India + MUTV + National Geographic Asia + National Geographic Wild Asia + NHK World Japan + NHK World Premium + Nickelodeon South East Asia + Nick Jr Asia + Now 668 + Now Baogu Movies + Now Baogu Superstars + Now Business News Channel + Now Chinese Drama Channel + Now Data Channel + Now Direct + Now Drama Channel + Now Golf 2 + Now Golf 3 + Now Jelli + Now News + Now News Channel + Now Sports 1 + Now Sports 2 + Now Sports 3 + Now Sports 4 + Now Sports 4K + Now Sports 5 + Now Sports 6 + Now Sports 7 + Now Sports Plus + Now Sports Premier League 1 + Now Sports Premier League 2 + Now Sports Premier League 3 + Now Sports Premier League 4 + Now Sports Premier League 5 + Now Sports Premier League 6 + Now Sports Premier League TV + Now Sports Prime + Now Video Express + Outdoor Channel International + Phoenix Chinese Channel + Phoenix Hong Kong + Phoenix InfoNews Channel + Rock Entertainment + RT News + RugbyPass TV + Sansha TV + SET India + Shenzhen Satellite TV + Sky News UK + Sony Max Asia + Sony SAB TV Asia + Star Bharat India + Star Chinese Movies South East Asia + Star Gold + Star Plus Southeast Asia + TFC Asia-Pacific + Thrill + TLC Southeast Asia + Travel Channel Asia + TV5Monde Asie + TV5Monde Style HD + TVBS Asia + TVN Asia + TVS 2 Southern TV + ViuTV + ViuTVsix + Warner TV Southeast Asia + Yicai TV + Zee Cinema Asia + Zee News + Zee TV Asia Pacific + Zhejiang Satellite TV + + \ No newline at end of file