epg-grabber 0.28.3 → 0.28.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/Channel.js +6 -2
- package/src/Program.js +4 -4
- package/src/parser.js +12 -6
- package/src/xmltv.js +2 -1
- package/tests/Channel.test.js +21 -0
- package/tests/Program.test.js +101 -61
- package/tests/xmltv.test.js +1 -1
package/package.json
CHANGED
package/src/Channel.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
class Channel {
|
|
2
2
|
constructor(c) {
|
|
3
3
|
const data = {
|
|
4
|
-
id: c.xmltv_id,
|
|
4
|
+
id: c.id || c.xmltv_id,
|
|
5
5
|
name: c.name,
|
|
6
6
|
site: c.site || '',
|
|
7
7
|
site_id: c.site_id,
|
|
8
8
|
lang: c.lang || '',
|
|
9
9
|
logo: c.logo || '',
|
|
10
|
-
url: c.
|
|
10
|
+
url: c.url || toURL(c.site)
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
for (let key in data) {
|
|
@@ -17,3 +17,7 @@ class Channel {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
module.exports = Channel
|
|
20
|
+
|
|
21
|
+
function toURL(site) {
|
|
22
|
+
return site ? `https://${site}` : ''
|
|
23
|
+
}
|
package/src/Program.js
CHANGED
|
@@ -2,18 +2,18 @@ const { padStart } = require('lodash')
|
|
|
2
2
|
const { toArray, toUnix, parseNumber } = require('./utils')
|
|
3
3
|
|
|
4
4
|
class Program {
|
|
5
|
-
constructor(p
|
|
5
|
+
constructor(p) {
|
|
6
6
|
const data = {
|
|
7
|
-
channel:
|
|
7
|
+
channel: p.channel,
|
|
8
8
|
title: p.title,
|
|
9
9
|
sub_title: p.sub_title || '',
|
|
10
|
-
description: p.description
|
|
10
|
+
description: [p.description, p.desc, ''].find(i => i !== undefined),
|
|
11
11
|
icon: toIconObject(p.icon),
|
|
12
12
|
episodeNumbers: getEpisodeNumbers(p.season, p.episode),
|
|
13
13
|
date: p.date ? toUnix(p.date) : null,
|
|
14
14
|
start: toUnix(p.start),
|
|
15
15
|
stop: toUnix(p.stop),
|
|
16
|
-
urls: toArray(p.url).map(toUrlObject),
|
|
16
|
+
urls: toArray(p.urls || p.url).map(toUrlObject),
|
|
17
17
|
ratings: toArray(p.ratings || p.rating).map(toRatingObject),
|
|
18
18
|
categories: toArray(p.categories || p.category),
|
|
19
19
|
directors: toArray(p.directors || p.director).map(toPersonObject),
|
package/src/parser.js
CHANGED
|
@@ -18,12 +18,12 @@ function parseChannels(xml) {
|
|
|
18
18
|
const channels = channelsTag.elements
|
|
19
19
|
.filter(el => el.name === 'channel')
|
|
20
20
|
.map(el => {
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (!
|
|
21
|
+
const c = el.attributes
|
|
22
|
+
c.name = el.elements.find(el => el.type === 'text').text
|
|
23
|
+
c.site = c.site || rootSite
|
|
24
|
+
if (!c.name) throw new Error(`Channel '${c.xmltv_id}' has no valid name`)
|
|
25
25
|
|
|
26
|
-
return new Channel(
|
|
26
|
+
return new Channel(c)
|
|
27
27
|
})
|
|
28
28
|
|
|
29
29
|
return { site: rootSite, channels }
|
|
@@ -41,5 +41,11 @@ async function parsePrograms(data) {
|
|
|
41
41
|
throw new Error('Parser should return an array')
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
return programs
|
|
44
|
+
return programs
|
|
45
|
+
.filter(i => i)
|
|
46
|
+
.map(p => {
|
|
47
|
+
p.channel = p.channel || channel.id
|
|
48
|
+
|
|
49
|
+
return new Program(p)
|
|
50
|
+
})
|
|
45
51
|
}
|
package/src/xmltv.js
CHANGED
package/tests/Channel.test.js
CHANGED
|
@@ -20,3 +20,24 @@ it('can create new Channel', () => {
|
|
|
20
20
|
logo: 'https://example.com/logos/1TV.png'
|
|
21
21
|
})
|
|
22
22
|
})
|
|
23
|
+
|
|
24
|
+
it('can create channel from exist object', () => {
|
|
25
|
+
const channel = new Channel({
|
|
26
|
+
name: '1 TV',
|
|
27
|
+
id: '1TV.com',
|
|
28
|
+
site_id: '1',
|
|
29
|
+
site: 'example.com',
|
|
30
|
+
lang: 'fr',
|
|
31
|
+
logo: 'https://example.com/logos/1TV.png'
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
expect(channel).toMatchObject({
|
|
35
|
+
name: '1 TV',
|
|
36
|
+
id: '1TV.com',
|
|
37
|
+
site_id: '1',
|
|
38
|
+
site: 'example.com',
|
|
39
|
+
url: 'https://example.com',
|
|
40
|
+
lang: 'fr',
|
|
41
|
+
logo: 'https://example.com/logos/1TV.png'
|
|
42
|
+
})
|
|
43
|
+
})
|
package/tests/Program.test.js
CHANGED
|
@@ -4,50 +4,48 @@ import Program from '../src/Program'
|
|
|
4
4
|
const channel = new Channel({ xmltv_id: '1tv', lang: 'en' })
|
|
5
5
|
|
|
6
6
|
it('can create new Program', () => {
|
|
7
|
-
const program = new Program(
|
|
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
|
-
adapters: [
|
|
42
|
-
{
|
|
43
|
-
value: 'Adapter1',
|
|
44
|
-
url: ['http://imdb.com/p/adapter1', 'http://imdb.com/p/adapter2'],
|
|
45
|
-
image: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg']
|
|
46
|
-
}
|
|
47
|
-
]
|
|
7
|
+
const program = new Program({
|
|
8
|
+
channel: channel.id,
|
|
9
|
+
title: 'Title',
|
|
10
|
+
sub_title: 'Subtitle',
|
|
11
|
+
description: 'Description',
|
|
12
|
+
icon: 'https://example.com/image.jpg',
|
|
13
|
+
season: 9,
|
|
14
|
+
episode: 238,
|
|
15
|
+
date: '20220506',
|
|
16
|
+
start: 1616133600000,
|
|
17
|
+
stop: '2021-03-19T06:30:00.000Z',
|
|
18
|
+
url: 'http://example.com/title.html',
|
|
19
|
+
category: ['Category1', 'Category2'],
|
|
20
|
+
rating: {
|
|
21
|
+
system: 'MPAA',
|
|
22
|
+
value: 'PG',
|
|
23
|
+
icon: 'http://example.com/pg_symbol.png'
|
|
24
|
+
},
|
|
25
|
+
directors: 'Director1',
|
|
26
|
+
actors: [
|
|
27
|
+
'Actor1',
|
|
28
|
+
{ value: 'Actor2', url: 'http://actor2.com', image: 'http://actor2.com/image.png' }
|
|
29
|
+
],
|
|
30
|
+
writer: {
|
|
31
|
+
value: 'Writer1',
|
|
32
|
+
url: { system: 'imdb', value: 'http://imdb.com/p/writer1' },
|
|
33
|
+
image: {
|
|
34
|
+
value: 'https://example.com/image.jpg',
|
|
35
|
+
type: 'person',
|
|
36
|
+
size: '2',
|
|
37
|
+
system: 'TestSystem',
|
|
38
|
+
orient: 'P'
|
|
39
|
+
}
|
|
48
40
|
},
|
|
49
|
-
|
|
50
|
-
|
|
41
|
+
adapters: [
|
|
42
|
+
{
|
|
43
|
+
value: 'Adapter1',
|
|
44
|
+
url: ['http://imdb.com/p/adapter1', 'http://imdb.com/p/adapter2'],
|
|
45
|
+
image: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg']
|
|
46
|
+
}
|
|
47
|
+
]
|
|
48
|
+
})
|
|
51
49
|
|
|
52
50
|
expect(program).toMatchObject({
|
|
53
51
|
channel: '1tv',
|
|
@@ -131,16 +129,60 @@ it('can create new Program', () => {
|
|
|
131
129
|
})
|
|
132
130
|
})
|
|
133
131
|
|
|
134
|
-
it('can create program
|
|
135
|
-
const program = new Program(
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
132
|
+
it('can create program from exist object', () => {
|
|
133
|
+
const program = new Program({
|
|
134
|
+
channel: channel.id,
|
|
135
|
+
title: 'Program 1',
|
|
136
|
+
start: '2021-03-19T06:00:00.000Z',
|
|
137
|
+
stop: '2021-03-19T06:30:00.000Z',
|
|
138
|
+
ratings: {
|
|
139
|
+
system: 'MPAA',
|
|
140
|
+
value: 'PG',
|
|
141
|
+
icon: 'http://example.com/pg_symbol.png'
|
|
141
142
|
},
|
|
142
|
-
|
|
143
|
-
)
|
|
143
|
+
actors: [{ value: 'Actor1', url: [], image: [] }]
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
expect(program).toMatchObject({
|
|
147
|
+
channel: '1tv',
|
|
148
|
+
title: 'Program 1',
|
|
149
|
+
sub_title: '',
|
|
150
|
+
description: '',
|
|
151
|
+
urls: [],
|
|
152
|
+
categories: [],
|
|
153
|
+
icon: {},
|
|
154
|
+
episodeNumbers: [],
|
|
155
|
+
date: null,
|
|
156
|
+
start: 1616133600000,
|
|
157
|
+
stop: 1616135400000,
|
|
158
|
+
ratings: [
|
|
159
|
+
{
|
|
160
|
+
system: 'MPAA',
|
|
161
|
+
value: 'PG',
|
|
162
|
+
icon: 'http://example.com/pg_symbol.png'
|
|
163
|
+
}
|
|
164
|
+
],
|
|
165
|
+
directors: [],
|
|
166
|
+
actors: [{ value: 'Actor1', url: [], image: [] }],
|
|
167
|
+
writers: [],
|
|
168
|
+
adapters: [],
|
|
169
|
+
producers: [],
|
|
170
|
+
composers: [],
|
|
171
|
+
editors: [],
|
|
172
|
+
presenters: [],
|
|
173
|
+
commentators: [],
|
|
174
|
+
guests: []
|
|
175
|
+
})
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
it('can create program without season number', () => {
|
|
179
|
+
const program = new Program({
|
|
180
|
+
channel: channel.id,
|
|
181
|
+
title: 'Program 1',
|
|
182
|
+
start: '2021-03-19T06:00:00.000Z',
|
|
183
|
+
stop: '2021-03-19T06:30:00.000Z',
|
|
184
|
+
episode: 238
|
|
185
|
+
})
|
|
144
186
|
|
|
145
187
|
expect(program.episodeNumbers).toMatchObject([
|
|
146
188
|
{ system: 'xmltv_ns', value: '0.237.0/1' },
|
|
@@ -149,15 +191,13 @@ it('can create program without season number', () => {
|
|
|
149
191
|
})
|
|
150
192
|
|
|
151
193
|
it('can create program without episode number', () => {
|
|
152
|
-
const program = new Program(
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
channel
|
|
160
|
-
)
|
|
194
|
+
const program = new Program({
|
|
195
|
+
channel: channel.id,
|
|
196
|
+
title: 'Program 1',
|
|
197
|
+
start: '2021-03-19T06:00:00.000Z',
|
|
198
|
+
stop: '2021-03-19T06:30:00.000Z',
|
|
199
|
+
season: 3
|
|
200
|
+
})
|
|
161
201
|
|
|
162
202
|
expect(program.episodeNumbers).toMatchObject([])
|
|
163
203
|
})
|
package/tests/xmltv.test.js
CHANGED
|
@@ -66,6 +66,6 @@ fit('can generate xmltv', () => {
|
|
|
66
66
|
const output = xmltv.generate({ channels, programs })
|
|
67
67
|
|
|
68
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 & 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=шеллы&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
|
|
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 & 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=шеллы&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>\r\n</tv>'
|
|
70
70
|
)
|
|
71
71
|
})
|