Add actor attributes and url object
This commit is contained in:
parent
d2a06a20d5
commit
22b2e9c19e
45
src/utils.js
45
src/utils.js
|
@ -150,7 +150,7 @@ utils.escapeString = function (string, defaultValue = '') {
|
|||
}
|
||||
|
||||
utils.convertToXMLTV = function ({ channels, programs }) {
|
||||
let output = `<?xml version="1.0" encoding="UTF-8" ?><tv date="${dayjs.utc().format('YYYYMMDDHHmmss ZZ')}">\r\n`
|
||||
let output = `<?xml version="1.0" encoding="UTF-8" ?><tv date="${dayjs.utc().format('YYYYMMDD')}">\r\n`
|
||||
for (let channel of channels) {
|
||||
const id = utils.escapeString(channel['xmltv_id'])
|
||||
const displayName = utils.escapeString(channel.name)
|
||||
|
@ -178,6 +178,7 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|||
const lang = program.lang || 'en'
|
||||
const xmltv_ns = createXMLTVNS(program.season, program.episode)
|
||||
const onscreen = createOnScreen(program.season, program.episode)
|
||||
const date = program.date || ''
|
||||
const credits = createCredits({'director':program.director,'actor':program.actor, 'writer':program.writer,'adapter':program.adapter,'producer':program.producer, 'composer':program.composer, 'editor':program.editor, 'presenter':program.presenter, 'commentator':program.commentator, 'guest':program.guest})
|
||||
const icon = utils.escapeString(program.icon)
|
||||
const sub_title = program.sub_title || ''
|
||||
|
@ -220,6 +221,9 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|||
if (onscreen) {
|
||||
output += `<episode-num system="onscreen">${onscreen}</episode-num>`
|
||||
}
|
||||
if (date) {
|
||||
output += `<date>${date}</date>`
|
||||
}
|
||||
|
||||
if (icon) {
|
||||
output += `<icon src="${icon}"/>`
|
||||
|
@ -254,13 +258,41 @@ utils.convertToXMLTV = function ({ channels, programs }) {
|
|||
|
||||
function createCredits(obj) {
|
||||
let cast = Object.entries(obj)
|
||||
.filter(([name, value]) => value !== null)
|
||||
.filter(([name, value]) => value)
|
||||
.map(([name, value]) => ({name, value}));
|
||||
let output = ''
|
||||
for(let role of cast){
|
||||
const r = Array.isArray(role.value) ? role.value: [role.value]
|
||||
for(let type of cast){
|
||||
const r = Array.isArray(type.value) ? type.value: [type.value]
|
||||
for(let person of r){
|
||||
output += `<${role.name}>${person}</${role.name}>`
|
||||
if (typeof person === 'string' || person instanceof String){
|
||||
person = {value: person}
|
||||
}
|
||||
|
||||
let attr = ''
|
||||
if(type.name.localeCompare('actor') === 0 && type.value.role){
|
||||
attr += ` role="${type.value.role}"`
|
||||
}
|
||||
if(type.name.localeCompare('actor') === 0 && type.value.guest){
|
||||
attr += ` guest="${type.value.guest}"`
|
||||
}
|
||||
output += `<${type.name}${attr}>${person.value}`
|
||||
|
||||
if(person.url){
|
||||
const r = Array.isArray(person.url) ? person.url: [person.url]
|
||||
for (let x of r){
|
||||
let attr = x.system ? ` system="${x.system}"` : ''
|
||||
output += `<url${attr}>${x.value}</url>`
|
||||
}
|
||||
}
|
||||
/*if (person.image){
|
||||
for (let x of person.image){
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
output += `</${type.name}>`
|
||||
}
|
||||
}
|
||||
return output
|
||||
|
@ -390,6 +422,7 @@ utils.parsePrograms = async function (data, config) {
|
|||
lang: program.lang || channel.lang || config.lang || 'en',
|
||||
start: program.start ? dayjs(program.start).unix() : null,
|
||||
stop: program.stop ? dayjs(program.stop).unix() : null,
|
||||
date: program.date || null,
|
||||
director: program.director || null,
|
||||
actor: program.actor || null,
|
||||
writer: program.writer || null,
|
||||
|
@ -420,4 +453,4 @@ utils.isObject = function (a) {
|
|||
return !!a && a.constructor === Object
|
||||
}
|
||||
|
||||
module.exports = utils
|
||||
module.exports = utils
|
||||
|
|
|
@ -56,7 +56,9 @@ it('can convert object to xmltv string', () => {
|
|||
const programs = [
|
||||
{
|
||||
title: 'Program 1',
|
||||
sub_title : 'Sub-title 1',
|
||||
description: 'Description for Program 1',
|
||||
url : 'http://example.com/title.html',
|
||||
start: 1616133600,
|
||||
stop: 1616135400,
|
||||
category: 'Test',
|
||||
|
@ -64,12 +66,16 @@ it('can convert object to xmltv string', () => {
|
|||
episode: 239,
|
||||
icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777',
|
||||
channel: '1TV.com',
|
||||
lang: 'it'
|
||||
lang: 'it',
|
||||
date: '20220505',
|
||||
director: {value:'Director 1', url:{value: 'http://example.com/director1.html', system: 'TestSystem'}},
|
||||
actor: ['Actor 1', 'Actor 2'],
|
||||
writer: 'Writer 1'
|
||||
}
|
||||
]
|
||||
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><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>'
|
||||
'<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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><sub-title>Sub-title 1</sub-title><desc lang="it">Description for Program 1</desc><category lang="it">Test</category><url>http://example.com/title.html</url><episode-num system="xmltv_ns">8.238.0/1</episode-num><episode-num system="onscreen">S09E239</episode-num><date>20220505</date><icon src="https://example.com/images/Program1.png?x=шеллы&sid=777"/><credits><director>Director 1<url system="TestSystem">http://example.com/director1.html</url></director><actor>Actor 1</actor><actor>Actor 2</actor><writer>Writer 1</writer></credits></programme>\r\n</tv>'
|
||||
)
|
||||
})
|
||||
|
||||
|
@ -91,7 +97,7 @@ it('can convert object to xmltv string without season number', () => {
|
|||
]
|
||||
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><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=шеллы&sid=777"/></programme>\r\n</tv>'
|
||||
'<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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=шеллы&sid=777"/></programme>\r\n</tv>'
|
||||
)
|
||||
})
|
||||
|
||||
|
@ -113,7 +119,7 @@ it('can convert object to xmltv string without episode number', () => {
|
|||
]
|
||||
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 date="20220505">\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>'
|
||||
)
|
||||
})
|
||||
|
||||
|
@ -140,7 +146,7 @@ it('can convert object to xmltv string without categories', () => {
|
|||
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"/><url>https://example.com</url></channel>\r\n<programme start="20210319060000 +0000" stop="20210319063000 +0000" channel="1TV.com"><title lang="it">Program 1</title></programme>\r\n</tv>'
|
||||
'<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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<programme start="20210319060000 +0000" stop="20210319063000 +0000" channel="1TV.com"><title lang="it">Program 1</title></programme>\r\n</tv>'
|
||||
)
|
||||
})
|
||||
|
||||
|
@ -161,7 +167,36 @@ it('can convert object to xmltv string with multiple categories', () => {
|
|||
]
|
||||
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">Test1</category><category lang="it">Test2</category><icon src="https://example.com/images/Program1.png?x=шеллы&sid=777"/></programme>\r\n</tv>'
|
||||
'<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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">Test1</category><category lang="it">Test2</category><icon src="https://example.com/images/Program1.png?x=шеллы&sid=777"/></programme>\r\n</tv>'
|
||||
)
|
||||
})
|
||||
|
||||
it('can convert object to xmltv string with multiple credits member', () => {
|
||||
const file = fs.readFileSync('./tests/input/example.com.channels.xml', { encoding: 'utf-8' })
|
||||
const { channels } = utils.parseChannels(file)
|
||||
const programs = [
|
||||
{
|
||||
title: 'Program 1',
|
||||
sub_title : 'Sub-title 1',
|
||||
description: 'Description for Program 1',
|
||||
url : 'http://example.com/title.html',
|
||||
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',
|
||||
date: '20220505',
|
||||
director: {value:'Director 1', url:{value: 'http://example.com/director1.html', system: 'TestSystem'}},
|
||||
actor: {value:'Actor 1', role:'Manny', guest:'yes', url:{value: 'http://example.com/actor1.html', system: 'TestSystem'}},
|
||||
writer: [{value:'Writer 1', url:{value: 'http://example.com/w1.html', system: 'TestSystem'}},{value:'Writer 2', url:{value: 'http://example.com/w2.html', system: 'TestSystem'}}]
|
||||
}
|
||||
]
|
||||
const output = utils.convertToXMLTV({ channels, programs })
|
||||
expect(output).toBe(
|
||||
'<?xml version="1.0" encoding="UTF-8" ?><tv date="20220505">\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><sub-title>Sub-title 1</sub-title><desc lang="it">Description for Program 1</desc><category lang="it">Test</category><url>http://example.com/title.html</url><episode-num system="xmltv_ns">8.238.0/1</episode-num><episode-num system="onscreen">S09E239</episode-num><date>20220505</date><icon src="https://example.com/images/Program1.png?x=шеллы&sid=777"/><credits><director>Director 1<url system="TestSystem">http://example.com/director1.html</url></director><actor role="Manny" guest="yes">Actor 1<url system="TestSystem">http://example.com/actor1.html</url></actor><writer>Writer 1<url system="TestSystem">http://example.com/w1.html</url></writer><writer>Writer 2<url system="TestSystem">http://example.com/w2.html</url></writer></credits></programme>\r\n</tv>'
|
||||
)
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue