epg-grabber 0.29.1 → 0.29.2
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/bin/epg-grabber.js +3 -0
- package/package.json +2 -1
- package/tests/__data__/expected/duplicates.guide.xml +6 -0
- package/tests/{input → __data__/input}/async.config.js +0 -0
- package/tests/__data__/input/duplicates.config.js +18 -0
- package/tests/{input → __data__/input}/example.channels.xml +0 -0
- package/tests/{input → __data__/input}/example.config.js +0 -0
- package/tests/{input → __data__/input}/mini.config.js +0 -0
- package/tests/__data__/output/duplicates.guide.xml +6 -0
- package/tests/__data__/output/duplicates.guide.xml.gz +0 -0
- package/tests/__data__/output/mini.guide.xml +4 -0
- package/tests/__data__/output/mini.guide.xml.gz +0 -0
- package/tests/bin.test.js +36 -9
- package/tests/config.test.js +1 -1
- package/tests/parser.test.js +3 -3
package/bin/epg-grabber.js
CHANGED
|
@@ -9,6 +9,7 @@ const { EPGGrabber, parseChannels, generateXMLTV } = require('../src/index')
|
|
|
9
9
|
const { create: createLogger } = require('../src/logger')
|
|
10
10
|
const { parseNumber, getUTCDate } = require('../src/utils')
|
|
11
11
|
const { name, version, description } = require('../package.json')
|
|
12
|
+
const _ = require('lodash')
|
|
12
13
|
const dayjs = require('dayjs')
|
|
13
14
|
const utc = require('dayjs/plugin/utc')
|
|
14
15
|
|
|
@@ -99,6 +100,8 @@ async function main() {
|
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
|
|
103
|
+
programs = _.uniqBy(programs, p => p.start + p.channel)
|
|
104
|
+
|
|
102
105
|
const xml = generateXMLTV({ channels, programs })
|
|
103
106
|
let outputPath = options.output || config.output
|
|
104
107
|
if (options.gzip) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "epg-grabber",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.2",
|
|
4
4
|
"description": "Node.js CLI tool for grabbing EPG from different sites",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"preferGlobal": true,
|
|
@@ -35,6 +35,7 @@
|
|
|
35
35
|
"commander": "^7.1.0",
|
|
36
36
|
"curl-generator": "^0.2.0",
|
|
37
37
|
"dayjs": "^1.10.4",
|
|
38
|
+
"epg-parser": "^0.1.6",
|
|
38
39
|
"glob": "^7.1.6",
|
|
39
40
|
"lodash": "^4.17.21",
|
|
40
41
|
"node-gzip": "^1.1.2",
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?><tv date="20220828">
|
|
2
|
+
<channel id="1TV.com"><display-name>1 TV</display-name><icon src="https://example.com/logos/1TV.png"/><url>https://example.com</url></channel>
|
|
3
|
+
<channel id="2TV.com"><display-name>2 TV</display-name><url>https://example.com</url></channel>
|
|
4
|
+
<programme start="20220101000000 +0000" stop="20220101010000 +0000" channel="1TV.com"><title lang="fr">Program1</title></programme>
|
|
5
|
+
<programme start="20220101000000 +0000" stop="20220101010000 +0000" channel="2TV.com"><title>Program1</title></programme>
|
|
6
|
+
</tv>
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
site: 'example.com',
|
|
3
|
+
url: 'https://google.com',
|
|
4
|
+
parser() {
|
|
5
|
+
return [
|
|
6
|
+
{
|
|
7
|
+
title: 'Program1',
|
|
8
|
+
start: 1640995200000,
|
|
9
|
+
stop: 1640998800000
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
title: 'Program1',
|
|
13
|
+
start: 1640995200000,
|
|
14
|
+
stop: 1640998900000
|
|
15
|
+
}
|
|
16
|
+
]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?><tv date="20220829">
|
|
2
|
+
<channel id="1TV.com"><display-name>1 TV</display-name><icon src="https://example.com/logos/1TV.png"/><url>https://example.com</url></channel>
|
|
3
|
+
<channel id="2TV.com"><display-name>2 TV</display-name><url>https://example.com</url></channel>
|
|
4
|
+
<programme start="20220101000000 +0000" stop="20220101010000 +0000" channel="1TV.com"><title lang="fr">Program1</title></programme>
|
|
5
|
+
<programme start="20220101000000 +0000" stop="20220101010000 +0000" channel="2TV.com"><title>Program1</title></programme>
|
|
6
|
+
</tv>
|
|
Binary file
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" ?><tv date="20220829">
|
|
2
|
+
<channel id="1TV.com"><display-name>1 TV</display-name><icon src="https://example.com/logos/1TV.png"/><url>https://example.com</url></channel>
|
|
3
|
+
<channel id="2TV.com"><display-name>2 TV</display-name><url>https://example.com</url></channel>
|
|
4
|
+
</tv>
|
|
Binary file
|
package/tests/bin.test.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
const { execSync } = require('child_process')
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
const path = require('path')
|
|
4
|
+
const epgParser = require('epg-parser')
|
|
2
5
|
|
|
3
6
|
const pwd = `${__dirname}/..`
|
|
4
7
|
|
|
@@ -10,7 +13,7 @@ function stdoutResultTester(stdout) {
|
|
|
10
13
|
|
|
11
14
|
it('can load config', () => {
|
|
12
15
|
const result = execSync(
|
|
13
|
-
`node ${pwd}/bin/epg-grabber.js --config=tests/input/example.config.js --delay=0`,
|
|
16
|
+
`node ${pwd}/bin/epg-grabber.js --config=tests/__data__/input/example.config.js --delay=0`,
|
|
14
17
|
{
|
|
15
18
|
encoding: 'utf8'
|
|
16
19
|
}
|
|
@@ -22,9 +25,9 @@ it('can load config', () => {
|
|
|
22
25
|
it('can load mini config', () => {
|
|
23
26
|
const result = execSync(
|
|
24
27
|
`node ${pwd}/bin/epg-grabber.js \
|
|
25
|
-
--config=tests/input/mini.config.js \
|
|
26
|
-
--channels=tests/input/example.channels.xml \
|
|
27
|
-
--output=tests/output/mini.guide.xml \
|
|
28
|
+
--config=tests/__data__/input/mini.config.js \
|
|
29
|
+
--channels=tests/__data__/input/example.channels.xml \
|
|
30
|
+
--output=tests/__data__/output/mini.guide.xml \
|
|
28
31
|
--lang=fr \
|
|
29
32
|
--days=3 \
|
|
30
33
|
--delay=0 \
|
|
@@ -36,15 +39,17 @@ it('can load mini config', () => {
|
|
|
36
39
|
)
|
|
37
40
|
|
|
38
41
|
expect(stdoutResultTester(result)).toBe(true)
|
|
39
|
-
expect(result.includes("File 'tests/output/mini.guide.xml' successfully saved")).toBe(
|
|
42
|
+
expect(result.includes("File 'tests/__data__/output/mini.guide.xml' successfully saved")).toBe(
|
|
43
|
+
true
|
|
44
|
+
)
|
|
40
45
|
})
|
|
41
46
|
|
|
42
47
|
it('can generate gzip version', () => {
|
|
43
48
|
const result = execSync(
|
|
44
49
|
`node ${pwd}/bin/epg-grabber.js \
|
|
45
|
-
--config=tests/input/mini.config.js \
|
|
46
|
-
--channels=tests/input/example.channels.xml \
|
|
47
|
-
--output=tests/output/mini.guide.xml.gz \
|
|
50
|
+
--config=tests/__data__/input/mini.config.js \
|
|
51
|
+
--channels=tests/__data__/input/example.channels.xml \
|
|
52
|
+
--output=tests/__data__/output/mini.guide.xml.gz \
|
|
48
53
|
--gzip`,
|
|
49
54
|
{
|
|
50
55
|
encoding: 'utf8'
|
|
@@ -52,5 +57,27 @@ it('can generate gzip version', () => {
|
|
|
52
57
|
)
|
|
53
58
|
|
|
54
59
|
expect(stdoutResultTester(result)).toBe(true)
|
|
55
|
-
expect(result.includes("File 'tests/output/mini.guide.xml.gz' successfully saved")).toBe(
|
|
60
|
+
expect(result.includes("File 'tests/__data__/output/mini.guide.xml.gz' successfully saved")).toBe(
|
|
61
|
+
true
|
|
62
|
+
)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('removes duplicates of the program', () => {
|
|
66
|
+
const result = execSync(
|
|
67
|
+
`node ${pwd}/bin/epg-grabber.js \
|
|
68
|
+
--config=tests/__data__/input/duplicates.config.js \
|
|
69
|
+
--channels=tests/__data__/input/example.channels.xml \
|
|
70
|
+
--output=tests/__data__/output/duplicates.guide.xml`,
|
|
71
|
+
{
|
|
72
|
+
encoding: 'utf8'
|
|
73
|
+
}
|
|
74
|
+
)
|
|
75
|
+
|
|
76
|
+
let output = fs.readFileSync(path.resolve(__dirname, '__data__/output/duplicates.guide.xml'))
|
|
77
|
+
let expected = fs.readFileSync(path.resolve(__dirname, '__data__/expected/duplicates.guide.xml'))
|
|
78
|
+
|
|
79
|
+
output = epgParser.parse(output)
|
|
80
|
+
expected = epgParser.parse(expected)
|
|
81
|
+
|
|
82
|
+
expect(output.programs).toEqual(expected.programs)
|
|
56
83
|
})
|
package/tests/config.test.js
CHANGED
|
@@ -3,7 +3,7 @@ import path from 'path'
|
|
|
3
3
|
import fs from 'fs'
|
|
4
4
|
|
|
5
5
|
it('can load config', () => {
|
|
6
|
-
const config = loadConfig(require(path.resolve('./tests/input/example.config.js')))
|
|
6
|
+
const config = loadConfig(require(path.resolve('./tests/__data__/input/example.config.js')))
|
|
7
7
|
expect(config).toMatchObject({
|
|
8
8
|
days: 1,
|
|
9
9
|
delay: 3000,
|
package/tests/parser.test.js
CHANGED
|
@@ -4,7 +4,7 @@ import Program from '../src/Program'
|
|
|
4
4
|
import fs from 'fs'
|
|
5
5
|
|
|
6
6
|
it('can parse valid channels.xml', () => {
|
|
7
|
-
const file = fs.readFileSync('./tests/input/example.channels.xml', { encoding: 'utf-8' })
|
|
7
|
+
const file = fs.readFileSync('./tests/__data__/input/example.channels.xml', { encoding: 'utf-8' })
|
|
8
8
|
const { channels, site } = parseChannels(file)
|
|
9
9
|
|
|
10
10
|
expect(typeof site).toBe('string')
|
|
@@ -15,7 +15,7 @@ it('can parse valid channels.xml', () => {
|
|
|
15
15
|
|
|
16
16
|
it('can parse programs', done => {
|
|
17
17
|
const channel = new Channel({ xmltv_id: '1tv' })
|
|
18
|
-
const config = require('./input/example.config.js')
|
|
18
|
+
const config = require('./__data__/input/example.config.js')
|
|
19
19
|
|
|
20
20
|
parsePrograms({ channel, config })
|
|
21
21
|
.then(programs => {
|
|
@@ -28,7 +28,7 @@ it('can parse programs', done => {
|
|
|
28
28
|
|
|
29
29
|
it('can parse programs async', done => {
|
|
30
30
|
const channel = new Channel({ xmltv_id: '1tv' })
|
|
31
|
-
const config = require('./input/async.config.js')
|
|
31
|
+
const config = require('./__data__/input/async.config.js')
|
|
32
32
|
|
|
33
33
|
parsePrograms({ channel, config })
|
|
34
34
|
.then(programs => {
|