epg-grabber 0.23.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 CHANGED
@@ -80,6 +80,7 @@ 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)
84
85
  - `--curl`: display current request as CURL (default: false)
85
86
  - `--log`: path to log file (optional)
@@ -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,6 +23,7 @@ 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)
26
28
  .option('--curl', 'Display request as CURL', false)
27
29
  .option('--log <log>', 'Path to log file')
@@ -65,6 +67,7 @@ async function main() {
65
67
  config = merge(config, {
66
68
  days: options.days,
67
69
  debug: options.debug,
70
+ gzip: options.gzip,
68
71
  curl: options.curl,
69
72
  lang: options.lang,
70
73
  delay: options.delay,
@@ -110,8 +113,15 @@ async function main() {
110
113
  }
111
114
 
112
115
  const xml = utils.convertToXMLTV({ config, channels, programs })
113
- const outputPath = options.output || config.output || 'guide.xml'
114
- utils.writeToFile(outputPath, xml)
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
+ }
115
125
 
116
126
  logger.info(`File '${outputPath}' successfully saved`)
117
127
  logger.info('Finish')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epg-grabber",
3
- "version": "0.23.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,
@@ -36,6 +36,7 @@
36
36
  "dayjs": "^1.10.4",
37
37
  "glob": "^7.1.6",
38
38
  "lodash": "^4.17.21",
39
+ "node-gzip": "^1.1.2",
39
40
  "tough-cookie": "^4.0.0",
40
41
  "winston": "^3.3.3",
41
42
  "xml-js": "^1.6.11"
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
+ })