From 72f0ab12e6fdc3f7fe8669bdeb781e519262ed70 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 20 Nov 2022 17:36:55 +0300 Subject: [PATCH 1/4] Update i.mjh.nz.test.js --- sites/i.mjh.nz/i.mjh.nz.test.js | 1 + 1 file changed, 1 insertion(+) diff --git a/sites/i.mjh.nz/i.mjh.nz.test.js b/sites/i.mjh.nz/i.mjh.nz.test.js index dafb5b1c..7938511f 100644 --- a/sites/i.mjh.nz/i.mjh.nz.test.js +++ b/sites/i.mjh.nz/i.mjh.nz.test.js @@ -1,6 +1,7 @@ // npm run channels:parse -- --config=./sites/i.mjh.nz/i.mjh.nz.config.js --output=./sites/i.mjh.nz/i.mjh.nz_us-pluto.channels.xml --set=path:PlutoTV/us // npx epg-grabber --config=sites/i.mjh.nz/i.mjh.nz.config.js --channels=sites/i.mjh.nz/i.mjh.nz_us-pluto.channels.xml --output=guide.xml --days=2 // npx epg-grabber --config=sites/i.mjh.nz/i.mjh.nz.config.js --channels=sites/i.mjh.nz/i.mjh.nz_us-stirr.channels.xml --output=guide.xml --days=2 +// npx epg-grabber --config=sites/i.mjh.nz/i.mjh.nz.config.js --channels=sites/i.mjh.nz/i.mjh.nz_us-skygo.channels.xml --output=guide.xml --days=2 const { parser, url } = require('./i.mjh.nz.config.js') const dayjs = require('dayjs') From 4b95ac16f858644ec3da94b9d7ac1883439cb300 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 20 Nov 2022 17:37:29 +0300 Subject: [PATCH 2/4] Update i.mjh.nz.config.js --- sites/i.mjh.nz/i.mjh.nz.config.js | 69 +++++++------------------------ 1 file changed, 16 insertions(+), 53 deletions(-) diff --git a/sites/i.mjh.nz/i.mjh.nz.config.js b/sites/i.mjh.nz/i.mjh.nz.config.js index fff66b18..5a696e54 100644 --- a/sites/i.mjh.nz/i.mjh.nz.config.js +++ b/sites/i.mjh.nz/i.mjh.nz.config.js @@ -7,78 +7,41 @@ const customParseFormat = require('dayjs/plugin/customParseFormat') dayjs.extend(isBetween) dayjs.extend(customParseFormat) +const API_ENDPOINT = 'https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master' + module.exports = { site: 'i.mjh.nz', request: { cache: { - ttl: 6 * 60 * 60 * 1000 // 6h + ttl: 3 * 60 * 60 * 1000 // 3h }, - maxContentLength: 20 * 1024 * 1024 // 20Mb + maxContentLength: 30 * 1024 * 1024 // 30Mb }, url: function ({ channel }) { - const [source] = channel.site_id.split('#') + const [path] = channel.site_id.split('#') - return `https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master/${source}.xml` + return `${API_ENDPOINT}/${path}.xml` }, parser: function ({ content, channel, date, cached }) { - let programs = [] - const items = parseItems(content, channel, date) - items.forEach(item => { - programs.push({ - title: parseTitle(item, channel), - description: parseDescription(item, channel), - category: parseCategory(item, channel), - start: parseStart(item), - stop: parseStop(item) - }) - }) - - return programs + return parseItems(content, channel, date) }, async channels({ path, lang = 'en' }) { - const [service] = path.split('/') - let data = await axios - .get(`https://i.mjh.nz/${service}/app.json`) + let xml = await axios + .get(`${API_ENDPOINT}/${path}.xml`) .then(r => r.data) .catch(console.log) + let data = parser.parse(xml) - const channels = [] - const items = data.channels || data - for (let id in items) { - const channel = items[id] - channels.push({ + return data.channels.map(channel => { + return { lang, - site_id: `${path}#${id}`, - name: channel.name - }) - } - - return channels + site_id: `${path}#${channel.id}`, + name: channel.name[0].value + } + }) } } -function parseTitle(item, channel) { - return item.title.length ? item.title[0].value : null -} - -function parseDescription(item, channel) { - return item.desc.length ? item.desc[0].value : null -} - -function parseCategory(item, channel) { - const category = item.category.length ? item.category[0].value : '' - - return category.split(/\s\&\;\s/g).filter(c => c) -} - -function parseStart(item) { - return dayjs(item.start, 'YYYYMMDDHHmmss ZZ') -} - -function parseStop(item) { - return dayjs(item.stop, 'YYYYMMDDHHmmss ZZ') -} - function parseItems(content, channel, date) { try { const curr_day = date From 20be5bc168038cb7f738e6a8f9c1259c26b75afe Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 20 Nov 2022 17:37:37 +0300 Subject: [PATCH 3/4] Create i.mjh.nz_us-skygo.channels.xml --- sites/i.mjh.nz/i.mjh.nz_us-skygo.channels.xml | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 sites/i.mjh.nz/i.mjh.nz_us-skygo.channels.xml diff --git a/sites/i.mjh.nz/i.mjh.nz_us-skygo.channels.xml b/sites/i.mjh.nz/i.mjh.nz_us-skygo.channels.xml new file mode 100644 index 00000000..2338b68f --- /dev/null +++ b/sites/i.mjh.nz/i.mjh.nz_us-skygo.channels.xml @@ -0,0 +1,104 @@ + + + + Al Jazeera + Animal Planet + BBC Earth + BBC UKTV + BBC World News + Bravo + Bravo PLUS 1 + Breeze TV + Cartoon Network + Cbeebies + CGTN + CGTN Documentary + CNBC + CNN + Colors + Country TV + Discovery + Discovery Turbo + E! + FACE TV + Firstlight + HGTV + HISTORY + Hope Channel + JONES! + JONES! too + Living + MTV 80s + MTV Hits + MTV + Nickelodeon + Nick Jr. + Nick Music + Parliament TV + Prime + Prime PLUS 1 + Rialto + RT + Shine TV + SKY Arena + Sky Arts + SKY Box Office 041 + SKY Box Office 042 + SKY Box Office 043 + Sky Box Sets + Sky Movies Action + Sky Movies Classics + Sky Movies Family + Sky Movies Greats + Sky Movies Premiere + Sky News + Sky Sport 1 + Sky Sport 2 + Sky Sport 3 + Sky Sport 4 + Sky Sport 5 + Sky Sport 6 + Sky Sport 7 beIN SPORTS + Sky Sport 9 + SoHo + Star Gold + TAB Trackside 1 + TAB Trackside 2 + Te Reo + The Edge TV + Three + ThreePlusOne + TLC + TVNZ 1 + TVNZ 1+1 + TVNZ 2 + TVNZ 2+1 + TVNZ DUKE + DukePlus1 + Universal TV + Vibe + + + + + + + + + + + + + + + + + + + + + + + + + From 8cc92c8b0b4a530ab6bf2761c091257dbbeb0988 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 20 Nov 2022 17:44:22 +0300 Subject: [PATCH 4/4] Update i.mjh.nz.test.js --- sites/i.mjh.nz/i.mjh.nz.test.js | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/sites/i.mjh.nz/i.mjh.nz.test.js b/sites/i.mjh.nz/i.mjh.nz.test.js index 7938511f..09051478 100644 --- a/sites/i.mjh.nz/i.mjh.nz.test.js +++ b/sites/i.mjh.nz/i.mjh.nz.test.js @@ -25,22 +25,20 @@ it('can generate valid url', () => { it('can parse response', () => { const content = ` Little Stars Universe Barney and Friends Baby Bop forgets to say "please" and "thank you". Riff shares his dream of becoming an inventor. Children & Family Barney and Friends Baby Bop forgets to say "please" and "thank you". Riff shares his dream of becoming an inventor. Children & Family ` - const result = parser({ content, channel, date }).map(p => { - p.start = p.start.toJSON() - p.stop = p.stop.toJSON() - return p - }) + const results = parser({ content, channel, date }) - expect(result).toMatchObject([ - { - start: '2022-05-03T10:49:22.000Z', - stop: '2022-05-03T11:21:22.000Z', - title: 'Barney and Friends', - description: - 'Baby Bop forgets to say "please" and "thank you". Riff shares his dream of becoming an inventor.', - category: ['Children', 'Family'] - } - ]) + expect(results[0]).toMatchObject({ + start: '2022-05-03T10:49:22.000Z', + stop: '2022-05-03T11:21:22.000Z', + title: [{ value: 'Barney and Friends' }], + desc: [ + { + value: + 'Baby Bop forgets to say "please" and "thank you". Riff shares his dream of becoming an inventor.' + } + ], + category: [{ value: 'Children & Family' }] + }) }) it('can handle empty guide', () => {