epg-grabber 0.25.4 → 0.26.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 +5 -7
- package/bin/epg-grabber.js +4 -7
- package/package.json +2 -2
- package/src/utils.js +8 -22
package/README.md
CHANGED
|
@@ -80,7 +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
|
-
- `--cache-
|
|
83
|
+
- `--cache-ttl`: maximum time for storing each request in milliseconds (default: 0)
|
|
84
84
|
- `--gzip`: compress the output (default: false)
|
|
85
85
|
- `--debug`: enable debug mode (default: false)
|
|
86
86
|
- `--curl`: display current request as CURL (default: false)
|
|
@@ -102,12 +102,8 @@ module.exports = {
|
|
|
102
102
|
|
|
103
103
|
method: 'GET',
|
|
104
104
|
timeout: 5000,
|
|
105
|
-
cache: { // cache options (details: https://
|
|
106
|
-
|
|
107
|
-
readHeaders: false,
|
|
108
|
-
exclude: {
|
|
109
|
-
query: false
|
|
110
|
-
}
|
|
105
|
+
cache: { // cache options (details: https://axios-cache-interceptor.js.org/#/pages/per-request-configuration)
|
|
106
|
+
ttl: 60 * 1000 // 60s
|
|
111
107
|
},
|
|
112
108
|
|
|
113
109
|
/**
|
|
@@ -192,6 +188,8 @@ From each function in `config.js` you can access a `context` object containing t
|
|
|
192
188
|
- `content`: The response data as a String
|
|
193
189
|
- `buffer`: The response data as an ArrayBuffer
|
|
194
190
|
- `headers`: The response headers
|
|
191
|
+
- `request`: The request config
|
|
192
|
+
- `cached`: A boolean to check whether this request was cached or not
|
|
195
193
|
|
|
196
194
|
## Channels List
|
|
197
195
|
|
package/bin/epg-grabber.js
CHANGED
|
@@ -24,7 +24,7 @@ program
|
|
|
24
24
|
.option('--delay <delay>', 'Delay between requests (in mileseconds)', parseInteger)
|
|
25
25
|
.option('--timeout <timeout>', 'Set a timeout for each request (in mileseconds)', parseInteger)
|
|
26
26
|
.option(
|
|
27
|
-
'--cache-
|
|
27
|
+
'--cache-ttl <cacheTtl>',
|
|
28
28
|
'Maximum time for storing each request (in milliseconds)',
|
|
29
29
|
parseInteger
|
|
30
30
|
)
|
|
@@ -76,14 +76,11 @@ async function main() {
|
|
|
76
76
|
curl: options.curl,
|
|
77
77
|
lang: options.lang,
|
|
78
78
|
delay: options.delay,
|
|
79
|
-
request: {
|
|
80
|
-
timeout: options.timeout,
|
|
81
|
-
cache: {
|
|
82
|
-
maxAge: options.cacheMaxAge
|
|
83
|
-
}
|
|
84
|
-
}
|
|
79
|
+
request: {}
|
|
85
80
|
})
|
|
86
81
|
|
|
82
|
+
if (options.timeout) config.request.timeout = options.timeout
|
|
83
|
+
if (options.cacheTtl) config.request.cache.ttl = options.cacheTtl
|
|
87
84
|
if (options.channels) config.channels = options.channels
|
|
88
85
|
else if (config.channels)
|
|
89
86
|
config.channels = path.join(path.dirname(options.config), config.channels)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epg-grabber",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "Node.js CLI tool for grabbing EPG from different sites",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"preferGlobal": true,
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"axios": "^0.21.1",
|
|
32
|
-
"axios-cache-
|
|
32
|
+
"axios-cache-interceptor": "^0.10.3",
|
|
33
33
|
"axios-cookiejar-support": "^1.0.1",
|
|
34
34
|
"axios-mock-adapter": "^1.20.0",
|
|
35
35
|
"commander": "^7.1.0",
|
package/src/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ const { padStart } = require('lodash')
|
|
|
3
3
|
const path = require('path')
|
|
4
4
|
const axios = require('axios').default
|
|
5
5
|
const axiosCookieJarSupport = require('axios-cookiejar-support').default
|
|
6
|
-
const
|
|
6
|
+
const { setupCache } = require('axios-cache-interceptor')
|
|
7
7
|
const tough = require('tough-cookie')
|
|
8
8
|
const convert = require('xml-js')
|
|
9
9
|
const { merge } = require('lodash')
|
|
@@ -41,13 +41,7 @@ utils.loadConfig = function (config) {
|
|
|
41
41
|
withCredentials: true,
|
|
42
42
|
jar: new tough.CookieJar(),
|
|
43
43
|
responseType: 'arraybuffer',
|
|
44
|
-
cache:
|
|
45
|
-
readHeaders: false,
|
|
46
|
-
exclude: {
|
|
47
|
-
query: false
|
|
48
|
-
},
|
|
49
|
-
maxAge: 0
|
|
50
|
-
}
|
|
44
|
+
cache: false
|
|
51
45
|
}
|
|
52
46
|
}
|
|
53
47
|
|
|
@@ -55,7 +49,7 @@ utils.loadConfig = function (config) {
|
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
utils.createClient = function (config) {
|
|
58
|
-
const client =
|
|
52
|
+
const client = setupCache(axios.create())
|
|
59
53
|
client.interceptors.request.use(
|
|
60
54
|
function (request) {
|
|
61
55
|
if (config.debug) {
|
|
@@ -80,7 +74,7 @@ utils.createClient = function (config) {
|
|
|
80
74
|
{
|
|
81
75
|
headers: response.headers,
|
|
82
76
|
data,
|
|
83
|
-
|
|
77
|
+
cached: response.cached
|
|
84
78
|
},
|
|
85
79
|
null,
|
|
86
80
|
2
|
|
@@ -318,20 +312,12 @@ utils.getUTCDate = function (d = null) {
|
|
|
318
312
|
}
|
|
319
313
|
|
|
320
314
|
utils.parseResponse = async (item, response, config) => {
|
|
321
|
-
let buffer
|
|
322
|
-
let content
|
|
323
|
-
if (utils.isObject(response.data) || Array.isArray(response.data)) {
|
|
324
|
-
content = JSON.stringify(response.data)
|
|
325
|
-
buffer = Buffer.from(content, 'utf8')
|
|
326
|
-
} else {
|
|
327
|
-
content = response.data.toString()
|
|
328
|
-
buffer = response.data
|
|
329
|
-
}
|
|
330
315
|
const data = merge(item, config, {
|
|
331
|
-
content,
|
|
332
|
-
buffer,
|
|
316
|
+
content: response.data.toString(),
|
|
317
|
+
buffer: response.data,
|
|
333
318
|
headers: response.headers,
|
|
334
|
-
request: response.request
|
|
319
|
+
request: response.request,
|
|
320
|
+
cached: response.cached
|
|
335
321
|
})
|
|
336
322
|
|
|
337
323
|
if (!item.channel.logo && config.logo) {
|