epg-grabber 0.21.0 → 0.24.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 +2 -0
- package/bin/epg-grabber.js +14 -2
- package/package.json +3 -1
- package/src/index.js +5 -2
- package/src/utils.js +25 -0
- package/tests/bin.test.js +16 -0
package/README.md
CHANGED
|
@@ -80,7 +80,9 @@ Arguments:
|
|
|
80
80
|
- `--days`: number of days for which to grab the program (default: 1)
|
|
81
81
|
- `--delay`: delay between requests (default: 3000)
|
|
82
82
|
- `--timeout`: set a timeout for each request (default: 5000)
|
|
83
|
+
- `--gzip`: compress output (default: false)
|
|
83
84
|
- `--debug`: enable debug mode (default: false)
|
|
85
|
+
- `--curl`: display current request as CURL (default: false)
|
|
84
86
|
- `--log`: path to log file (optional)
|
|
85
87
|
- `--log-level`: set the log level (default: 'info')
|
|
86
88
|
|
package/bin/epg-grabber.js
CHANGED
|
@@ -8,6 +8,7 @@ const grabber = require('../src/index')
|
|
|
8
8
|
const utils = require('../src/utils')
|
|
9
9
|
const { name, version, description } = require('../package.json')
|
|
10
10
|
const { merge } = require('lodash')
|
|
11
|
+
const { gzip } = require('node-gzip')
|
|
11
12
|
const { createLogger, format, transports } = require('winston')
|
|
12
13
|
const { combine, timestamp, printf } = format
|
|
13
14
|
|
|
@@ -22,7 +23,9 @@ program
|
|
|
22
23
|
.option('--days <days>', 'Number of days for which to grab the program', parseInteger, 1)
|
|
23
24
|
.option('--delay <delay>', 'Delay between requests (in mileseconds)', parseInteger)
|
|
24
25
|
.option('--timeout <timeout>', 'Set a timeout for each request (in mileseconds)', parseInteger)
|
|
26
|
+
.option('--gzip', 'Compress the output', false)
|
|
25
27
|
.option('--debug', 'Enable debug mode', false)
|
|
28
|
+
.option('--curl', 'Display request as CURL', false)
|
|
26
29
|
.option('--log <log>', 'Path to log file')
|
|
27
30
|
.option('--log-level <level>', 'Set log level', 'info')
|
|
28
31
|
.parse(process.argv)
|
|
@@ -64,6 +67,8 @@ async function main() {
|
|
|
64
67
|
config = merge(config, {
|
|
65
68
|
days: options.days,
|
|
66
69
|
debug: options.debug,
|
|
70
|
+
gzip: options.gzip,
|
|
71
|
+
curl: options.curl,
|
|
67
72
|
lang: options.lang,
|
|
68
73
|
delay: options.delay,
|
|
69
74
|
request: {
|
|
@@ -108,8 +113,15 @@ async function main() {
|
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
const xml = utils.convertToXMLTV({ config, channels, programs })
|
|
111
|
-
|
|
112
|
-
|
|
116
|
+
let outputPath = options.output || config.output
|
|
117
|
+
if (options.gzip) {
|
|
118
|
+
outputPath = outputPath || 'guide.xml.gz'
|
|
119
|
+
const compressed = await gzip(xml)
|
|
120
|
+
utils.writeToFile(outputPath, compressed)
|
|
121
|
+
} else {
|
|
122
|
+
outputPath = outputPath || 'guide.xml'
|
|
123
|
+
utils.writeToFile(outputPath, xml)
|
|
124
|
+
}
|
|
113
125
|
|
|
114
126
|
logger.info(`File '${outputPath}' successfully saved`)
|
|
115
127
|
logger.info('Finish')
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epg-grabber",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.0",
|
|
4
4
|
"description": "Node.js CLI tool for grabbing EPG from different sites",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"preferGlobal": true,
|
|
@@ -32,9 +32,11 @@
|
|
|
32
32
|
"axios-cookiejar-support": "^1.0.1",
|
|
33
33
|
"axios-mock-adapter": "^1.20.0",
|
|
34
34
|
"commander": "^7.1.0",
|
|
35
|
+
"curl-generator": "^0.2.0",
|
|
35
36
|
"dayjs": "^1.10.4",
|
|
36
37
|
"glob": "^7.1.6",
|
|
37
38
|
"lodash": "^4.17.21",
|
|
39
|
+
"node-gzip": "^1.1.2",
|
|
38
40
|
"tough-cookie": "^4.0.0",
|
|
39
41
|
"winston": "^3.3.3",
|
|
40
42
|
"xml-js": "^1.6.11"
|
package/src/index.js
CHANGED
|
@@ -18,9 +18,12 @@ module.exports = {
|
|
|
18
18
|
cb(item, null)
|
|
19
19
|
programs = programs.concat(results)
|
|
20
20
|
})
|
|
21
|
-
.catch(
|
|
21
|
+
.catch(error => {
|
|
22
22
|
item.programs = []
|
|
23
|
-
|
|
23
|
+
if (config.debug) {
|
|
24
|
+
console.log('Error:', JSON.stringify(error, null, 2))
|
|
25
|
+
}
|
|
26
|
+
cb(item, error)
|
|
24
27
|
})
|
|
25
28
|
|
|
26
29
|
await utils.sleep(config.delay)
|
package/src/utils.js
CHANGED
|
@@ -8,6 +8,7 @@ const convert = require('xml-js')
|
|
|
8
8
|
const { merge } = require('lodash')
|
|
9
9
|
const dayjs = require('dayjs')
|
|
10
10
|
const utc = require('dayjs/plugin/utc')
|
|
11
|
+
const { CurlGenerator } = require('curl-generator')
|
|
11
12
|
dayjs.extend(utc)
|
|
12
13
|
axiosCookieJarSupport(axios)
|
|
13
14
|
|
|
@@ -208,6 +209,16 @@ utils.buildRequest = async function (item, config) {
|
|
|
208
209
|
console.log('Request:', JSON.stringify(request, null, 2))
|
|
209
210
|
}
|
|
210
211
|
|
|
212
|
+
if (config.curl) {
|
|
213
|
+
const curl = CurlGenerator({
|
|
214
|
+
url: request.url,
|
|
215
|
+
method: request.method,
|
|
216
|
+
headers: request.headers,
|
|
217
|
+
body: request.data
|
|
218
|
+
})
|
|
219
|
+
console.log(curl)
|
|
220
|
+
}
|
|
221
|
+
|
|
211
222
|
return request
|
|
212
223
|
}
|
|
213
224
|
|
|
@@ -266,6 +277,20 @@ utils.getUTCDate = function (d = null) {
|
|
|
266
277
|
}
|
|
267
278
|
|
|
268
279
|
utils.parseResponse = async (item, response, config) => {
|
|
280
|
+
if (config.debug) {
|
|
281
|
+
console.log(
|
|
282
|
+
'Response:',
|
|
283
|
+
JSON.stringify(
|
|
284
|
+
{
|
|
285
|
+
headers: response.headers,
|
|
286
|
+
data: response.data.toString()
|
|
287
|
+
},
|
|
288
|
+
null,
|
|
289
|
+
2
|
|
290
|
+
)
|
|
291
|
+
)
|
|
292
|
+
}
|
|
293
|
+
|
|
269
294
|
const data = merge(item, config, {
|
|
270
295
|
content: response.data.toString(),
|
|
271
296
|
buffer: response.data,
|
package/tests/bin.test.js
CHANGED
|
@@ -38,3 +38,19 @@ it('can load mini config', () => {
|
|
|
38
38
|
expect(stdoutResultTester(result)).toBe(true)
|
|
39
39
|
expect(result.includes("File 'tests/output/mini.guide.xml' successfully saved")).toBe(true)
|
|
40
40
|
})
|
|
41
|
+
|
|
42
|
+
it('can generate gzip version', () => {
|
|
43
|
+
const result = execSync(
|
|
44
|
+
`node ${pwd}/bin/epg-grabber.js \
|
|
45
|
+
--config=tests/input/mini.config.js \
|
|
46
|
+
--channels=tests/input/example.com.channels.xml \
|
|
47
|
+
--output=tests/output/mini.guide.xml.gz \
|
|
48
|
+
--gzip`,
|
|
49
|
+
{
|
|
50
|
+
encoding: 'utf8'
|
|
51
|
+
}
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
expect(stdoutResultTester(result)).toBe(true)
|
|
55
|
+
expect(result.includes("File 'tests/output/mini.guide.xml.gz' successfully saved")).toBe(true)
|
|
56
|
+
})
|