forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
virgintvgo.virginmedia.com.config.js
117 lines (104 loc) · 3.14 KB
/
virgintvgo.virginmedia.com.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const axios = require('axios')
const dayjs = require('dayjs')
const API_ENDPOINT = 'https://prod.oesp.virginmedia.com/oesp/v4/GB/eng/web'
module.exports = {
site: 'virgintvgo.virginmedia.com',
days: 2,
request: {
cache: {
ttl: 60 * 60 * 1000 // 1 hour
}
},
url: function ({ date }) {
return `${API_ENDPOINT}/programschedules/${date.format('YYYYMMDD')}/1`
},
async parser({ content, channel, date }) {
let programs = []
let items = parseItems(content, channel)
if (!items.length) return programs
const d = date.format('YYYYMMDD')
const promises = [
axios.get(`${API_ENDPOINT}/programschedules/${d}/2`),
axios.get(`${API_ENDPOINT}/programschedules/${d}/3`),
axios.get(`${API_ENDPOINT}/programschedules/${d}/4`)
]
await Promise.allSettled(promises)
.then(results => {
results.forEach(r => {
if (r.status === 'fulfilled') {
items = items.concat(parseItems(r.value.data, channel))
}
})
})
.catch(console.error)
// items.forEach(item => {
for (let item of items) {
const detail = await loadProgramDetails(item)
programs.push({
title: item.t,
description: parseDescription(detail),
category: parseCategory(detail),
season: parseSeason(detail),
episode: parseEpisode(detail),
start: parseStart(item),
stop: parseStop(item)
})
}
//)
return programs
},
async channels() {
const data = await axios
.get(`${API_ENDPOINT}/channels`)
.then(r => r.data)
.catch(console.log)
return data.channels.map(item => {
return {
lang: 'en',
site_id: item.id.replace('lgi-gb-prodobo-master:40980-', ''),
name: item.title
}
})
}
}
async function loadProgramDetails(item) {
if (!item.i) return {}
const url = `${API_ENDPOINT}/listings/${item.i}`
const data = await axios
.get(url)
.then(r => r.data)
.catch(console.log)
return data || {}
}
function parseStart(item) {
return dayjs(item.s)
}
function parseStop(item) {
return dayjs(item.e)
}
function parseItems(content, channel) {
const data = typeof content === 'string' ? JSON.parse(content) : content
if (!data || !Array.isArray(data.entries)) return []
const entity = data.entries.find(e => e.o === `lgi-gb-prodobo-master:${channel.site_id}`)
return entity ? entity.l : []
}
function parseDescription(detail) {
return detail.program.longDescription || null
}
function parseCategory(detail) {
let categories = []
detail.program.categories.forEach(category => {
categories.push(category.title)
})
return categories
}
function parseSeason(detail) {
if (!detail.program.seriesNumber) return null
if (String(detail.program.seriesNumber).length > 2) return null
return detail.program.seriesNumber
}
function parseEpisode(detail) {
if (!detail.program.seriesEpisodeNumber) return null
if (String(detail.program.seriesEpisodeNumber).length > 3) return null
return detail.program.seriesEpisodeNumber
}