mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Merge pull request #626 from iptv-org/add-sportsnet.ca
Add guide from sportsnet.ca
This commit is contained in:
commit
0a91f53547
4 changed files with 126 additions and 0 deletions
17
.github/workflows/sportsnet.ca.yml
vendored
Normal file
17
.github/workflows/sportsnet.ca.yml
vendored
Normal file
|
@ -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 }}
|
49
sites/sportsnet.ca/sportsnet.ca.config.js
Normal file
49
sites/sportsnet.ca/sportsnet.ca.config.js
Normal file
|
@ -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
|
||||
}
|
47
sites/sportsnet.ca/sportsnet.ca.test.js
Normal file
47
sites/sportsnet.ca/sportsnet.ca.test.js
Normal file
|
@ -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([])
|
||||
})
|
13
sites/sportsnet.ca/sportsnet.ca_ca.channels.xml
Normal file
13
sites/sportsnet.ca/sportsnet.ca_ca.channels.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="sportsnet.ca">
|
||||
<channels>
|
||||
<channel lang="en" xmltv_id="SportsNetOntario.ca" site_id="24533">SportsNet Ontario</channel>
|
||||
<channel lang="en" xmltv_id="SportsNetOne.ca" site_id="24469">SportsNet One</channel>
|
||||
<channel lang="en" xmltv_id="SportsNet360.ca" site_id="24467">SportsNet 360</channel>
|
||||
<channel lang="en" xmltv_id="SportsNetWest.ca" site_id="24468">SportsNet West</channel>
|
||||
<channel lang="en" xmltv_id="SportsNetEast.ca" site_id="24466">SportsNet East</channel>
|
||||
<channel lang="en" xmltv_id="SportsNetPacific.ca" site_id="24530">SportsNet Pacific</channel>
|
||||
<channel lang="en" xmltv_id="SportsNetWorld.ca" site_id="5895">SportsNet World</channel>
|
||||
<channel lang="en" xmltv_id="WWENetworkCanada.us" site_id="29659">WWE Network Canada</channel>
|
||||
</channels>
|
||||
</site>
|
Loading…
Add table
Add a link
Reference in a new issue