epg-grabber 0.16.0 → 0.17.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 +27 -1
- package/tests/utils.test.js +3 -1
package/README.md
CHANGED
|
@@ -159,12 +159,14 @@ module.exports = {
|
|
|
159
159
|
return [
|
|
160
160
|
{
|
|
161
161
|
title, // program title (required)
|
|
162
|
-
start, //
|
|
163
|
-
stop, //
|
|
164
|
-
description, // program
|
|
165
|
-
category, // program
|
|
166
|
-
|
|
167
|
-
|
|
162
|
+
start, // start time of the program (required)
|
|
163
|
+
stop, // end time of the program (required)
|
|
164
|
+
description, // description of the program (optional)
|
|
165
|
+
category, // program type (optional)
|
|
166
|
+
season, // season number (optional)
|
|
167
|
+
episode, // episode number (optional)
|
|
168
|
+
icon, // image associated with the program (optional)
|
|
169
|
+
lang // language of the description (default: 'en')
|
|
168
170
|
},
|
|
169
171
|
...
|
|
170
172
|
]
|
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.17.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
|
|
package/tests/utils.test.js
CHANGED
|
@@ -60,6 +60,8 @@ it('can convert object to xmltv string', () => {
|
|
|
60
60
|
start: 1616133600,
|
|
61
61
|
stop: 1616135400,
|
|
62
62
|
category: 'Test',
|
|
63
|
+
season: 9,
|
|
64
|
+
episode: 239,
|
|
63
65
|
icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
|
|
64
66
|
channel: '1TV.com',
|
|
65
67
|
lang: 'it'
|
|
@@ -67,7 +69,7 @@ it('can convert object to xmltv string', () => {
|
|
|
67
69
|
]
|
|
68
70
|
const output = utils.convertToXMLTV({ channels, programs })
|
|
69
71
|
expect(output).toBe(
|
|
70
|
-
'<?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>'
|
|
72
|
+
'<?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>'
|
|
71
73
|
)
|
|
72
74
|
})
|
|
73
75
|
|