Added support lang and logo attributes to channels.xml

This commit is contained in:
freearhey 2021-04-01 04:48:30 +03:00
parent 2d46c8ca87
commit 4ccbe0a7e6
3 changed files with 23 additions and 30 deletions

View File

@ -38,13 +38,13 @@ async function main() {
const progs = await client const progs = await client
.get(url) .get(url)
.then(response => { .then(response => {
item.channel.logo = config.logo if (!item.channel.logo && config.logo) {
? config.logo({ item.channel.logo = config.logo({
channel: item.channel, channel: item.channel,
content: response.data.toString(), content: response.data.toString(),
buffer: response.data buffer: response.data
}) })
: null }
const programs = utils.parsePrograms({ response, item, config }) const programs = utils.parsePrograms({ response, item, config })
console.log( console.log(
@ -54,7 +54,10 @@ async function main() {
) )
if (options.debug) console.timeEnd(' time') if (options.debug) console.timeEnd(' time')
return programs return programs.map(program => {
program.lang = program.lang || item.channel.lang || undefined
return program
})
}) })
.then(utils.sleep(config.delay)) .then(utils.sleep(config.delay))
.catch(err => { .catch(err => {

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<site site="example.com"> <site site="example.com">
<channels> <channels>
<channel site_id="1" xmltv_id="1TV.com">1 TV</channel> <channel site_id="1" xmltv_id="1TV.com" lang="fr" logo="https://example.com/logos/1TV.png">1 TV</channel>
<channel site_id="2" xmltv_id="2TV.com">2 TV</channel> <channel site_id="2" xmltv_id="2TV.com">2 TV</channel>
</channels> </channels>
</site> </site>

View File

@ -25,34 +25,23 @@ it('can parse valid channels.xml', () => {
name: '1 TV', name: '1 TV',
xmltv_id: '1TV.com', xmltv_id: '1TV.com',
site_id: '1', site_id: '1',
site: 'example.com' site: 'example.com',
lang: 'fr',
logo: 'https://example.com/logos/1TV.png'
}, },
{ {
name: '2 TV', name: '2 TV',
xmltv_id: '2TV.com', xmltv_id: '2TV.com',
site_id: '2', site_id: '2',
site: 'example.com' site: 'example.com',
lang: undefined,
logo: undefined
} }
]) ])
}) })
it('can convert object to xmltv string', () => { it('can convert object to xmltv string', () => {
const config = { lang: 'en' } const channels = utils.parseChannels('./tests/input/example.com.channels.xml')
const channels = [
{
name: '1 TV',
xmltv_id: '1TV.com',
site_id: '1',
site: 'example.com',
logo: 'http://example.com/logos/1TV.png'
},
{
name: '2 TV',
xmltv_id: '2TV.com',
site_id: '2',
site: 'example.com'
}
]
const programs = [ const programs = [
{ {
title: 'Program 1', title: 'Program 1',
@ -60,12 +49,13 @@ it('can convert object to xmltv string', () => {
start: '2021-03-19 06:00:00 +0000', start: '2021-03-19 06:00:00 +0000',
stop: '2021-03-19 06:30:00 +0000', stop: '2021-03-19 06:30:00 +0000',
category: 'Test', category: 'Test',
channel: '1TV.com' channel: '1TV.com',
lang: 'it'
} }
] ]
const output = utils.convertToXMLTV({ config, channels, programs }) const output = utils.convertToXMLTV({ channels, programs })
expect(output).toBe( 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="http://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="en">Program 1</title><desc lang="en">Description for Program 1</desc><category lang="en">Test</category></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" /></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></programme>\r\n</tv>'
) )
}) })