Add url tag to output

This commit is contained in:
Aleksandr Statciuk 2021-09-22 17:12:26 +03:00
parent 287bb4f71b
commit d49333a9a9
2 changed files with 7 additions and 3 deletions

View File

@ -110,8 +110,8 @@ utils.escapeString = function (string, defaultValue = '') {
}
utils.convertToXMLTV = function ({ config, channels, programs }) {
const url = config.site ? 'https://' + config.site : null
let output = `<?xml version="1.0" encoding="UTF-8" ?><tv>\r\n`
for (let channel of channels) {
const id = this.escapeString(channel['xmltv_id'])
const displayName = this.escapeString(channel.name)
@ -120,6 +120,9 @@ utils.convertToXMLTV = function ({ config, channels, programs }) {
const logo = this.escapeString(channel.logo)
output += `<icon src="${logo}"/>`
}
if (url) {
output += `<url>${url}</url>`
}
output += `</channel>\r\n`
}

View File

@ -61,9 +61,10 @@ it('can convert object to xmltv string', () => {
lang: 'it'
}
]
const output = utils.convertToXMLTV({ channels, programs })
const config = { site: 'example.com' }
const output = utils.convertToXMLTV({ config, 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"/></channel>\r\n<channel id="2TV.com"><display-name>2 TV</display-name></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=шеллы&amp;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><icon src="https://example.com/images/Program1.png?x=шеллы&amp;sid=777"/></programme>\r\n</tv>'
)
})