From 3fc8c8e41d09fce34175938c9191ba21cd8f9a48 Mon Sep 17 00:00:00 2001 From: RevGear Date: Wed, 14 Dec 2022 22:11:28 +0000 Subject: [PATCH 1/4] foxsports.com.au --- .../foxsports.com.au.config.js | 39 ++++++++++++++++ .../foxsports.com.au/foxsports.com.au.test.js | 44 +++++++++++++++++++ .../foxsports.com.au_au.channels.xml | 21 +++++++++ 3 files changed, 104 insertions(+) create mode 100644 sites/foxsports.com.au/foxsports.com.au.config.js create mode 100644 sites/foxsports.com.au/foxsports.com.au.test.js create mode 100644 sites/foxsports.com.au/foxsports.com.au_au.channels.xml diff --git a/sites/foxsports.com.au/foxsports.com.au.config.js b/sites/foxsports.com.au/foxsports.com.au.config.js new file mode 100644 index 00000000..998812e6 --- /dev/null +++ b/sites/foxsports.com.au/foxsports.com.au.config.js @@ -0,0 +1,39 @@ +const dayjs = require('dayjs') + +module.exports = { + site: 'foxsports.com.au', + request: { + cache: { + ttl: 60 * 60 * 1000 // 1 hour + } + }, + url({ date }) { + return `https://tvguide.foxsports.com.au/granite-api/programmes.json?from=${date.format('YYYY-MM-DD')}&to=${date.add(1, 'd').format('YYYY-MM-DD')}` + }, + parser({ content, channel }) { + let programs = [] + const items = parseItems(content, channel) + items.forEach(item => { + programs.push({ + title: item.programmeTitle, + sub_title: item.title, + category: item.genreTitle, + description: item.synopsis, + start: dayjs.utc(item.startTime), + stop: dayjs.utc(item.endTime) + }) + }) + + return programs + } +} + +function parseItems(content, channel) { + const data = JSON.parse(content) + if (!data) return [] + const programmes = data['channel-programme'] + if (!Array.isArray(programmes)) return [] + + const channelData = programmes.filter(i => i.channelId == channel.site_id) + return channelData && Array.isArray(channelData) ? channelData : [] +} diff --git a/sites/foxsports.com.au/foxsports.com.au.test.js b/sites/foxsports.com.au/foxsports.com.au.test.js new file mode 100644 index 00000000..a33faf41 --- /dev/null +++ b/sites/foxsports.com.au/foxsports.com.au.test.js @@ -0,0 +1,44 @@ + +const { parser, url } = require('./foxsports.com.au.config.js') +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') +dayjs.extend(utc) + +const date = dayjs.utc('2022-12-14', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '2', + xmltv_id: 'FoxLeague.au' + } +it('can generate valid url', () => { + expect(url({ date })).toBe( + 'https://tvguide.foxsports.com.au/granite-api/programmes.json?from=2022-12-14&to=2022-12-15' + ) +}) + +it('can parse response', () => { + const content = `{"channel-programme":[{"id":"31cc8b4c-3711-49f0-bf22-2ec3993b0a07","programmeTitle":"NRL","title":"Eels v Titans","startTime":"2022-12-14T00:00:00+11:00","endTime":"2022-12-14T01:00:00+11:00","duration":60,"live":false,"genreId":"5c389cf4-8db7-4b52-9773-52355bd28559","channelId":2,"channelName":"FOX League","channelAbbreviation":"LEAGUE","programmeUID":235220,"round":"R1","statsMatchId":null,"closedCaptioned":true,"statsFixtureId":10207,"genreTitle":"Rugby League","parentGenreId":"a953f929-2d12-41a4-b0e9-97f401afff11","parentGenreTitle":"Sport","pmgId":"PMG01306944","statsSport":"league","type":"GAME","hiDef":true,"widescreen":true,"classification":"","synopsis":"The Eels and Titans have plenty of motivation this season after heartbreaking Finals losses in 2021. Parramatta has won their past five against Gold Coast.","preGameStartTime":null,"closeCaptioned":true}]}` + + const result = parser({ content, channel }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + title: 'NRL', + sub_title: 'Eels v Titans', + description: `The Eels and Titans have plenty of motivation this season after heartbreaking Finals losses in 2021. Parramatta has won their past five against Gold Coast.`, + category: 'Rugby League', + start: '2022-12-13T13:00:00.000Z', + stop: '2022-12-13T14:00:00.000Z' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: `{"channel-programme":[]}` + }, channel) + expect(result).toMatchObject([]) +}) \ No newline at end of file diff --git a/sites/foxsports.com.au/foxsports.com.au_au.channels.xml b/sites/foxsports.com.au/foxsports.com.au_au.channels.xml new file mode 100644 index 00000000..eeba20f7 --- /dev/null +++ b/sites/foxsports.com.au/foxsports.com.au_au.channels.xml @@ -0,0 +1,21 @@ + + + + + FOX League + FOX Sports 503 + + FOX Footy + FOX Sports 505 + FOX Sports 506 + FOX Sports More + FOX Cricket + + + + + + + + + \ No newline at end of file From 9a94a3ec4d7b3f2b4b9b921dd7e5ebc625a7cee5 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 16 Dec 2022 01:43:12 +0300 Subject: [PATCH 2/4] Update foxsports.com.au.test.js --- .../foxsports.com.au/foxsports.com.au.test.js | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/sites/foxsports.com.au/foxsports.com.au.test.js b/sites/foxsports.com.au/foxsports.com.au.test.js index a33faf41..751c64ef 100644 --- a/sites/foxsports.com.au/foxsports.com.au.test.js +++ b/sites/foxsports.com.au/foxsports.com.au.test.js @@ -1,3 +1,4 @@ +// npx epg-grabber --config=sites/foxsports.com.au/foxsports.com.au.config.js --channels=sites/foxsports.com.au/foxsports.com.au_au.channels.xml --output=guide.xml --days=2 const { parser, url } = require('./foxsports.com.au.config.js') const dayjs = require('dayjs') @@ -6,39 +7,42 @@ dayjs.extend(utc) const date = dayjs.utc('2022-12-14', 'YYYY-MM-DD').startOf('d') const channel = { - site_id: '2', - xmltv_id: 'FoxLeague.au' - } + site_id: '2', + xmltv_id: 'FoxLeague.au' +} it('can generate valid url', () => { - expect(url({ date })).toBe( - 'https://tvguide.foxsports.com.au/granite-api/programmes.json?from=2022-12-14&to=2022-12-15' - ) + expect(url({ date })).toBe( + 'https://tvguide.foxsports.com.au/granite-api/programmes.json?from=2022-12-14&to=2022-12-15' + ) }) it('can parse response', () => { - const content = `{"channel-programme":[{"id":"31cc8b4c-3711-49f0-bf22-2ec3993b0a07","programmeTitle":"NRL","title":"Eels v Titans","startTime":"2022-12-14T00:00:00+11:00","endTime":"2022-12-14T01:00:00+11:00","duration":60,"live":false,"genreId":"5c389cf4-8db7-4b52-9773-52355bd28559","channelId":2,"channelName":"FOX League","channelAbbreviation":"LEAGUE","programmeUID":235220,"round":"R1","statsMatchId":null,"closedCaptioned":true,"statsFixtureId":10207,"genreTitle":"Rugby League","parentGenreId":"a953f929-2d12-41a4-b0e9-97f401afff11","parentGenreTitle":"Sport","pmgId":"PMG01306944","statsSport":"league","type":"GAME","hiDef":true,"widescreen":true,"classification":"","synopsis":"The Eels and Titans have plenty of motivation this season after heartbreaking Finals losses in 2021. Parramatta has won their past five against Gold Coast.","preGameStartTime":null,"closeCaptioned":true}]}` + const content = `{"channel-programme":[{"id":"31cc8b4c-3711-49f0-bf22-2ec3993b0a07","programmeTitle":"NRL","title":"Eels v Titans","startTime":"2022-12-14T00:00:00+11:00","endTime":"2022-12-14T01:00:00+11:00","duration":60,"live":false,"genreId":"5c389cf4-8db7-4b52-9773-52355bd28559","channelId":2,"channelName":"FOX League","channelAbbreviation":"LEAGUE","programmeUID":235220,"round":"R1","statsMatchId":null,"closedCaptioned":true,"statsFixtureId":10207,"genreTitle":"Rugby League","parentGenreId":"a953f929-2d12-41a4-b0e9-97f401afff11","parentGenreTitle":"Sport","pmgId":"PMG01306944","statsSport":"league","type":"GAME","hiDef":true,"widescreen":true,"classification":"","synopsis":"The Eels and Titans have plenty of motivation this season after heartbreaking Finals losses in 2021. Parramatta has won their past five against Gold Coast.","preGameStartTime":null,"closeCaptioned":true}]}` - const result = parser({ content, channel }).map(p => { - p.start = p.start.toJSON() - p.stop = p.stop.toJSON() - return p - }) + const result = parser({ content, channel }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) - expect(result).toMatchObject([ - { - title: 'NRL', - sub_title: 'Eels v Titans', - description: `The Eels and Titans have plenty of motivation this season after heartbreaking Finals losses in 2021. Parramatta has won their past five against Gold Coast.`, - category: 'Rugby League', - start: '2022-12-13T13:00:00.000Z', - stop: '2022-12-13T14:00:00.000Z' - } - ]) + expect(result).toMatchObject([ + { + title: 'NRL', + sub_title: 'Eels v Titans', + description: `The Eels and Titans have plenty of motivation this season after heartbreaking Finals losses in 2021. Parramatta has won their past five against Gold Coast.`, + category: 'Rugby League', + start: '2022-12-13T13:00:00.000Z', + stop: '2022-12-13T14:00:00.000Z' + } + ]) }) it('can handle empty guide', () => { - const result = parser({ - content: `{"channel-programme":[]}` - }, channel) - expect(result).toMatchObject([]) -}) \ No newline at end of file + const result = parser( + { + content: `{"channel-programme":[]}` + }, + channel + ) + expect(result).toMatchObject([]) +}) From 396c74e86a32f23202f7204b02150db6fa225404 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 16 Dec 2022 01:43:26 +0300 Subject: [PATCH 3/4] Update foxsports.com.au_au.channels.xml --- sites/foxsports.com.au/foxsports.com.au_au.channels.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/sites/foxsports.com.au/foxsports.com.au_au.channels.xml b/sites/foxsports.com.au/foxsports.com.au_au.channels.xml index eeba20f7..d7bc38b2 100644 --- a/sites/foxsports.com.au/foxsports.com.au_au.channels.xml +++ b/sites/foxsports.com.au/foxsports.com.au_au.channels.xml @@ -1,15 +1,15 @@ - + FOX Cricket + FOX Footy FOX League FOX Sports 503 - - FOX Footy FOX Sports 505 FOX Sports 506 FOX Sports More - FOX Cricket + FOX Sports News + From 5ee0642799b983d39d6508e1acceb3fdc28c3274 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 16 Dec 2022 01:43:32 +0300 Subject: [PATCH 4/4] Create foxsports.com.au.yml --- .github/workflows/foxsports.com.au.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/foxsports.com.au.yml diff --git a/.github/workflows/foxsports.com.au.yml b/.github/workflows/foxsports.com.au.yml new file mode 100644 index 00000000..8100af83 --- /dev/null +++ b/.github/workflows/foxsports.com.au.yml @@ -0,0 +1,17 @@ +name: foxsports.com.au +on: + schedule: + - cron: '0 3 * * *' + 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 }}