forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
watch.sportsnet.ca.config.js
69 lines (58 loc) · 1.69 KB
/
watch.sportsnet.ca.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
dayjs.extend(utc)
module.exports = {
site: 'watch.sportsnet.ca',
days: 2,
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
},
async channels() {
const axios = require('axios')
const html = await axios
.get(`https://watch.sportsnet.ca/schedule/tvlistings`)
.then(r => r.data)
.catch(console.log)
let [, __data] = html.match(/window\.__data \= ([^<]+)<\/script>/)
const func = new Function(`"use strict";return ${__data}`)
const data = func()
return data.cache.list['678|page_size=24'].list.items.map(item => {
return {
lang: 'en',
site_id: item.id,
name: item.title
}
})
}
}
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
}