diff --git a/.github/workflows/sportsnet.ca.yml b/.github/workflows/sportsnet.ca.yml new file mode 100644 index 00000000..375a84cc --- /dev/null +++ b/.github/workflows/sportsnet.ca.yml @@ -0,0 +1,17 @@ +name: sportsnet.ca +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 }} diff --git a/sites/sportsnet.ca/sportsnet.ca.config.js b/sites/sportsnet.ca/sportsnet.ca.config.js new file mode 100644 index 00000000..5a73609f --- /dev/null +++ b/sites/sportsnet.ca/sportsnet.ca.config.js @@ -0,0 +1,49 @@ +const dayjs = require('dayjs') +const utc = require('dayjs/plugin/utc') + +dayjs.extend(utc) + +module.exports = { + site: 'sportsnet.ca', + url: function ({ channel, date }) { + return `https://production-cdn.sportsnet.ca/api/schedules?channels=${ + channel.site_id + }&date=${date.format('YYYY-MM-DD')}&duration=24&hour=0` + }, + parser: function ({ content }) { + let programs = [] + const items = parseItems(content) + items.forEach(item => { + programs.push({ + title: item.item.title, + description: item.item.shortDescription, + icon: parseIcon(item), + start: parseStart(item), + stop: parseStop(item) + }) + }) + + return programs + } +} + +function parseIcon(item) { + if (!item.item || !item.item.images) return null + + return item.item.images.tile +} + +function parseStart(item) { + return dayjs.utc(item.startDate) +} + +function parseStop(item) { + return dayjs.utc(item.endDate) +} + +function parseItems(content) { + const data = JSON.parse(content) + if (!Array.isArray(data) || !Array.isArray(data[0].schedules)) return [] + + return data[0].schedules +} diff --git a/sites/sportsnet.ca/sportsnet.ca.test.js b/sites/sportsnet.ca/sportsnet.ca.test.js new file mode 100644 index 00000000..324b086a --- /dev/null +++ b/sites/sportsnet.ca/sportsnet.ca.test.js @@ -0,0 +1,47 @@ +// npx epg-grabber --config=sites/sportsnet.ca/sportsnet.ca.config.js --channels=sites/sportsnet.ca/sportsnet.ca_ca.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./sportsnet.ca.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-03-14', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '24533', + xmltv_id: 'SportsNetOntario.ca' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://production-cdn.sportsnet.ca/api/schedules?channels=24533&date=2022-03-14&duration=24&hour=0' + ) +}) + +it('can parse response', () => { + const content = `[{"channelId":"24533","startDate":"2022-03-14T00:00:00.000Z","endDate":"2022-03-15T00:00:00.000Z","schedules":[{"channelId":"24533","customFields":{"ContentId":"EP029977175139","Checksum":"2DA90E7E66B9C311F98B186B89C50FAD"},"endDate":"2022-03-14T02:30:00Z","id":"826cb731-9de4-4cf3-bcca-d548d8a33d16","startDate":"2022-03-14T00:00:00Z","item":{"id":"34a028b0-eacf-40f3-9bf9-62ee3330df1b","type":"program","title":"Calgary Flames at Colorado Avalanche","shortDescription":"Johnny Gaudreau and the Flames pay a visit to the Avalanche. Calgary won 4-3 in overtime March 5.","path":"/channel/24533","duration":9000,"images":{"tile":"https://production-static.sportsnet-static.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='785305'&EntityType='LinearSchedule'&EntityId='826cb731-9de4-4cf3-bcca-d548d8a33d16'&Width=3840&Height=2160","wallpaper":"https://production-static.sportsnet-static.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='785311'&EntityType='LinearSchedule'&EntityId='826cb731-9de4-4cf3-bcca-d548d8a33d16'&Width=3840&Height=2160"}}}]}]` + const result = parser({ content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-03-14T00:00:00.000Z', + stop: '2022-03-14T02:30:00.000Z', + title: 'Calgary Flames at Colorado Avalanche', + description: + 'Johnny Gaudreau and the Flames pay a visit to the Avalanche. Calgary won 4-3 in overtime March 5.', + icon: "https://production-static.sportsnet-static.com/shain/v1/dataservice/ResizeImage/$value?Format='jpg'&Quality=85&ImageId='785305'&EntityType='LinearSchedule'&EntityId='826cb731-9de4-4cf3-bcca-d548d8a33d16'&Width=3840&Height=2160" + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: `[{"channelId":"245321","startDate":"2022-03-14T00:00:00.000Z","endDate":"2022-03-15T00:00:00.000Z","schedules":[]}]` + }) + expect(result).toMatchObject([]) +}) diff --git a/sites/sportsnet.ca/sportsnet.ca_ca.channels.xml b/sites/sportsnet.ca/sportsnet.ca_ca.channels.xml new file mode 100644 index 00000000..47140dab --- /dev/null +++ b/sites/sportsnet.ca/sportsnet.ca_ca.channels.xml @@ -0,0 +1,13 @@ + + + + SportsNet Ontario + SportsNet One + SportsNet 360 + SportsNet West + SportsNet East + SportsNet Pacific + SportsNet World + WWE Network Canada + +