From b9226aadf9abc95b3e0d56dcb23bff0efaf62065 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 10 Jun 2022 13:42:42 +0300 Subject: [PATCH 1/7] Create mewatch.sg.test.js --- sites/mewatch.sg/mewatch.sg.test.js | 54 +++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 sites/mewatch.sg/mewatch.sg.test.js diff --git a/sites/mewatch.sg/mewatch.sg.test.js b/sites/mewatch.sg/mewatch.sg.test.js new file mode 100644 index 00000000..e98f8590 --- /dev/null +++ b/sites/mewatch.sg/mewatch.sg.test.js @@ -0,0 +1,54 @@ +// npx epg-grabber --config=sites/mewatch.sg/mewatch.sg.config.js --channels=sites/mewatch.sg/mewatch.sg_sg.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./mewatch.sg.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('2022-06-11', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '97098', + xmltv_id: 'Channel5Singapore.sg' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://cdn.mewatch.sg/api/schedules?channels=97098&date=2022-06-11&duration=24&ff=idp,ldp,rpt,cd&hour=21&intersect=true&lang=en&segments=all' + ) +}) + +it('can parse response', () => { + const content = `[{"channelId":"97098","startDate":"2022-06-11T21:00:00.000Z","endDate":"2022-06-12T21:00:00.000Z","schedules":[{"channelId":"97098","customId":"37040748","endDate":"2022-06-11T21:30:00Z","id":"788a7dd","live":false,"startDate":"2022-06-11T21:00:00Z","isGap":false,"InteractiveType":"0","item":{"type":"episode","title":"Open Homes S3 - EP 2","blackoutMessage":"Programme is not available for live streaming.","description":"Mike heads down to the Sydney beaches to visit a beachside renovation with all the bells and whistles, we see a kitchen tip and recipe anyone can do at home. We finish up in the prestigious Byron bay to visit a multi million dollar award winning home.","classification":{"code":"IMDA-G","name":"G"},"episodeNumber":2,"episodeTitle":"Collaroy, Sydney","seasonNumber":3,"images":{"wallpaper":"https://production.togglestatic.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='4853691'&EntityType='LinearSchedule'&EntityId='788a7dd9-9b12-446f-91b4-c8ac9fec95e5'&Width=1280&Height=720&device=web_browser&subscriptions=Anonymous&segmentationTags=all","tile":"https://production.togglestatic.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='4853697'&EntityType='LinearSchedule'&EntityId='788a7dd9-9b12-446f-91b4-c8ac9fec95e5'&Width=1280&Height=720&device=web_browser&subscriptions=Anonymous&segmentationTags=all"},"enableCatchUp":true,"enableStartOver":false,"enableSeeking":false,"programSource":"ACQUIRED","simulcast":"LOCAL","masterReferenceKey":"0CH50CH5A0105567800020A0000000000P3254400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}}]}]` + const result = parser({ content, channel }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-06-11T21:00:00.000Z', + stop: '2022-06-11T21:30:00.000Z', + title: 'Open Homes S3 - EP 2', + description: + 'Mike heads down to the Sydney beaches to visit a beachside renovation with all the bells and whistles, we see a kitchen tip and recipe anyone can do at home. We finish up in the prestigious Byron bay to visit a multi million dollar award winning home.', + icon: `https://production.togglestatic.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='4853697'&EntityType='LinearSchedule'&EntityId='788a7dd9-9b12-446f-91b4-c8ac9fec95e5'&Width=1280&Height=720&device=web_browser&subscriptions=Anonymous&segmentationTags=all`, + episode: 2, + season: 3, + rating: { + system: 'IMDA', + value: 'G' + } + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: `[{"channelId":"9798","startDate":"2022-06-11T21:00:00.000Z","endDate":"2022-06-12T21:00:00.000Z","schedules":[]}]`, + channel + }) + expect(result).toMatchObject([]) +}) From 6618ac6beae59ee95c2067c5f589b5d15bd7a8f8 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 10 Jun 2022 13:42:48 +0300 Subject: [PATCH 2/7] Create mewatch.sg.config.js --- sites/mewatch.sg/mewatch.sg.config.js | 56 +++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 sites/mewatch.sg/mewatch.sg.config.js diff --git a/sites/mewatch.sg/mewatch.sg.config.js b/sites/mewatch.sg/mewatch.sg.config.js new file mode 100644 index 00000000..8b1bec06 --- /dev/null +++ b/sites/mewatch.sg/mewatch.sg.config.js @@ -0,0 +1,56 @@ +const dayjs = require('dayjs') + +module.exports = { + site: 'mewatch.sg', + url: function ({ channel, date }) { + return `https://cdn.mewatch.sg/api/schedules?channels=${channel.site_id}&date=${date.format( + 'YYYY-MM-DD' + )}&duration=24&ff=idp,ldp,rpt,cd&hour=21&intersect=true&lang=en&segments=all` + }, + parser: function ({ content, channel }) { + let programs = [] + const items = parseItems(content, channel) + items.forEach(item => { + const info = item.item + programs.push({ + title: info.title, + description: info.description, + icon: info.images.tile, + episode: info.episodeNumber, + season: info.seasonNumber, + start: parseStart(item), + stop: parseStop(item), + rating: parseRating(info) + }) + }) + + return programs + } +} + +function parseStart(item) { + return dayjs(item.startDate) +} + +function parseStop(item) { + return dayjs(item.endDate) +} + +function parseRating(info) { + const classification = info.classification + if (classification && classification.code) { + const [system, value] = classification.code.split('-') + + return { system, value } + } + + return null +} + +function parseItems(content, channel) { + const data = JSON.parse(content) + if (!data || !Array.isArray(data)) return [] + const channelData = data.find(i => i.channelId === channel.site_id) + + return channelData && Array.isArray(channelData.schedules) ? channelData.schedules : [] +} From 9ebdfbbbba469163e1cafa4de9e814ab89134df2 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 10 Jun 2022 13:43:08 +0300 Subject: [PATCH 3/7] Create mewatch.sg_sg.channels.xml --- sites/mewatch.sg/mewatch.sg_sg.channels.xml | 22 +++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 sites/mewatch.sg/mewatch.sg_sg.channels.xml diff --git a/sites/mewatch.sg/mewatch.sg_sg.channels.xml b/sites/mewatch.sg/mewatch.sg_sg.channels.xml new file mode 100644 index 00000000..d2c08bde --- /dev/null +++ b/sites/mewatch.sg/mewatch.sg_sg.channels.xml @@ -0,0 +1,22 @@ + + + + Channel 5 + Channel 8 + Channel U + Suria + Vasantham + CNA + oktolidays + eGG Network + Animax + GEM + HBO + HBO Hits + HBO Family + HBO Signature + Cinemax + LIVE 1 + LIVE 2 + + From 7dffe1c80679c260b55c026d96eee45c64a8345c Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 10 Jun 2022 14:58:30 +0300 Subject: [PATCH 4/7] Update mewatch.sg_sg.channels.xml --- sites/mewatch.sg/mewatch.sg_sg.channels.xml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sites/mewatch.sg/mewatch.sg_sg.channels.xml b/sites/mewatch.sg/mewatch.sg_sg.channels.xml index d2c08bde..edb9b6b9 100644 --- a/sites/mewatch.sg/mewatch.sg_sg.channels.xml +++ b/sites/mewatch.sg/mewatch.sg_sg.channels.xml @@ -1,21 +1,21 @@ - Channel 5 - Channel 8 + Channel 5 + Channel 8 Channel U Suria Vasantham CNA oktolidays - eGG Network + eGG Network Animax - GEM - HBO + GEM + HBO HBO Hits - HBO Family - HBO Signature - Cinemax + HBO Family + HBO Signature + Cinemax LIVE 1 LIVE 2 From 1da50aa4799a0da0a5a3e48d7d4363d3ad1503fb Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 10 Jun 2022 14:59:13 +0300 Subject: [PATCH 5/7] Create mewatch.sg.yml --- .github/workflows/mewatch.sg.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/mewatch.sg.yml diff --git a/.github/workflows/mewatch.sg.yml b/.github/workflows/mewatch.sg.yml new file mode 100644 index 00000000..3211f0f6 --- /dev/null +++ b/.github/workflows/mewatch.sg.yml @@ -0,0 +1,17 @@ +name: mewatch.sg +on: + schedule: + - cron: '0 0 * * *' + workflow_dispatch: + workflow_run: + workflows: [_trigger] + types: + - completed +jobs: + load: + uses: ./.github/workflows/_load.yml + with: + site: ${{github.workflow}} + secrets: + APP_ID: ${{ secrets.APP_ID }} + APP_PRIVATE_KEY: ${{ secrets.APP_PRIVATE_KEY }} From 04f3d11e9c95a957c7bfa737d6eea3f5a99071c8 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 13 Jun 2022 18:43:20 +0300 Subject: [PATCH 6/7] Update mewatch.sg.test.js --- sites/mewatch.sg/mewatch.sg.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sites/mewatch.sg/mewatch.sg.test.js b/sites/mewatch.sg/mewatch.sg.test.js index e98f8590..698d4f86 100644 --- a/sites/mewatch.sg/mewatch.sg.test.js +++ b/sites/mewatch.sg/mewatch.sg.test.js @@ -20,7 +20,7 @@ it('can generate valid url', () => { }) it('can parse response', () => { - const content = `[{"channelId":"97098","startDate":"2022-06-11T21:00:00.000Z","endDate":"2022-06-12T21:00:00.000Z","schedules":[{"channelId":"97098","customId":"37040748","endDate":"2022-06-11T21:30:00Z","id":"788a7dd","live":false,"startDate":"2022-06-11T21:00:00Z","isGap":false,"InteractiveType":"0","item":{"type":"episode","title":"Open Homes S3 - EP 2","blackoutMessage":"Programme is not available for live streaming.","description":"Mike heads down to the Sydney beaches to visit a beachside renovation with all the bells and whistles, we see a kitchen tip and recipe anyone can do at home. We finish up in the prestigious Byron bay to visit a multi million dollar award winning home.","classification":{"code":"IMDA-G","name":"G"},"episodeNumber":2,"episodeTitle":"Collaroy, Sydney","seasonNumber":3,"images":{"wallpaper":"https://production.togglestatic.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='4853691'&EntityType='LinearSchedule'&EntityId='788a7dd9-9b12-446f-91b4-c8ac9fec95e5'&Width=1280&Height=720&device=web_browser&subscriptions=Anonymous&segmentationTags=all","tile":"https://production.togglestatic.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='4853697'&EntityType='LinearSchedule'&EntityId='788a7dd9-9b12-446f-91b4-c8ac9fec95e5'&Width=1280&Height=720&device=web_browser&subscriptions=Anonymous&segmentationTags=all"},"enableCatchUp":true,"enableStartOver":false,"enableSeeking":false,"programSource":"ACQUIRED","simulcast":"LOCAL","masterReferenceKey":"0CH50CH5A0105567800020A0000000000P3254400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}}]}]` + const content = `[{"channelId":"97098","startDate":"2022-06-11T21:00:00.000Z","endDate":"2022-06-12T21:00:00.000Z","schedules":[{"channelId":"97098","customId":"37040748","endDate":"2022-06-11T21:30:00Z","id":"788a7dd","live":false,"startDate":"2022-06-11T21:00:00Z","isGap":false,"InteractiveType":"0","item":{"type":"episode","title":"Open Homes S3 - EP 2","blackoutMessage":"Programme is not available for live streaming.","description":"Mike heads down to the Sydney beaches to visit a beachside renovation with all the bells and whistles, we see a kitchen tip and recipe anyone can do at home. We finish up in the prestigious Byron bay to visit a multi million dollar award winning home.","classification":{"code":"IMDA-G (Violence)","name":"G (Violence)"},"episodeNumber":2,"episodeTitle":"Collaroy, Sydney","seasonNumber":3,"images":{"wallpaper":"https://production.togglestatic.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='4853691'&EntityType='LinearSchedule'&EntityId='788a7dd9-9b12-446f-91b4-c8ac9fec95e5'&Width=1280&Height=720&device=web_browser&subscriptions=Anonymous&segmentationTags=all","tile":"https://production.togglestatic.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='4853697'&EntityType='LinearSchedule'&EntityId='788a7dd9-9b12-446f-91b4-c8ac9fec95e5'&Width=1280&Height=720&device=web_browser&subscriptions=Anonymous&segmentationTags=all"},"enableCatchUp":true,"enableStartOver":false,"enableSeeking":false,"programSource":"ACQUIRED","simulcast":"LOCAL","masterReferenceKey":"0CH50CH5A0105567800020A0000000000P3254400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"}}]}]` const result = parser({ content, channel }).map(p => { p.start = p.start.toJSON() p.stop = p.stop.toJSON() From d44e445c3235bdd2551e2cb1cc6e94766b991132 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 13 Jun 2022 18:43:23 +0300 Subject: [PATCH 7/7] Update mewatch.sg.config.js --- sites/mewatch.sg/mewatch.sg.config.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sites/mewatch.sg/mewatch.sg.config.js b/sites/mewatch.sg/mewatch.sg.config.js index 8b1bec06..ebfa4589 100644 --- a/sites/mewatch.sg/mewatch.sg.config.js +++ b/sites/mewatch.sg/mewatch.sg.config.js @@ -39,7 +39,11 @@ function parseStop(item) { function parseRating(info) { const classification = info.classification if (classification && classification.code) { - const [system, value] = classification.code.split('-') + const [_, system, value] = classification.code.match(/^([A-Z]+)\-([A-Z0-9]+)/) || [ + null, + null, + null + ] return { system, value } }