epg-grabber 0.25.1 → 0.25.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/utils.js +13 -7
- package/tests/utils.test.js +80 -24
package/package.json
CHANGED
package/src/utils.js
CHANGED
|
@@ -220,13 +220,15 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|
|
220
220
|
output += '</tv>'
|
|
221
221
|
|
|
222
222
|
function createXMLTVNS(s, e) {
|
|
223
|
-
if (!
|
|
223
|
+
if (!e) return null
|
|
224
|
+
s = s || 1
|
|
224
225
|
|
|
225
226
|
return `${s - 1}.${e - 1}.0/1`
|
|
226
227
|
}
|
|
227
228
|
|
|
228
229
|
function createOnScreen(s, e) {
|
|
229
|
-
if (!
|
|
230
|
+
if (!e) return null
|
|
231
|
+
s = s || 1
|
|
230
232
|
|
|
231
233
|
s = padStart(s, 2, '0')
|
|
232
234
|
e = padStart(e, 2, '0')
|
|
@@ -316,11 +318,15 @@ utils.getUTCDate = function (d = null) {
|
|
|
316
318
|
}
|
|
317
319
|
|
|
318
320
|
utils.parseResponse = async (item, response, config) => {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
321
|
+
let buffer
|
|
322
|
+
let content
|
|
323
|
+
if (utils.isObject(response.data) || Array.isArray(response.data)) {
|
|
324
|
+
content = JSON.stringify(response.data)
|
|
325
|
+
buffer = Buffer.from(content, 'utf8')
|
|
326
|
+
} else {
|
|
327
|
+
content = response.data.toString()
|
|
328
|
+
buffer = response.data
|
|
329
|
+
}
|
|
324
330
|
const data = merge(item, config, {
|
|
325
331
|
content,
|
|
326
332
|
buffer,
|
package/tests/utils.test.js
CHANGED
|
@@ -73,6 +73,50 @@ it('can convert object to xmltv string', () => {
|
|
|
73
73
|
)
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
+
it('can convert object to xmltv string without season number', () => {
|
|
77
|
+
const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
|
|
78
|
+
const { channels } = utils.parseChannels(file)
|
|
79
|
+
const programs = [
|
|
80
|
+
{
|
|
81
|
+
title: 'Program 1',
|
|
82
|
+
description: 'Description for Program 1',
|
|
83
|
+
start: 1616133600,
|
|
84
|
+
stop: 1616135400,
|
|
85
|
+
category: 'Test',
|
|
86
|
+
episode: 239,
|
|
87
|
+
icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
|
|
88
|
+
channel: '1TV.com',
|
|
89
|
+
lang: 'it'
|
|
90
|
+
}
|
|
91
|
+
]
|
|
92
|
+
const output = utils.convertToXMLTV({ channels, programs })
|
|
93
|
+
expect(output).toBe(
|
|
94
|
+
'<?xml version="1.0" encoding="UTF-8" ?><tv>\r\n<channel id="1TV.com"><display-name>1 TV</display-name><icon src="https://example.com/logos/1TV.png"/><url>https://example.com</url></channel>\r\n<channel id="2TV.com"><display-name>2 TV</display-name><url>https://example.com</url></channel>\r\n<programme start="20210319060000 +0000" stop="20210319063000 +0000" channel="1TV.com"><title lang="it">Program 1</title><desc lang="it">Description for Program 1</desc><category lang="it">Test</category><episode-num system="xmltv_ns">0.238.0/1</episode-num><episode-num system="onscreen">S01E239</episode-num><icon src="https://example.com/images/Program1.png?x=шеллы&sid=777"/></programme>\r\n</tv>'
|
|
95
|
+
)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('can convert object to xmltv string without episode number', () => {
|
|
99
|
+
const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
|
|
100
|
+
const { channels } = utils.parseChannels(file)
|
|
101
|
+
const programs = [
|
|
102
|
+
{
|
|
103
|
+
title: 'Program 1',
|
|
104
|
+
description: 'Description for Program 1',
|
|
105
|
+
start: 1616133600,
|
|
106
|
+
stop: 1616135400,
|
|
107
|
+
category: 'Test',
|
|
108
|
+
season: 1,
|
|
109
|
+
icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
|
|
110
|
+
channel: '1TV.com',
|
|
111
|
+
lang: 'it'
|
|
112
|
+
}
|
|
113
|
+
]
|
|
114
|
+
const output = utils.convertToXMLTV({ channels, programs })
|
|
115
|
+
expect(output).toBe(
|
|
116
|
+
'<?xml version="1.0" encoding="UTF-8" ?><tv>\r\n<channel id="1TV.com"><display-name>1 TV</display-name><icon src="https://example.com/logos/1TV.png"/><url>https://example.com</url></channel>\r\n<channel id="2TV.com"><display-name>2 TV</display-name><url>https://example.com</url></channel>\r\n<programme start="20210319060000 +0000" stop="20210319063000 +0000" channel="1TV.com"><title lang="it">Program 1</title><desc lang="it">Description for Program 1</desc><category lang="it">Test</category><icon src="https://example.com/images/Program1.png?x=шеллы&sid=777"/></programme>\r\n</tv>'
|
|
117
|
+
)
|
|
118
|
+
})
|
|
119
|
+
|
|
76
120
|
it('can convert object to xmltv string without categories', () => {
|
|
77
121
|
const channels = [
|
|
78
122
|
{
|
|
@@ -149,7 +193,7 @@ it('can fetch data', () => {
|
|
|
149
193
|
url: 'http://example.com/20210319/1tv.json',
|
|
150
194
|
withCredentials: true
|
|
151
195
|
}
|
|
152
|
-
utils.fetchData(
|
|
196
|
+
utils.fetchData(mockAxios, request).then(jest.fn).catch(jest.fn)
|
|
153
197
|
expect(mockAxios).toHaveBeenCalledWith(
|
|
154
198
|
expect.objectContaining({
|
|
155
199
|
data: { accountID: '123' },
|
|
@@ -170,37 +214,46 @@ it('can fetch data', () => {
|
|
|
170
214
|
|
|
171
215
|
it('can build request async', done => {
|
|
172
216
|
const config = utils.loadConfig(require(path.resolve('./tests/input/async.config.js')))
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
'
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
217
|
+
|
|
218
|
+
utils
|
|
219
|
+
.buildRequest({}, config)
|
|
220
|
+
.then(request => {
|
|
221
|
+
expect(request).toMatchObject({
|
|
222
|
+
data: { accountID: '123' },
|
|
223
|
+
headers: {
|
|
224
|
+
'Content-Type': 'application/json',
|
|
225
|
+
Cookie: 'abc=123',
|
|
226
|
+
'User-Agent':
|
|
227
|
+
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36 Edg/79.0.309.71'
|
|
228
|
+
},
|
|
229
|
+
maxContentLength: 5242880,
|
|
230
|
+
method: 'POST',
|
|
231
|
+
responseType: 'arraybuffer',
|
|
232
|
+
timeout: 5000,
|
|
233
|
+
url: 'http://example.com/20210319/1tv.json',
|
|
234
|
+
withCredentials: true
|
|
235
|
+
})
|
|
236
|
+
done()
|
|
188
237
|
})
|
|
189
|
-
done
|
|
190
|
-
})
|
|
238
|
+
.catch(done)
|
|
191
239
|
})
|
|
192
240
|
|
|
193
241
|
it('can load logo async', done => {
|
|
194
242
|
const config = utils.loadConfig(require(path.resolve('./tests/input/async.config.js')))
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
243
|
+
|
|
244
|
+
utils
|
|
245
|
+
.loadLogo({}, config)
|
|
246
|
+
.then(logo => {
|
|
247
|
+
expect(logo).toBe('http://example.com/logos/1TV.png?x=шеллы&sid=777')
|
|
248
|
+
done()
|
|
249
|
+
})
|
|
250
|
+
.catch(done)
|
|
199
251
|
})
|
|
200
252
|
|
|
201
253
|
it('can parse programs', done => {
|
|
202
254
|
const config = utils.loadConfig(require(path.resolve('./tests/input/example.com.config.js')))
|
|
203
|
-
|
|
255
|
+
|
|
256
|
+
utils
|
|
204
257
|
.parsePrograms({ channel: { xmltv_id: '1tv', lang: 'en' } }, config)
|
|
205
258
|
.then(programs => {
|
|
206
259
|
expect(programs).toMatchObject([
|
|
@@ -218,14 +271,17 @@ it('can parse programs', done => {
|
|
|
218
271
|
])
|
|
219
272
|
done()
|
|
220
273
|
})
|
|
274
|
+
.catch(done)
|
|
221
275
|
})
|
|
222
276
|
|
|
223
277
|
it('can parse programs async', done => {
|
|
224
278
|
const config = utils.loadConfig(require(path.resolve('./tests/input/async.config.js')))
|
|
225
|
-
|
|
279
|
+
|
|
280
|
+
utils
|
|
226
281
|
.parsePrograms({ channel: { xmltv_id: '1tv', lang: 'en' } }, config)
|
|
227
282
|
.then(programs => {
|
|
228
283
|
expect(programs.length).toBe(0)
|
|
229
284
|
done()
|
|
230
285
|
})
|
|
286
|
+
.catch(done)
|
|
231
287
|
})
|