epg-grabber 0.25.0 → 0.25.3

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.25.0",
3
+ "version": "0.25.3",
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/utils.js CHANGED
@@ -70,9 +70,10 @@ utils.createClient = function (config) {
70
70
  client.interceptors.response.use(
71
71
  function (response) {
72
72
  if (config.debug) {
73
- const data = utils.isObject(response.data)
74
- ? JSON.stringify(response.data)
75
- : response.data.toString()
73
+ const data =
74
+ utils.isObject(response.data) || Array.isArray(response.data)
75
+ ? JSON.stringify(response.data)
76
+ : response.data.toString()
76
77
  console.log(
77
78
  'Response:',
78
79
  JSON.stringify(
@@ -219,13 +220,15 @@ utils.convertToXMLTV = function ({ channels, programs }) {
219
220
  output += '</tv>'
220
221
 
221
222
  function createXMLTVNS(s, e) {
222
- if (!s || !e) return null
223
+ if (!s && !e) return null
224
+ s = s || 1
223
225
 
224
226
  return `${s - 1}.${e - 1}.0/1`
225
227
  }
226
228
 
227
229
  function createOnScreen(s, e) {
228
- if (!s || !e) return null
230
+ if (!s && !e) return null
231
+ s = s || 1
229
232
 
230
233
  s = padStart(s, 2, '0')
231
234
  e = padStart(e, 2, '0')
@@ -315,10 +318,15 @@ utils.getUTCDate = function (d = null) {
315
318
  }
316
319
 
317
320
  utils.parseResponse = async (item, response, config) => {
318
- const content = utils.isObject(response.data)
319
- ? JSON.stringify(response.data)
320
- : response.data.toString()
321
- const buffer = Buffer.from(content, 'utf8')
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
+ }
322
330
  const data = merge(item, config, {
323
331
  content,
324
332
  buffer,
@@ -73,6 +73,28 @@ it('can convert object to xmltv string', () => {
73
73
  )
74
74
  })
75
75
 
76
+ it('can convert object to xmltv string without season number', () => {
77
+ const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
78
+ const { channels } = utils.parseChannels(file)
79
+ const programs = [
80
+ {
81
+ title: 'Program 1',
82
+ description: 'Description for Program 1',
83
+ start: 1616133600,
84
+ stop: 1616135400,
85
+ category: 'Test',
86
+ episode: 239,
87
+ icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
88
+ channel: '1TV.com',
89
+ lang: 'it'
90
+ }
91
+ ]
92
+ const output = utils.convertToXMLTV({ channels, programs })
93
+ expect(output).toBe(
94
+ '<?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">0.238.0/1</episode-num><episode-num system="onscreen">S01E239</episode-num><icon src="https://example.com/images/Program1.png?x=шеллы&amp;sid=777"/></programme>\r\n</tv>'
95
+ )
96
+ })
97
+
76
98
  it('can convert object to xmltv string without categories', () => {
77
99
  const channels = [
78
100
  {