epg-grabber 0.27.2 → 0.28.2

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.
@@ -1,401 +1,11 @@
1
- import mockAxios from 'jest-mock-axios'
2
- import utils from '../src/utils'
3
- import axios from 'axios'
4
- import path from 'path'
5
- import fs from 'fs'
6
-
7
- jest.useFakeTimers('modern').setSystemTime(new Date('2022-05-05'))
8
-
9
- it('can load valid config.js', () => {
10
- const config = utils.loadConfig(require(path.resolve('./tests/input/example.com.config.js')))
11
- expect(config).toMatchObject({
12
- days: 1,
13
- delay: 3000,
14
- lang: 'en',
15
- site: 'example.com'
16
- })
17
- expect(config.request).toMatchObject({
18
- timeout: 5000,
19
- headers: {
20
- 'Content-Type': 'application/json',
21
- Cookie: 'abc=123'
22
- }
23
- })
24
- expect(typeof config.request.data).toEqual('function')
25
- expect(typeof config.url).toEqual('function')
26
- expect(typeof config.logo).toEqual('function')
27
- expect(config.request.data()).toEqual({ accountID: '123' })
28
- expect(config.url()).toEqual('http://example.com/20210319/1tv.json')
29
- expect(config.logo()).toEqual('http://example.com/logos/1TV.png?x=шеллы&sid=777')
30
- })
31
-
32
- it('can parse valid channels.xml', () => {
33
- const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
34
- const { channels } = utils.parseChannels(file)
35
- expect(channels).toEqual([
36
- {
37
- name: '1 TV',
38
- xmltv_id: '1TV.com',
39
- site_id: '1',
40
- site: 'example.com',
41
- lang: 'fr',
42
- logo: 'https://example.com/logos/1TV.png'
43
- },
44
- {
45
- name: '2 TV',
46
- xmltv_id: '2TV.com',
47
- site_id: '2',
48
- site: 'example.com',
49
- lang: undefined,
50
- logo: undefined
51
- }
52
- ])
53
- })
54
-
55
- it('can convert object to xmltv string', () => {
56
- const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
57
- const { channels } = utils.parseChannels(file)
58
- const programs = [
59
- {
60
- title: 'Program 1',
61
- sub_title: 'Sub-title & 1',
62
- description: 'Description for Program 1',
63
- url: 'http://example.com/title.html',
64
- start: 1616133600,
65
- stop: 1616135400,
66
- category: 'Test',
67
- season: 9,
68
- episode: 239,
69
- icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
70
- channel: '1TV.com',
71
- lang: 'it',
72
- date: '20220505',
73
- director: {
74
- value: 'Director 1',
75
- url: { value: 'http://example.com/director1.html', system: 'TestSystem' }
76
- },
77
- actor: ['Actor 1', 'Actor 2'],
78
- writer: 'Writer 1'
79
- }
80
- ]
81
- const output = utils.convertToXMLTV({ channels, programs })
82
- expect(output).toBe(
83
- '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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><sub-title>Sub-title &amp; 1</sub-title><desc lang="it">Description for Program 1</desc><category lang="it">Test</category><url>http://example.com/title.html</url><episode-num system="xmltv_ns">8.238.0/1</episode-num><episode-num system="onscreen">S09E239</episode-num><date>20220505</date><icon src="https://example.com/images/Program1.png?x=шеллы&amp;sid=777"/><credits><director>Director 1<url system="TestSystem">http://example.com/director1.html</url></director><actor>Actor 1</actor><actor>Actor 2</actor><writer>Writer 1</writer></credits></programme>\r\n</tv>'
84
- )
85
- })
86
-
87
- it('can convert object to xmltv string without season number', () => {
88
- const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
89
- const { channels } = utils.parseChannels(file)
90
- const programs = [
91
- {
92
- title: 'Program 1',
93
- description: 'Description for Program 1',
94
- start: 1616133600,
95
- stop: 1616135400,
96
- category: 'Test',
97
- episode: 239,
98
- icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
99
- channel: '1TV.com',
100
- lang: 'it'
101
- }
102
- ]
103
- const output = utils.convertToXMLTV({ channels, programs })
104
- expect(output).toBe(
105
- '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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=шеллы&amp;sid=777"/></programme>\r\n</tv>'
106
- )
107
- })
108
-
109
- it('can convert object to xmltv string without episode number', () => {
110
- const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
111
- const { channels } = utils.parseChannels(file)
112
- const programs = [
113
- {
114
- title: 'Program 1',
115
- description: 'Description for Program 1',
116
- start: 1616133600,
117
- stop: 1616135400,
118
- category: 'Test',
119
- season: 1,
120
- icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
121
- channel: '1TV.com',
122
- lang: 'it'
123
- }
124
- ]
125
- const output = utils.convertToXMLTV({ channels, programs })
126
- expect(output).toBe(
127
- '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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=шеллы&amp;sid=777"/></programme>\r\n</tv>'
128
- )
129
- })
130
-
131
- it('can convert object to xmltv string without categories', () => {
132
- const channels = [
133
- {
134
- name: '1 TV',
135
- xmltv_id: '1TV.com',
136
- site_id: '1',
137
- site: 'example.com',
138
- lang: 'fr',
139
- logo: 'https://example.com/logos/1TV.png'
140
- }
141
- ]
142
- const programs = [
143
- {
144
- title: 'Program 1',
145
- start: 1616133600,
146
- stop: 1616135400,
147
- channel: '1TV.com',
148
- lang: 'it'
149
- }
150
- ]
151
- const config = { site: 'example.com' }
152
- const output = utils.convertToXMLTV({ config, channels, programs })
153
- expect(output).toBe(
154
- '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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<programme start="20210319060000 +0000" stop="20210319063000 +0000" channel="1TV.com"><title lang="it">Program 1</title></programme>\r\n</tv>'
155
- )
156
- })
157
-
158
- it('can convert object to xmltv string with multiple categories', () => {
159
- const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
160
- const { channels } = utils.parseChannels(file)
161
- const programs = [
162
- {
163
- title: 'Program 1',
164
- description: 'Description for Program 1',
165
- start: 1616133600,
166
- stop: 1616135400,
167
- category: ['Test1', 'Test2'],
168
- icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
169
- channel: '1TV.com',
170
- lang: 'it'
171
- }
172
- ]
173
- const output = utils.convertToXMLTV({ channels, programs })
174
- expect(output).toBe(
175
- '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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">Test1</category><category lang="it">Test2</category><icon src="https://example.com/images/Program1.png?x=шеллы&amp;sid=777"/></programme>\r\n</tv>'
176
- )
177
- })
178
-
179
- it('can convert object to xmltv string with multiple urls', () => {
180
- const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
181
- const { channels } = utils.parseChannels(file)
182
- const programs = [
183
- {
184
- title: 'Program 1',
185
- description: 'Description for Program 1',
186
- start: 1616133600,
187
- stop: 1616135400,
188
- category: ['Test1', 'Test2'],
189
- url: [
190
- 'https://example.com/noattr.html',
191
- { value: 'https://example.com/attr.html', system: 'TestSystem' }
192
- ],
193
- icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
194
- channel: '1TV.com',
195
- lang: 'it'
196
- }
197
- ]
198
- const output = utils.convertToXMLTV({ channels, programs })
199
- expect(output).toBe(
200
- '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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">Test1</category><category lang="it">Test2</category><url>https://example.com/noattr.html</url><url system="TestSystem">https://example.com/attr.html</url><icon src="https://example.com/images/Program1.png?x=шеллы&amp;sid=777"/></programme>\r\n</tv>'
201
- )
202
- })
203
-
204
- it('can convert object to xmltv string with multiple images', () => {
205
- const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
206
- const { channels } = utils.parseChannels(file)
207
- const programs = [
208
- {
209
- title: 'Program 1',
210
- description: 'Description for Program 1',
211
- start: 1616133600,
212
- stop: 1616135400,
213
- category: ['Test1', 'Test2'],
214
- url: [
215
- 'https://example.com/noattr.html',
216
- { value: 'https://example.com/attr.html', system: 'TestSystem' }
217
- ],
218
- actor: {
219
- value: 'Actor 1',
220
- image: [
221
- 'https://example.com/image1.jpg',
222
- {
223
- value: 'https://example.com/image2.jpg',
224
- type: 'person',
225
- size: '2',
226
- system: 'TestSystem',
227
- orient: 'P'
228
- }
229
- ]
230
- },
231
- icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
232
- channel: '1TV.com',
233
- lang: 'it'
234
- }
235
- ]
236
- const output = utils.convertToXMLTV({ channels, programs })
237
- expect(output).toBe(
238
- '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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">Test1</category><category lang="it">Test2</category><url>https://example.com/noattr.html</url><url system="TestSystem">https://example.com/attr.html</url><icon src="https://example.com/images/Program1.png?x=шеллы&amp;sid=777"/><credits><actor>Actor 1<image>https://example.com/image1.jpg</image><image type="person" size="2" orient="P" system="TestSystem">https://example.com/image2.jpg</image></actor></credits></programme>\r\n</tv>'
239
- )
240
- })
241
-
242
- it('can convert object to xmltv string with multiple credits member', () => {
243
- const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
244
- const { channels } = utils.parseChannels(file)
245
- const programs = [
246
- {
247
- title: 'Program 1',
248
- sub_title: 'Sub-title 1',
249
- description: 'Description for Program 1',
250
- url: 'http://example.com/title.html',
251
- start: 1616133600,
252
- stop: 1616135400,
253
- category: 'Test',
254
- season: 9,
255
- episode: 239,
256
- icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
257
- channel: '1TV.com',
258
- lang: 'it',
259
- date: '20220505',
260
- director: {
261
- value: 'Director 1',
262
- url: { value: 'http://example.com/director1.html', system: 'TestSystem' }
263
- },
264
- actor: {
265
- value: 'Actor 1',
266
- role: 'Manny',
267
- guest: 'yes',
268
- url: { value: 'http://example.com/actor1.html', system: 'TestSystem' }
269
- },
270
- writer: [
271
- { value: 'Writer 1', url: { value: 'http://example.com/w1.html', system: 'TestSystem' } },
272
- { value: 'Writer 2', url: { value: 'http://example.com/w2.html', system: 'TestSystem' } }
273
- ]
274
- }
275
- ]
276
- const output = utils.convertToXMLTV({ channels, programs })
277
- expect(output).toBe(
278
- '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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><sub-title>Sub-title 1</sub-title><desc lang="it">Description for Program 1</desc><category lang="it">Test</category><url>http://example.com/title.html</url><episode-num system="xmltv_ns">8.238.0/1</episode-num><episode-num system="onscreen">S09E239</episode-num><date>20220505</date><icon src="https://example.com/images/Program1.png?x=шеллы&amp;sid=777"/><credits><director>Director 1<url system="TestSystem">http://example.com/director1.html</url></director><actor role="Manny" guest="yes">Actor 1<url system="TestSystem">http://example.com/actor1.html</url></actor><writer>Writer 1<url system="TestSystem">http://example.com/w1.html</url></writer><writer>Writer 2<url system="TestSystem">http://example.com/w2.html</url></writer></credits></programme>\r\n</tv>'
279
- )
280
- })
1
+ import { escapeString } from '../src/utils'
281
2
 
282
3
  it('can escape string', () => {
283
4
  const string = 'Música тест dun. &<>"\'\r\n'
284
- expect(utils.escapeString(string)).toBe('Música тест dun. &amp;&lt;&gt;&quot;&apos;')
5
+ expect(escapeString(string)).toBe('Música тест dun. &amp;&lt;&gt;&quot;&apos;')
285
6
  })
286
7
 
287
8
  it('can escape url', () => {
288
9
  const string = 'http://example.com/logos/1TV.png?param1=val&param2=val'
289
- expect(utils.escapeString(string)).toBe(
290
- 'http://example.com/logos/1TV.png?param1=val&amp;param2=val'
291
- )
292
- })
293
-
294
- it('can fetch data', () => {
295
- const request = {
296
- data: { accountID: '123' },
297
- headers: {
298
- 'Content-Type': 'application/json',
299
- Cookie: 'abc=123',
300
- 'User-Agent':
301
- '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'
302
- },
303
- maxContentLength: 5242880,
304
- method: 'POST',
305
- responseType: 'arraybuffer',
306
- timeout: 5000,
307
- url: 'http://example.com/20210319/1tv.json',
308
- withCredentials: true
309
- }
310
- utils.fetchData(mockAxios, request).then(jest.fn).catch(jest.fn)
311
- expect(mockAxios).toHaveBeenCalledWith(
312
- expect.objectContaining({
313
- data: { accountID: '123' },
314
- headers: {
315
- 'Content-Type': 'application/json',
316
- Cookie: 'abc=123',
317
- 'User-Agent':
318
- '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'
319
- },
320
- method: 'POST',
321
- responseType: 'arraybuffer',
322
- timeout: 5000,
323
- url: 'http://example.com/20210319/1tv.json',
324
- withCredentials: true
325
- })
326
- )
327
- })
328
-
329
- it('can build request async', done => {
330
- const config = utils.loadConfig(require(path.resolve('./tests/input/async.config.js')))
331
-
332
- utils
333
- .buildRequest({}, config)
334
- .then(request => {
335
- expect(request).toMatchObject({
336
- data: { accountID: '123' },
337
- headers: {
338
- 'Content-Type': 'application/json',
339
- Cookie: 'abc=123',
340
- 'User-Agent':
341
- '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'
342
- },
343
- maxContentLength: 5242880,
344
- method: 'POST',
345
- responseType: 'arraybuffer',
346
- timeout: 5000,
347
- url: 'http://example.com/20210319/1tv.json',
348
- withCredentials: true
349
- })
350
- done()
351
- })
352
- .catch(done)
353
- })
354
-
355
- it('can load logo async', done => {
356
- const config = utils.loadConfig(require(path.resolve('./tests/input/async.config.js')))
357
-
358
- utils
359
- .loadLogo({}, config)
360
- .then(logo => {
361
- expect(logo).toBe('http://example.com/logos/1TV.png?x=шеллы&sid=777')
362
- done()
363
- })
364
- .catch(done)
365
- })
366
-
367
- it('can parse programs', done => {
368
- const config = utils.loadConfig(require(path.resolve('./tests/input/example.com.config.js')))
369
-
370
- utils
371
- .parsePrograms({ channel: { xmltv_id: '1tv', lang: 'en' } }, config)
372
- .then(programs => {
373
- expect(programs).toMatchObject([
374
- {
375
- title: 'Title',
376
- description: 'Description',
377
- lang: 'en',
378
- category: ['Category1', 'Category2'],
379
- icon: 'https://example.com/image.jpg',
380
- season: 9,
381
- episode: 238,
382
- start: 1640995200,
383
- stop: 1640998800
384
- }
385
- ])
386
- done()
387
- })
388
- .catch(done)
389
- })
390
-
391
- it('can parse programs async', done => {
392
- const config = utils.loadConfig(require(path.resolve('./tests/input/async.config.js')))
393
-
394
- utils
395
- .parsePrograms({ channel: { xmltv_id: '1tv', lang: 'en' } }, config)
396
- .then(programs => {
397
- expect(programs.length).toBe(0)
398
- done()
399
- })
400
- .catch(done)
10
+ expect(escapeString(string)).toBe('http://example.com/logos/1TV.png?param1=val&amp;param2=val')
401
11
  })
@@ -0,0 +1,71 @@
1
+ import Channel from '../src/Channel'
2
+ import Program from '../src/Program'
3
+ import xmltv from '../src/xmltv'
4
+
5
+ jest.useFakeTimers('modern').setSystemTime(new Date('2022-05-05'))
6
+
7
+ const channels = [
8
+ new Channel({
9
+ xmltv_id: '1TV.co',
10
+ name: '1 TV',
11
+ logo: 'https://example.com/logos/1TV.png',
12
+ site: 'example.com'
13
+ }),
14
+ new Channel({
15
+ xmltv_id: '2TV.co',
16
+ name: '2 TV',
17
+ site: 'example.com'
18
+ })
19
+ ]
20
+
21
+ fit('can generate xmltv', () => {
22
+ const programs = [
23
+ new Program(
24
+ {
25
+ title: 'Program 1',
26
+ sub_title: 'Sub-title & 1',
27
+ description: 'Description for Program 1',
28
+ url: 'http://example.com/title.html',
29
+ start: '2021-03-19T06:00:00.000Z',
30
+ stop: '2021-03-19T06:30:00.000Z',
31
+ category: 'Test',
32
+ date: '2022-05-06',
33
+ season: 9,
34
+ episode: 239,
35
+ icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
36
+ channel: '1TV.co',
37
+ rating: {
38
+ system: 'MPAA',
39
+ value: 'PG',
40
+ icon: 'http://example.com/pg_symbol.png'
41
+ },
42
+ director: [
43
+ {
44
+ value: 'Director 1',
45
+ url: { value: 'http://example.com/director1.html', system: 'TestSystem' },
46
+ image: [
47
+ 'https://example.com/image1.jpg',
48
+ {
49
+ value: 'https://example.com/image2.jpg',
50
+ type: 'person',
51
+ size: '2',
52
+ system: 'TestSystem',
53
+ orient: 'P'
54
+ }
55
+ ]
56
+ },
57
+ 'Director 2'
58
+ ],
59
+ actor: ['Actor 1', 'Actor 2'],
60
+ writer: 'Writer 1'
61
+ },
62
+ channels[0]
63
+ )
64
+ ]
65
+
66
+ const output = xmltv.generate({ channels, programs })
67
+
68
+ expect(output).toBe(
69
+ '<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\r\n<channel id="1TV.co"><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.co"><display-name>2 TV</display-name><url>https://example.com</url></channel>\r\n<programme start="20210319060000 +0000" stop="20210319063000 +0000" channel="1TV.co"><title>Program 1</title><sub-title>Sub-title &amp; 1</sub-title><desc>Description for Program 1</desc><credits><director>Director 1<url system="TestSystem">http://example.com/director1.html</url><image>https://example.com/image1.jpg</image><image type="person" size="2" orient="P" system="TestSystem">https://example.com/image2.jpg</image></director><director>Director 2</director><actor>Actor 1</actor><actor>Actor 2</actor><writer>Writer 1</writer></credits><date>20220506</date><category>Test</category><icon src="https://example.com/images/Program1.png?x=шеллы&amp;sid=777"/><url>http://example.com/title.html</url><episode-num system="xmltv_ns">8.238.0/1</episode-num><episode-num system="onscreen">S09E239</episode-num><rating system="MPAA"><value>PG</value><icon src="http://example.com/pg_symbol.png"/></rating></programme></tv>'
70
+ )
71
+ })