epg-grabber 0.14.0 → 0.16.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
@@ -56,6 +56,7 @@ module.exports = {
56
56
  <tv>
57
57
  <channel id="CNN.us">
58
58
  <display-name>CNN</display-name>
59
+ <url>https://example.com</url>
59
60
  </channel>
60
61
  <programme start="20211116040000 +0000" stop="20211116050000 +0000" channel="CNN.us">
61
62
  <title lang="en">News at 10PM</title>
@@ -93,6 +94,7 @@ module.exports = {
93
94
  lang: 'fr', // default language for all programs (default: 'en')
94
95
  days: 3, // number of days for which to grab the program (default: 1)
95
96
  delay: 5000, // delay between requests (default: 3000)
97
+ ignore: true, // skip all channels during request (default: false)
96
98
 
97
99
  request: { // request options (details: https://github.com/axios/axios#request-config)
98
100
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epg-grabber",
3
- "version": "0.14.0",
3
+ "version": "0.16.0",
4
4
  "description": "Node.js CLI tool for grabbing EPG from different sites",
5
5
  "main": "src/index.js",
6
6
  "preferGlobal": true,
package/src/index.js CHANGED
@@ -14,6 +14,12 @@ module.exports = {
14
14
 
15
15
  let programs = []
16
16
  for (let item of queue) {
17
+ if (config.ignore) {
18
+ item.programs = []
19
+ cb(item, new Error('Skipped'))
20
+ continue
21
+ }
22
+
17
23
  await utils
18
24
  .buildRequest(item, config)
19
25
  .then(request => utils.fetchData(request))
package/src/utils.js CHANGED
@@ -123,8 +123,8 @@ utils.convertToXMLTV = function ({ channels, programs }) {
123
123
  const title = utils.escapeString(program.title)
124
124
  const description = utils.escapeString(program.description)
125
125
  const categories = Array.isArray(program.category) ? program.category : [program.category]
126
- const start = program.start ? dayjs.utc(program.start).format('YYYYMMDDHHmmss ZZ') : ''
127
- const stop = program.stop ? dayjs.utc(program.stop).format('YYYYMMDDHHmmss ZZ') : ''
126
+ const start = program.start ? dayjs.unix(program.start).utc().format('YYYYMMDDHHmmss ZZ') : ''
127
+ const stop = program.stop ? dayjs.unix(program.stop).utc().format('YYYYMMDDHHmmss ZZ') : ''
128
128
  const lang = program.lang || 'en'
129
129
  const icon = utils.escapeString(program.icon)
130
130
 
@@ -244,7 +244,7 @@ utils.parseResponse = async (item, response, config) => {
244
244
  })
245
245
 
246
246
  if (!item.channel.logo && config.logo) {
247
- item.channel.logo = await utils.loadLogo(data, config)
247
+ data.channel.logo = await utils.loadLogo(data, config)
248
248
  }
249
249
 
250
250
  return await utils.parsePrograms(data, config)
@@ -265,9 +265,16 @@ utils.parsePrograms = async function (data, config) {
265
265
  return programs
266
266
  .filter(i => i)
267
267
  .map(program => {
268
- program.channel = channel.xmltv_id
269
- program.lang = program.lang || channel.lang || config.lang || 'en'
270
- return program
268
+ return {
269
+ title: program.title,
270
+ description: program.description || null,
271
+ category: program.category || null,
272
+ icon: program.icon || null,
273
+ channel: channel.xmltv_id,
274
+ lang: program.lang || channel.lang || config.lang || 'en',
275
+ start: program.start ? dayjs(program.start).unix() : null,
276
+ stop: program.stop ? dayjs(program.stop).unix() : null
277
+ }
271
278
  })
272
279
  }
273
280
 
package/tests/bin.test.js CHANGED
@@ -1,8 +1,6 @@
1
1
  const { execSync } = require('child_process')
2
- const pwd = `${__dirname}/..`
3
- import axios from 'axios'
4
2
 
5
- jest.mock('axios')
3
+ const pwd = `${__dirname}/..`
6
4
 
7
5
  function stdoutResultTester(stdout) {
8
6
  return [`Finish`].every(val => {
@@ -22,8 +20,6 @@ it('can load config', () => {
22
20
  })
23
21
 
24
22
  it('can load mini config', () => {
25
- axios.mockImplementation(() => Promise.resolve({ data: '' }))
26
-
27
23
  const result = execSync(
28
24
  `node ${pwd}/bin/epg-grabber.js \
29
25
  --config=tests/input/mini.config.js \
@@ -32,7 +28,8 @@ it('can load mini config', () => {
32
28
  --lang=fr \
33
29
  --days=3 \
34
30
  --delay=0 \
35
- --timeout=10000`,
31
+ --debug \
32
+ --timeout=1`,
36
33
  {
37
34
  encoding: 'utf8'
38
35
  }
@@ -71,3 +71,23 @@ it('can grab single channel programs', done => {
71
71
  done()
72
72
  })
73
73
  })
74
+
75
+ it('return "Skipped" error if ignore option in config is true', done => {
76
+ const config = {
77
+ site: 'example.com',
78
+ ignore: true,
79
+ url: `http://example.com/20210319/1tv.json`,
80
+ parser: () => []
81
+ }
82
+ const channel = {
83
+ site: 'example.com',
84
+ site_id: 'cnn',
85
+ xmltv_id: 'CNN.us',
86
+ lang: 'en',
87
+ name: 'CNN'
88
+ }
89
+ grabber.grab(channel, config, (data, err) => {
90
+ expect(err.message).toBe('Skipped')
91
+ done()
92
+ })
93
+ })
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  site: 'example.com',
3
+ ignore: true,
3
4
  channels: 'example.com.channels.xml',
4
5
  output: 'tests/output/guide.xml',
5
6
  url: () => 'http://example.com/20210319/1tv.json',
@@ -1,5 +1,6 @@
1
1
  module.exports = {
2
2
  site: 'example.com',
3
+ ignore: true,
3
4
  url: 'http://example.com/20210319/1tv.json',
4
5
  parser: () => []
5
6
  }
@@ -7,6 +7,7 @@ it('can load valid config.js', () => {
7
7
  const config = utils.loadConfig(require(path.resolve('./tests/input/example.com.config.js')))
8
8
  expect(config).toMatchObject({
9
9
  days: 1,
10
+ ignore: true,
10
11
  delay: 3000,
11
12
  lang: 'en',
12
13
  site: 'example.com'
@@ -56,8 +57,8 @@ it('can convert object to xmltv string', () => {
56
57
  {
57
58
  title: 'Program 1',
58
59
  description: 'Description for Program 1',
59
- start: '2021-03-19 06:00:00 +0000',
60
- stop: '2021-03-19 06:30:00 +0000',
60
+ start: 1616133600,
61
+ stop: 1616135400,
61
62
  category: 'Test',
62
63
  icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
63
64
  channel: '1TV.com',
@@ -84,8 +85,8 @@ it('can convert object to xmltv string without categories', () => {
84
85
  const programs = [
85
86
  {
86
87
  title: 'Program 1',
87
- start: '2021-03-19 06:00:00 +0000',
88
- stop: '2021-03-19 06:30:00 +0000',
88
+ start: 1616133600,
89
+ stop: 1616135400,
89
90
  channel: '1TV.com',
90
91
  lang: 'it'
91
92
  }
@@ -104,8 +105,8 @@ it('can convert object to xmltv string with multiple categories', () => {
104
105
  {
105
106
  title: 'Program 1',
106
107
  description: 'Description for Program 1',
107
- start: '2021-03-19 06:00:00 +0000',
108
- stop: '2021-03-19 06:30:00 +0000',
108
+ start: 1616133600,
109
+ stop: 1616135400,
109
110
  category: ['Test1', 'Test2'],
110
111
  icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
111
112
  channel: '1TV.com',