epg-grabber 0.28.4 → 0.28.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "epg-grabber",
3
- "version": "0.28.4",
3
+ "version": "0.28.5",
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/Program.js CHANGED
@@ -4,15 +4,16 @@ const { toArray, toUnix, parseNumber } = require('./utils')
4
4
  class Program {
5
5
  constructor(p) {
6
6
  const data = {
7
- channel: p.channel,
8
- title: p.title,
7
+ site: p.site || '',
8
+ channel: p.channel || '',
9
+ title: p.title || '',
9
10
  sub_title: p.sub_title || '',
10
- description: [p.description, p.desc, ''].find(i => i !== undefined),
11
+ description: [p.description, p.desc].find(i => i) || '',
11
12
  icon: toIconObject(p.icon),
12
- episodeNumbers: getEpisodeNumbers(p.season, p.episode),
13
+ episodeNumbers: p.episodeNumbers || getEpisodeNumbers(p.season, p.episode),
13
14
  date: p.date ? toUnix(p.date) : null,
14
- start: toUnix(p.start),
15
- stop: toUnix(p.stop),
15
+ start: p.start ? toUnix(p.start) : null,
16
+ stop: p.stop ? toUnix(p.stop) : null,
16
17
  urls: toArray(p.urls || p.url).map(toUrlObject),
17
18
  ratings: toArray(p.ratings || p.rating).map(toRatingObject),
18
19
  categories: toArray(p.categories || p.category),
@@ -84,7 +85,8 @@ function toUrlObject(url) {
84
85
  }
85
86
 
86
87
  function toIconObject(icon) {
87
- if (!icon || typeof icon === 'string') return { src: icon }
88
+ if (!icon) return { src: '' }
89
+ if (typeof icon === 'string') return { src: icon }
88
90
 
89
91
  return {
90
92
  src: icon.src || ''
package/src/index.js CHANGED
@@ -4,9 +4,13 @@ const { parseChannels, parsePrograms } = require('./parser')
4
4
  const { generate: generateXMLTV } = require('./xmltv')
5
5
  const { load: loadConfig } = require('./config')
6
6
  const { sleep, isPromise } = require('./utils')
7
+ const Channel = require('./Channel')
8
+ const Program = require('./Program')
7
9
 
8
10
  module.exports.generateXMLTV = generateXMLTV
9
11
  module.exports.parseChannels = parseChannels
12
+ module.exports.Channel = Channel
13
+ module.exports.Program = Program
10
14
 
11
15
  class EPGGrabber {
12
16
  constructor(config = {}) {
package/src/parser.js CHANGED
@@ -44,6 +44,7 @@ async function parsePrograms(data) {
44
44
  return programs
45
45
  .filter(i => i)
46
46
  .map(p => {
47
+ p.site = channel.site
47
48
  p.channel = p.channel || channel.id
48
49
 
49
50
  return new Program(p)
package/src/utils.js CHANGED
@@ -12,11 +12,16 @@ module.exports.parseNumber = parseNumber
12
12
  module.exports.formatDate = formatDate
13
13
  module.exports.toArray = toArray
14
14
  module.exports.toUnix = toUnix
15
+ module.exports.isDate = isDate
15
16
 
16
17
  function sleep(ms) {
17
18
  return new Promise(resolve => setTimeout(resolve, ms))
18
19
  }
19
20
 
21
+ function isDate(d) {
22
+ return dayjs(d).isValid()
23
+ }
24
+
20
25
  function isObject(a) {
21
26
  return !!a && a.constructor === Object
22
27
  }
package/src/xmltv.js CHANGED
@@ -1,9 +1,23 @@
1
- const { escapeString, getUTCDate, formatDate } = require('./utils')
1
+ const Channel = require('./Channel')
2
+ const Program = require('./Program')
3
+ const { escapeString, getUTCDate, formatDate, isDate } = require('./utils')
2
4
  const el = createElement
3
5
 
4
6
  module.exports.generate = generate
5
7
 
6
8
  function generate({ channels, programs, date = getUTCDate() }) {
9
+ if (!channels.every(c => c instanceof Channel)) {
10
+ throw new Error('"channels" must be an array of Channels')
11
+ }
12
+
13
+ if (!programs.every(p => p instanceof Program)) {
14
+ throw new Error('"programs" must be an array of Programs')
15
+ }
16
+
17
+ if (!isDate(date)) {
18
+ throw new Error('"date" must be a valid date')
19
+ }
20
+
7
21
  let output = `<?xml version="1.0" encoding="UTF-8" ?>`
8
22
  output += createElements(channels, programs, date)
9
23
 
@@ -1,10 +1,11 @@
1
1
  import Channel from '../src/Channel'
2
2
  import Program from '../src/Program'
3
3
 
4
- const channel = new Channel({ xmltv_id: '1tv', lang: 'en' })
4
+ const channel = new Channel({ xmltv_id: '1tv', lang: 'en', site: 'example.com' })
5
5
 
6
6
  it('can create new Program', () => {
7
7
  const program = new Program({
8
+ site: channel.site,
8
9
  channel: channel.id,
9
10
  title: 'Title',
10
11
  sub_title: 'Subtitle',
@@ -48,6 +49,7 @@ it('can create new Program', () => {
48
49
  })
49
50
 
50
51
  expect(program).toMatchObject({
52
+ site: 'example.com',
51
53
  channel: '1tv',
52
54
  title: 'Title',
53
55
  sub_title: 'Subtitle',