epg-grabber 0.29.3 → 0.29.5
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/Program.js +2 -2
- package/src/xmltv.js +111 -111
- package/tests/xmltv.test.js +2 -2
package/package.json
CHANGED
package/src/Program.js
CHANGED
|
@@ -9,8 +9,8 @@ class Program {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
const data = {
|
|
12
|
-
site:
|
|
13
|
-
channel:
|
|
12
|
+
site: c.site || '',
|
|
13
|
+
channel: c.id || '',
|
|
14
14
|
titles: toArray(p.titles || p.title).map(text => toTextObject(text, c.lang)),
|
|
15
15
|
sub_titles: toArray(p.sub_titles || p.sub_title).map(text => toTextObject(text, c.lang)),
|
|
16
16
|
descriptions: toArray(p.descriptions || p.description || p.desc).map(text =>
|
package/src/xmltv.js
CHANGED
|
@@ -6,142 +6,142 @@ const el = createElement
|
|
|
6
6
|
module.exports.generate = generate
|
|
7
7
|
|
|
8
8
|
function generate({ channels, programs, date = getUTCDate() }) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (!channels.every(c => c instanceof Channel)) {
|
|
10
|
+
throw new Error('"channels" must be an array of Channels')
|
|
11
|
+
}
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (!programs.every(p => p instanceof Program)) {
|
|
14
|
+
throw new Error('"programs" must be an array of Programs')
|
|
15
|
+
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
if (!isDate(date)) {
|
|
18
|
+
throw new Error('"date" must be a valid date')
|
|
19
|
+
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
let output = `<?xml version="1.0" encoding="UTF-8" ?>`
|
|
22
|
+
output += createElements(channels, programs, date)
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
return output
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
function createElements(channels, programs, date) {
|
|
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
|
-
|
|
28
|
+
return el('tv', { date: formatDate(date, 'YYYYMMDD') }, [
|
|
29
|
+
...channels.map(channel => {
|
|
30
|
+
return (
|
|
31
|
+
'\r\n' +
|
|
32
|
+
el('channel', { id: channel.id }, [
|
|
33
|
+
el('display-name', {}, [escapeString(channel.name)]),
|
|
34
|
+
el('icon', { src: channel.logo }),
|
|
35
|
+
el('url', {}, [channel.url])
|
|
36
|
+
])
|
|
37
|
+
)
|
|
38
|
+
}),
|
|
39
|
+
...programs.map(program => {
|
|
40
|
+
return (
|
|
41
|
+
'\r\n' +
|
|
42
|
+
el(
|
|
43
|
+
'programme',
|
|
44
|
+
{
|
|
45
|
+
start: formatDate(program.start, 'YYYYMMDDHHmmss ZZ'),
|
|
46
|
+
stop: formatDate(program.stop, 'YYYYMMDDHHmmss ZZ'),
|
|
47
|
+
channel: program.channel
|
|
48
|
+
},
|
|
49
|
+
[
|
|
50
|
+
...program.titles.map(title =>
|
|
51
|
+
el('title', { lang: title.lang }, [escapeString(title.value)])
|
|
52
|
+
),
|
|
53
|
+
...program.sub_titles.map(sub_title =>
|
|
54
|
+
el('sub-title', { lang: sub_title.lang }, [escapeString(sub_title.value)])
|
|
55
|
+
),
|
|
56
|
+
...program.descriptions.map(desc =>
|
|
57
|
+
el('desc', { lang: desc.lang }, [escapeString(desc.value)])
|
|
58
|
+
),
|
|
59
|
+
el('credits', {}, [
|
|
60
|
+
...program.directors.map(data => createCastMember('director', data)),
|
|
61
|
+
...program.actors.map(data => createCastMember('actor', data)),
|
|
62
|
+
...program.writers.map(data => createCastMember('writer', data)),
|
|
63
|
+
...program.adapters.map(data => createCastMember('adapter', data)),
|
|
64
|
+
...program.producers.map(data => createCastMember('producer', data)),
|
|
65
|
+
...program.composers.map(data => createCastMember('composer', data)),
|
|
66
|
+
...program.editors.map(data => createCastMember('editor', data)),
|
|
67
|
+
...program.presenters.map(data => createCastMember('presenter', data)),
|
|
68
|
+
...program.commentators.map(data => createCastMember('commentator', data)),
|
|
69
|
+
...program.guests.map(data => createCastMember('guest', data))
|
|
70
|
+
]),
|
|
71
|
+
el('date', {}, [formatDate(program.date, 'YYYYMMDD')]),
|
|
72
|
+
...program.categories.map(category =>
|
|
73
|
+
el('category', { lang: category.lang }, [escapeString(category.value)])
|
|
74
|
+
),
|
|
75
|
+
el('icon', { src: program.icon.src }),
|
|
76
|
+
...program.urls.map(createURL),
|
|
77
|
+
...program.episodeNumbers.map(episode =>
|
|
78
|
+
el('episode-num', { system: episode.system }, [episode.value])
|
|
79
|
+
),
|
|
80
|
+
...program.ratings.map(rating =>
|
|
81
|
+
el('rating', { system: rating.system }, [
|
|
82
|
+
el('value', {}, [escapeString(rating.value)]),
|
|
83
|
+
el('icon', { src: rating.icon })
|
|
84
|
+
])
|
|
85
|
+
)
|
|
86
|
+
]
|
|
87
|
+
)
|
|
88
|
+
)
|
|
89
|
+
}),
|
|
90
|
+
'\r\n'
|
|
91
|
+
])
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
function createCastMember(position, data) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
95
|
+
return el(position, {}, [
|
|
96
|
+
escapeString(data.value),
|
|
97
|
+
...data.url.map(createURL),
|
|
98
|
+
...data.image.map(createImage)
|
|
99
|
+
])
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
function createImage(image) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
103
|
+
return el(
|
|
104
|
+
'image',
|
|
105
|
+
{
|
|
106
|
+
type: image.type,
|
|
107
|
+
size: image.size,
|
|
108
|
+
orient: image.orient,
|
|
109
|
+
system: image.system
|
|
110
|
+
},
|
|
111
|
+
[image.value]
|
|
112
|
+
)
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
function createURL(url) {
|
|
116
|
-
|
|
116
|
+
return el('url', { system: url.system }, [url.value])
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
function createElement(name, attrs = {}, children = []) {
|
|
120
|
-
|
|
120
|
+
return toString({ name, attrs, children })
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
function toString(elem) {
|
|
124
|
-
|
|
124
|
+
if (typeof elem === 'string' || typeof elem === 'number') return elem
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
126
|
+
let attrs = ''
|
|
127
|
+
for (let key in elem.attrs) {
|
|
128
|
+
let value = elem.attrs[key]
|
|
129
|
+
if (value) {
|
|
130
|
+
attrs += ` ${key}="${escapeString(value)}"`
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
134
|
+
if (elem.children.filter(Boolean).length) {
|
|
135
|
+
let children = ''
|
|
136
|
+
elem.children.forEach(childElem => {
|
|
137
|
+
children += toString(childElem)
|
|
138
|
+
})
|
|
139
139
|
|
|
140
|
-
|
|
141
|
-
|
|
140
|
+
return `<${elem.name}${attrs}>${children}</${elem.name}>`
|
|
141
|
+
}
|
|
142
142
|
|
|
143
|
-
|
|
144
|
-
|
|
143
|
+
if (!attrs) return ''
|
|
144
|
+
if (!['icon'].includes(elem.name)) return ''
|
|
145
145
|
|
|
146
|
-
|
|
146
|
+
return `<${elem.name}${attrs}/>`
|
|
147
147
|
}
|
package/tests/xmltv.test.js
CHANGED
|
@@ -36,7 +36,7 @@ it('can generate xmltv', () => {
|
|
|
36
36
|
icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
|
|
37
37
|
rating: {
|
|
38
38
|
system: 'MPAA',
|
|
39
|
-
value: '
|
|
39
|
+
value: 'P&G',
|
|
40
40
|
icon: 'http://example.com/pg_symbol.png'
|
|
41
41
|
},
|
|
42
42
|
director: [
|
|
@@ -74,6 +74,6 @@ it('can generate xmltv', () => {
|
|
|
74
74
|
const output = xmltv.generate({ channels, programs })
|
|
75
75
|
|
|
76
76
|
expect(output).toBe(
|
|
77
|
-
'<?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>
|
|
77
|
+
'<?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>P&G</value><icon src="http://example.com/pg_symbol.png"/></rating></programme>\r\n<programme start="20210319060000 +0000" stop="20210319063000 +0000" channel="2TV.co"><title lang="es">Program 2</title></programme>\r\n</tv>'
|
|
78
78
|
)
|
|
79
79
|
})
|