forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
i.mjh.nz.config.js
178 lines (158 loc) · 5.35 KB
/
i.mjh.nz.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
const dayjs = require('dayjs')
const axios = require('axios')
const parser = require('epg-parser')
const isBetween = require('dayjs/plugin/isBetween')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(isBetween)
dayjs.extend(customParseFormat)
const API_ENDPOINT = 'https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master'
module.exports = {
site: 'i.mjh.nz',
days: 2,
request: {
cache: {
ttl: 3 * 60 * 60 * 1000 // 3h
},
maxContentLength: 100 * 1024 * 1024 // 100Mb
},
url: function ({ channel }) {
const [path] = channel.site_id.split('#')
return `${API_ENDPOINT}/${path}.xml`
},
parser: function ({ content, channel, date }) {
const items = parseItems(content, channel, date)
let programs = items.map(item => {
return {
...item,
title: getTitle(item),
description: getDescription(item),
categories: getCategories(item)
}
})
programs = mergeMovieParts(programs)
return programs
},
async channels({ provider }) {
const providers = {
pluto: [
{ path: 'PlutoTV/br', lang: 'pt' },
{ path: 'PlutoTV/ca', lang: 'en' },
{ path: 'PlutoTV/cl', lang: 'es' },
{ path: 'PlutoTV/de', lang: 'de' },
{ path: 'PlutoTV/dk', lang: 'da' },
{ path: 'PlutoTV/es', lang: 'es' },
{ path: 'PlutoTV/fr', lang: 'fr' },
{ path: 'PlutoTV/gb', lang: 'en' },
{ path: 'PlutoTV/it', lang: 'it' },
{ path: 'PlutoTV/mx', lang: 'es' },
{ path: 'PlutoTV/no', lang: 'no' },
{ path: 'PlutoTV/se', lang: 'sv' },
{ path: 'PlutoTV/us', lang: 'en' }
],
plex: [
{ path: 'Plex/au', lang: 'en' },
{ path: 'Plex/ca', lang: 'en' },
{ path: 'Plex/es', lang: 'es' },
{ path: 'Plex/mx', lang: 'es' },
{ path: 'Plex/nz', lang: 'en' },
{ path: 'Plex/us', lang: 'en' }
],
samsung: [
{ path: 'SamsungTVPlus/at', lang: 'de' },
{ path: 'SamsungTVPlus/ca', lang: 'en' },
{ path: 'SamsungTVPlus/ch', lang: 'de' },
{ path: 'SamsungTVPlus/de', lang: 'de' },
{ path: 'SamsungTVPlus/es', lang: 'es' },
{ path: 'SamsungTVPlus/fr', lang: 'fr' },
{ path: 'SamsungTVPlus/gb', lang: 'en' },
{ path: 'SamsungTVPlus/in', lang: 'en' },
{ path: 'SamsungTVPlus/it', lang: 'it' },
{ path: 'SamsungTVPlus/kr', lang: 'ko' },
{ path: 'SamsungTVPlus/us', lang: 'en' }
],
skygo: [{ path: 'SkyGo/epg', lang: 'en' }],
stirr: [{ path: 'Stirr/all', lang: 'en' }],
foxtel: [{ path: 'Foxtel/epg', lang: 'en' }],
binge: [{ path: 'Binge/epg', lang: 'en' }],
dstv: [{ path: 'DStv/za', lang: 'en' }],
flash: [{ path: 'Flash/epg', lang: 'en' }],
kayo: [{ path: 'Kayo/epg', lang: 'en' }],
metv: [{ path: 'MeTV/epg', lang: 'en' }],
optus: [{ path: 'Optus/epg', lang: 'en' }],
pbs: [{ path: 'PBS/all', lang: 'en' }],
roku: [{ path: 'Roku/epg', lang: 'en' }],
singtel: [{ path: 'Singtel/epg', lang: 'en' }],
skysportnow: [{ path: 'SkySportNow/epg', lang: 'en' }],
au: [
{ path: 'au/Adelaide/epg', lang: 'en' },
{ path: 'au/Brisbane/epg', lang: 'en' },
{ path: 'au/Canberra/epg', lang: 'en' },
{ path: 'au/Darwin/epg', lang: 'en' },
{ path: 'au/Hobart/epg', lang: 'en' },
{ path: 'au/Melbourne/epg', lang: 'en' },
{ path: 'au/Perth/epg', lang: 'en' },
{ path: 'au/Sydney/epg', lang: 'en' }
],
hgtvgo: [{ path: 'hgtv_go/epg', lang: 'en' }],
nz: [{ path: 'nz/epg', lang: 'en' }]
}
let channels = []
const providerOptions = providers[provider]
for (const option of providerOptions) {
const xml = await axios
.get(`${API_ENDPOINT}/${option.path}.xml`)
.then(r => r.data)
.catch(console.log)
const data = parser.parse(xml)
data.channels.forEach(item => {
channels.push({
lang: option.lang,
site_id: `${option.path}#${item.id}`,
name: item.name[0].value
})
})
}
return channels
}
}
function mergeMovieParts(programs) {
let output = []
programs.forEach(prog => {
let prev = output[output.length - 1]
let found =
prev &&
prog.categories.includes('Movie') &&
prev.title === prog.title &&
prev.description === prog.description
if (found) {
prev.stop = prog.stop
} else {
output.push(prog)
}
})
return output
}
function getTitle(item) {
return item.title.length ? item.title[0].value : null
}
function getDescription(item) {
return item.desc.length ? item.desc[0].value : null
}
function getCategories(item) {
return item.category.map(c => c.value)
}
function parseItems(content, channel, date) {
try {
const curr_day = date
const next_day = date.add(1, 'd')
const [, site_id] = channel.site_id.split('#')
const data = parser.parse(content)
if (!data || !Array.isArray(data.programs)) return []
return data.programs.filter(
p =>
p.channel === site_id && dayjs(p.start, 'YYYYMMDDHHmmss ZZ').isBetween(curr_day, next_day)
)
} catch (error) {
return []
}
}