epg-grabber 0.15.2 → 0.18.0
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/README.md +8 -6
- package/bin/epg-grabber.js +1 -1
- package/package.json +2 -2
- package/src/utils.js +29 -1
- package/tests/bin.test.js +3 -6
- package/tests/input/example.com.config.js +20 -1
- package/tests/utils.test.js +25 -1
package/README.md
CHANGED
|
@@ -158,12 +158,14 @@ module.exports = {
|
|
|
158
158
|
return [
|
|
159
159
|
{
|
|
160
160
|
title, // program title (required)
|
|
161
|
-
start, //
|
|
162
|
-
stop, //
|
|
163
|
-
description, // program
|
|
164
|
-
category, // program
|
|
165
|
-
|
|
166
|
-
|
|
161
|
+
start, // start time of the program (required)
|
|
162
|
+
stop, // end time of the program (required)
|
|
163
|
+
description, // description of the program (optional)
|
|
164
|
+
category, // program type (optional)
|
|
165
|
+
season, // season number (optional)
|
|
166
|
+
episode, // episode number (optional)
|
|
167
|
+
icon, // image associated with the program (optional)
|
|
168
|
+
lang // language of the description (default: 'en')
|
|
167
169
|
},
|
|
168
170
|
...
|
|
169
171
|
]
|
package/bin/epg-grabber.js
CHANGED
|
@@ -7,7 +7,7 @@ const path = require('path')
|
|
|
7
7
|
const grabber = require('../src/index')
|
|
8
8
|
const utils = require('../src/utils')
|
|
9
9
|
const { name, version, description } = require('../package.json')
|
|
10
|
-
const merge = require('lodash
|
|
10
|
+
const { merge } = require('lodash')
|
|
11
11
|
const { createLogger, format, transports } = require('winston')
|
|
12
12
|
const { combine, timestamp, printf } = format
|
|
13
13
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epg-grabber",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.18.0",
|
|
4
4
|
"description": "Node.js CLI tool for grabbing EPG from different sites",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"preferGlobal": true,
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"commander": "^7.1.0",
|
|
35
35
|
"dayjs": "^1.10.4",
|
|
36
36
|
"glob": "^7.1.6",
|
|
37
|
-
"lodash
|
|
37
|
+
"lodash": "^4.17.21",
|
|
38
38
|
"tough-cookie": "^4.0.0",
|
|
39
39
|
"winston": "^3.3.3",
|
|
40
40
|
"xml-js": "^1.6.11"
|
package/src/utils.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
const fs = require('fs')
|
|
2
|
+
const { padStart } = require('lodash')
|
|
2
3
|
const path = require('path')
|
|
3
4
|
const axios = require('axios').default
|
|
4
5
|
const axiosCookieJarSupport = require('axios-cookiejar-support').default
|
|
5
6
|
const tough = require('tough-cookie')
|
|
6
7
|
const convert = require('xml-js')
|
|
7
|
-
const merge = require('lodash
|
|
8
|
+
const { merge } = require('lodash')
|
|
8
9
|
const dayjs = require('dayjs')
|
|
9
10
|
const utc = require('dayjs/plugin/utc')
|
|
10
11
|
dayjs.extend(utc)
|
|
@@ -126,6 +127,8 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|
|
126
127
|
const start = program.start ? dayjs.unix(program.start).utc().format('YYYYMMDDHHmmss ZZ') : ''
|
|
127
128
|
const stop = program.stop ? dayjs.unix(program.stop).utc().format('YYYYMMDDHHmmss ZZ') : ''
|
|
128
129
|
const lang = program.lang || 'en'
|
|
130
|
+
const xmltv_ns = createXMLTVNS(program.season, program.episode)
|
|
131
|
+
const onscreen = createOnScreen(program.season, program.episode)
|
|
129
132
|
const icon = utils.escapeString(program.icon)
|
|
130
133
|
|
|
131
134
|
if (start && stop && title) {
|
|
@@ -143,6 +146,14 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|
|
143
146
|
})
|
|
144
147
|
}
|
|
145
148
|
|
|
149
|
+
if (xmltv_ns) {
|
|
150
|
+
output += `<episode-num system="xmltv_ns">${xmltv_ns}</episode-num>`
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
if (onscreen) {
|
|
154
|
+
output += `<episode-num system="onscreen">${onscreen}</episode-num>`
|
|
155
|
+
}
|
|
156
|
+
|
|
146
157
|
if (icon) {
|
|
147
158
|
output += `<icon src="${icon}"/>`
|
|
148
159
|
}
|
|
@@ -153,6 +164,21 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|
|
153
164
|
|
|
154
165
|
output += '</tv>'
|
|
155
166
|
|
|
167
|
+
function createXMLTVNS(s, e) {
|
|
168
|
+
if (!s || !e) return null
|
|
169
|
+
|
|
170
|
+
return `${s - 1}.${e - 1}.0/1`
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function createOnScreen(s, e) {
|
|
174
|
+
if (!s || !e) return null
|
|
175
|
+
|
|
176
|
+
s = padStart(s, 2, '0')
|
|
177
|
+
e = padStart(e, 2, '0')
|
|
178
|
+
|
|
179
|
+
return `S${s}E${e}`
|
|
180
|
+
}
|
|
181
|
+
|
|
156
182
|
return output
|
|
157
183
|
}
|
|
158
184
|
|
|
@@ -269,6 +295,8 @@ utils.parsePrograms = async function (data, config) {
|
|
|
269
295
|
title: program.title,
|
|
270
296
|
description: program.description || null,
|
|
271
297
|
category: program.category || null,
|
|
298
|
+
season: program.season || null,
|
|
299
|
+
episode: program.episode || null,
|
|
272
300
|
icon: program.icon || null,
|
|
273
301
|
channel: channel.xmltv_id,
|
|
274
302
|
lang: program.lang || channel.lang || config.lang || 'en',
|
package/tests/bin.test.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
const { execSync } = require('child_process')
|
|
2
|
-
const pwd = `${__dirname}/..`
|
|
3
|
-
import axios from 'axios'
|
|
4
2
|
|
|
5
|
-
|
|
3
|
+
const pwd = `${__dirname}/..`
|
|
6
4
|
|
|
7
5
|
function stdoutResultTester(stdout) {
|
|
8
6
|
return [`Finish`].every(val => {
|
|
@@ -22,8 +20,6 @@ it('can load config', () => {
|
|
|
22
20
|
})
|
|
23
21
|
|
|
24
22
|
it('can load mini config', () => {
|
|
25
|
-
axios.mockImplementation(() => Promise.resolve({ data: '' }))
|
|
26
|
-
|
|
27
23
|
const result = execSync(
|
|
28
24
|
`node ${pwd}/bin/epg-grabber.js \
|
|
29
25
|
--config=tests/input/mini.config.js \
|
|
@@ -32,7 +28,8 @@ it('can load mini config', () => {
|
|
|
32
28
|
--lang=fr \
|
|
33
29
|
--days=3 \
|
|
34
30
|
--delay=0 \
|
|
35
|
-
--
|
|
31
|
+
--debug \
|
|
32
|
+
--timeout=1`,
|
|
36
33
|
{
|
|
37
34
|
encoding: 'utf8'
|
|
38
35
|
}
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
const dayjs = require('dayjs')
|
|
2
|
+
const utc = require('dayjs/plugin/utc')
|
|
3
|
+
|
|
4
|
+
dayjs.extend(utc)
|
|
5
|
+
|
|
1
6
|
module.exports = {
|
|
2
7
|
site: 'example.com',
|
|
3
8
|
channels: 'example.com.channels.xml',
|
|
@@ -13,6 +18,20 @@ module.exports = {
|
|
|
13
18
|
return { accountID: '123' }
|
|
14
19
|
}
|
|
15
20
|
},
|
|
16
|
-
parser: () =>
|
|
21
|
+
parser: () => {
|
|
22
|
+
return [
|
|
23
|
+
{
|
|
24
|
+
title: 'Title',
|
|
25
|
+
description: 'Description',
|
|
26
|
+
lang: 'en',
|
|
27
|
+
category: ['Category1', 'Category2'],
|
|
28
|
+
icon: 'https://example.com/image.jpg',
|
|
29
|
+
season: 9,
|
|
30
|
+
episode: 238,
|
|
31
|
+
start: dayjs.utc('2022-01-01 00:00:00'),
|
|
32
|
+
stop: dayjs.utc('2022-01-01 01:00:00')
|
|
33
|
+
}
|
|
34
|
+
]
|
|
35
|
+
},
|
|
17
36
|
logo: () => 'http://example.com/logos/1TV.png?x=шеллы&sid=777'
|
|
18
37
|
}
|
package/tests/utils.test.js
CHANGED
|
@@ -59,6 +59,8 @@ it('can convert object to xmltv string', () => {
|
|
|
59
59
|
start: 1616133600,
|
|
60
60
|
stop: 1616135400,
|
|
61
61
|
category: 'Test',
|
|
62
|
+
season: 9,
|
|
63
|
+
episode: 239,
|
|
62
64
|
icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
|
|
63
65
|
channel: '1TV.com',
|
|
64
66
|
lang: 'it'
|
|
@@ -66,7 +68,7 @@ it('can convert object to xmltv string', () => {
|
|
|
66
68
|
]
|
|
67
69
|
const output = utils.convertToXMLTV({ channels, programs })
|
|
68
70
|
expect(output).toBe(
|
|
69
|
-
'<?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>'
|
|
71
|
+
'<?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">8.238.0/1</episode-num><episode-num system="onscreen">S09E239</episode-num><icon src="https://example.com/images/Program1.png?x=шеллы&sid=777"/></programme>\r\n</tv>'
|
|
70
72
|
)
|
|
71
73
|
})
|
|
72
74
|
|
|
@@ -195,6 +197,28 @@ it('can load logo async', done => {
|
|
|
195
197
|
})
|
|
196
198
|
})
|
|
197
199
|
|
|
200
|
+
it('can parse programs', done => {
|
|
201
|
+
const config = utils.loadConfig(require(path.resolve('./tests/input/example.com.config.js')))
|
|
202
|
+
return utils
|
|
203
|
+
.parsePrograms({ channel: { xmltv_id: '1tv', lang: 'en' } }, config)
|
|
204
|
+
.then(programs => {
|
|
205
|
+
expect(programs).toMatchObject([
|
|
206
|
+
{
|
|
207
|
+
title: 'Title',
|
|
208
|
+
description: 'Description',
|
|
209
|
+
lang: 'en',
|
|
210
|
+
category: ['Category1', 'Category2'],
|
|
211
|
+
icon: 'https://example.com/image.jpg',
|
|
212
|
+
season: 9,
|
|
213
|
+
episode: 238,
|
|
214
|
+
start: 1640995200,
|
|
215
|
+
stop: 1640998800
|
|
216
|
+
}
|
|
217
|
+
])
|
|
218
|
+
done()
|
|
219
|
+
})
|
|
220
|
+
})
|
|
221
|
+
|
|
198
222
|
it('can parse programs async', done => {
|
|
199
223
|
const config = utils.loadConfig(require(path.resolve('./tests/input/async.config.js')))
|
|
200
224
|
return utils
|