Update utils.js
This commit is contained in:
parent
bb03f6e464
commit
e220cf828e
28
src/utils.js
28
src/utils.js
|
@ -1,10 +1,11 @@
|
|||
const fs = require('fs')
|
||||
const { padStart } = require('lodash')
|
||||
const path = require('path')
|
||||
const axios = require('axios').default
|
||||
const axiosCookieJarSupport = require('axios-cookiejar-support').default
|
||||
const tough = require('tough-cookie')
|
||||
const convert = require('xml-js')
|
||||
const merge = require('lodash.merge')
|
||||
const { merge } = require('lodash')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
dayjs.extend(utc)
|
||||
|
@ -126,6 +127,8 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|||
const start = program.start ? dayjs.unix(program.start).utc().format('YYYYMMDDHHmmss ZZ') : ''
|
||||
const stop = program.stop ? dayjs.unix(program.stop).utc().format('YYYYMMDDHHmmss ZZ') : ''
|
||||
const lang = program.lang || 'en'
|
||||
const xmltv_ns = createXMLTVNS(program.season, program.episode)
|
||||
const onscreen = createOnScreen(program.season, program.episode)
|
||||
const icon = utils.escapeString(program.icon)
|
||||
|
||||
if (start && stop && title) {
|
||||
|
@ -143,6 +146,14 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|||
})
|
||||
}
|
||||
|
||||
if (xmltv_ns) {
|
||||
output += `<episode-num system="xmltv_ns">${xmltv_ns}</episode-num>`
|
||||
}
|
||||
|
||||
if (onscreen) {
|
||||
output += `<episode-num system="onscreen">${onscreen}</episode-num>`
|
||||
}
|
||||
|
||||
if (icon) {
|
||||
output += `<icon src="${icon}"/>`
|
||||
}
|
||||
|
@ -153,6 +164,21 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|||
|
||||
output += '</tv>'
|
||||
|
||||
function createXMLTVNS(s, e) {
|
||||
if (!s || !e) return null
|
||||
|
||||
return `${s - 1}.${e - 1}.0/1`
|
||||
}
|
||||
|
||||
function createOnScreen(s, e) {
|
||||
if (!s || !e) return null
|
||||
|
||||
s = padStart(s, 2, '0')
|
||||
e = padStart(e, 2, '0')
|
||||
|
||||
return `S${s}E${e}`
|
||||
}
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
|
|
|
@ -60,6 +60,8 @@ it('can convert object to xmltv string', () => {
|
|||
start: 1616133600,
|
||||
stop: 1616135400,
|
||||
category: 'Test',
|
||||
season: 9,
|
||||
episode: 239,
|
||||
icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
|
||||
channel: '1TV.com',
|
||||
lang: 'it'
|
||||
|
@ -67,7 +69,7 @@ it('can convert object to xmltv string', () => {
|
|||
]
|
||||
const output = utils.convertToXMLTV({ channels, programs })
|
||||
expect(output).toBe(
|
||||
'<?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>'
|
||||
'<?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>'
|
||||
)
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue