forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
foxsports.com.au.config.js
69 lines (61 loc) · 1.81 KB
/
foxsports.com.au.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: 'foxsports.com.au',
days: 3,
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
},
async channels() {
const axios = require('axios')
const data = await axios
.get(
`https://tvguide.foxsports.com.au/granite-api/programmes.json?from=${dayjs().format(
'YYYY-MM-DD'
)}&to=${dayjs().add(1, 'd').format('YYYY-MM-DD')}`
)
.then(r => r.data)
.catch(console.log)
let channels = {}
data['channel-programme'].forEach(item => {
if (channels[item.channelId]) return
channels[item.channelId] = {
lang: 'en',
site_id: item.channelId,
name: item.channelName
}
})
return Object.values(channels)
}
}
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 : []
}