Renamed channel.id to channel.xmltv_id
This commit is contained in:
parent
19d206c11c
commit
d5ed0a35ee
|
@ -1,23 +1,23 @@
|
||||||
class Channel {
|
class Channel {
|
||||||
constructor(c) {
|
constructor(c) {
|
||||||
const data = {
|
const data = {
|
||||||
id: c.id || c.xmltv_id,
|
xmltv_id: c.xmltv_id,
|
||||||
name: c.name,
|
name: c.name,
|
||||||
site: c.site || '',
|
site: c.site || '',
|
||||||
site_id: c.site_id,
|
site_id: c.site_id,
|
||||||
lang: c.lang || '',
|
lang: c.lang || '',
|
||||||
logo: c.logo || '',
|
logo: c.logo || '',
|
||||||
url: c.url || toURL(c.site)
|
url: c.url || toURL(c.site)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let key in data) {
|
for (let key in data) {
|
||||||
this[key] = data[key]
|
this[key] = data[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Channel
|
module.exports = Channel
|
||||||
|
|
||||||
function toURL(site) {
|
function toURL(site) {
|
||||||
return site ? `https://${site}` : ''
|
return site ? `https://${site}` : ''
|
||||||
}
|
}
|
||||||
|
|
190
src/Program.js
190
src/Program.js
|
@ -3,140 +3,140 @@ const { toArray, toUnix, parseNumber } = require('./utils')
|
||||||
const Channel = require('./Channel')
|
const Channel = require('./Channel')
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
constructor(p, c) {
|
constructor(p, c) {
|
||||||
if (!(c instanceof Channel)) {
|
if (!(c instanceof Channel)) {
|
||||||
throw new Error('The second argument in the constructor must be the "Channel" class')
|
throw new Error('The second argument in the constructor must be the "Channel" class')
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
site: c.site || '',
|
site: c.site || '',
|
||||||
channel: c.id || '',
|
channel: c.xmltv_id || '',
|
||||||
titles: toArray(p.titles || p.title).map(text => toTextObject(text, c.lang)),
|
titles: toArray(p.titles || p.title).map(text => toTextObject(text, c.lang)),
|
||||||
sub_titles: toArray(p.sub_titles || p.sub_title).map(text => toTextObject(text, c.lang)),
|
sub_titles: toArray(p.sub_titles || p.sub_title).map(text => toTextObject(text, c.lang)),
|
||||||
descriptions: toArray(p.descriptions || p.description || p.desc).map(text =>
|
descriptions: toArray(p.descriptions || p.description || p.desc).map(text =>
|
||||||
toTextObject(text, c.lang)
|
toTextObject(text, c.lang)
|
||||||
),
|
),
|
||||||
icon: toIconObject(p.icon),
|
icon: toIconObject(p.icon),
|
||||||
episodeNumbers: p.episodeNum || p.episodeNumbers || getEpisodeNumbers(p.season, p.episode),
|
episodeNumbers: p.episodeNum || p.episodeNumbers || getEpisodeNumbers(p.season, p.episode),
|
||||||
date: p.date ? toUnix(p.date) : null,
|
date: p.date ? toUnix(p.date) : null,
|
||||||
start: p.start ? toUnix(p.start) : null,
|
start: p.start ? toUnix(p.start) : null,
|
||||||
stop: p.stop ? toUnix(p.stop) : null,
|
stop: p.stop ? toUnix(p.stop) : null,
|
||||||
urls: toArray(p.urls || p.url).map(toUrlObject),
|
urls: toArray(p.urls || p.url).map(toUrlObject),
|
||||||
ratings: toArray(p.ratings || p.rating).map(toRatingObject),
|
ratings: toArray(p.ratings || p.rating).map(toRatingObject),
|
||||||
categories: toArray(p.categories || p.category).map(text => toTextObject(text, c.lang)),
|
categories: toArray(p.categories || p.category).map(text => toTextObject(text, c.lang)),
|
||||||
directors: toArray(p.directors || p.director).map(toPersonObject),
|
directors: toArray(p.directors || p.director).map(toPersonObject),
|
||||||
actors: toArray(p.actors || p.actor).map(toPersonObject),
|
actors: toArray(p.actors || p.actor).map(toPersonObject),
|
||||||
writers: toArray(p.writers || p.writer).map(toPersonObject),
|
writers: toArray(p.writers || p.writer).map(toPersonObject),
|
||||||
adapters: toArray(p.adapters || p.adapter).map(toPersonObject),
|
adapters: toArray(p.adapters || p.adapter).map(toPersonObject),
|
||||||
producers: toArray(p.producers || p.producer).map(toPersonObject),
|
producers: toArray(p.producers || p.producer).map(toPersonObject),
|
||||||
composers: toArray(p.composers || p.composer).map(toPersonObject),
|
composers: toArray(p.composers || p.composer).map(toPersonObject),
|
||||||
editors: toArray(p.editors || p.editor).map(toPersonObject),
|
editors: toArray(p.editors || p.editor).map(toPersonObject),
|
||||||
presenters: toArray(p.presenters || p.presenter).map(toPersonObject),
|
presenters: toArray(p.presenters || p.presenter).map(toPersonObject),
|
||||||
commentators: toArray(p.commentators || p.commentator).map(toPersonObject),
|
commentators: toArray(p.commentators || p.commentator).map(toPersonObject),
|
||||||
guests: toArray(p.guests || p.guest).map(toPersonObject)
|
guests: toArray(p.guests || p.guest).map(toPersonObject)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let key in data) {
|
for (let key in data) {
|
||||||
this[key] = data[key]
|
this[key] = data[key]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Program
|
module.exports = Program
|
||||||
|
|
||||||
function toTextObject(text, lang) {
|
function toTextObject(text, lang) {
|
||||||
if (typeof text === 'string') {
|
if (typeof text === 'string') {
|
||||||
return { value: text, lang }
|
return { value: text, lang }
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: text.value,
|
value: text.value,
|
||||||
lang: text.lang
|
lang: text.lang
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toPersonObject(person) {
|
function toPersonObject(person) {
|
||||||
if (typeof person === 'string') {
|
if (typeof person === 'string') {
|
||||||
return {
|
return {
|
||||||
value: person,
|
value: person,
|
||||||
url: [],
|
url: [],
|
||||||
image: []
|
image: []
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: person.value,
|
value: person.value,
|
||||||
url: toArray(person.url).map(toUrlObject),
|
url: toArray(person.url).map(toUrlObject),
|
||||||
image: toArray(person.image).map(toImageObject)
|
image: toArray(person.image).map(toImageObject)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toImageObject(image) {
|
function toImageObject(image) {
|
||||||
if (typeof image === 'string') return { type: '', size: '', orient: '', system: '', value: image }
|
if (typeof image === 'string') return { type: '', size: '', orient: '', system: '', value: image }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: image.type || '',
|
type: image.type || '',
|
||||||
size: image.size || '',
|
size: image.size || '',
|
||||||
orient: image.orient || '',
|
orient: image.orient || '',
|
||||||
system: image.system || '',
|
system: image.system || '',
|
||||||
value: image.value
|
value: image.value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toRatingObject(rating) {
|
function toRatingObject(rating) {
|
||||||
if (typeof rating === 'string') return { system: '', icon: '', value: rating }
|
if (typeof rating === 'string') return { system: '', icon: '', value: rating }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
system: rating.system || '',
|
system: rating.system || '',
|
||||||
icon: rating.icon || '',
|
icon: rating.icon || '',
|
||||||
value: rating.value || ''
|
value: rating.value || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toUrlObject(url) {
|
function toUrlObject(url) {
|
||||||
if (typeof url === 'string') return { system: '', value: url }
|
if (typeof url === 'string') return { system: '', value: url }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
system: url.system || '',
|
system: url.system || '',
|
||||||
value: url.value || ''
|
value: url.value || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function toIconObject(icon) {
|
function toIconObject(icon) {
|
||||||
if (!icon) return { src: '' }
|
if (!icon) return { src: '' }
|
||||||
if (typeof icon === 'string') return { src: icon }
|
if (typeof icon === 'string') return { src: icon }
|
||||||
|
|
||||||
return {
|
return {
|
||||||
src: icon.src || ''
|
src: icon.src || ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEpisodeNumbers(s, e) {
|
function getEpisodeNumbers(s, e) {
|
||||||
s = parseNumber(s)
|
s = parseNumber(s)
|
||||||
e = parseNumber(e)
|
e = parseNumber(e)
|
||||||
|
|
||||||
return [createXMLTVNS(s, e), createOnScreen(s, e)].filter(Boolean)
|
return [createXMLTVNS(s, e), createOnScreen(s, e)].filter(Boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createXMLTVNS(s, e) {
|
function createXMLTVNS(s, e) {
|
||||||
if (!e) return null
|
if (!e) return null
|
||||||
s = s || 1
|
s = s || 1
|
||||||
|
|
||||||
return {
|
return {
|
||||||
system: 'xmltv_ns',
|
system: 'xmltv_ns',
|
||||||
value: `${s - 1}.${e - 1}.0/1`
|
value: `${s - 1}.${e - 1}.0/1`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function createOnScreen(s, e) {
|
function createOnScreen(s, e) {
|
||||||
if (!e) return null
|
if (!e) return null
|
||||||
s = s || 1
|
s = s || 1
|
||||||
|
|
||||||
s = padStart(s, 2, '0')
|
s = padStart(s, 2, '0')
|
||||||
e = padStart(e, 2, '0')
|
e = padStart(e, 2, '0')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
system: 'onscreen',
|
system: 'onscreen',
|
||||||
value: `S${s}E${e}`
|
value: `S${s}E${e}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ function createElements(channels, programs, date) {
|
||||||
...channels.map(channel => {
|
...channels.map(channel => {
|
||||||
return (
|
return (
|
||||||
'\r\n' +
|
'\r\n' +
|
||||||
el('channel', { id: channel.id }, [
|
el('channel', { id: channel.xmltv_id }, [
|
||||||
el('display-name', {}, [escapeString(channel.name)]),
|
el('display-name', {}, [escapeString(channel.name)]),
|
||||||
el('icon', { src: channel.logo }),
|
el('icon', { src: channel.logo }),
|
||||||
el('url', {}, [channel.url])
|
el('url', {}, [channel.url])
|
||||||
|
|
|
@ -12,28 +12,7 @@ it('can create new Channel', () => {
|
||||||
|
|
||||||
expect(channel).toMatchObject({
|
expect(channel).toMatchObject({
|
||||||
name: '1 TV',
|
name: '1 TV',
|
||||||
id: '1TV.com',
|
xmltv_id: '1TV.com',
|
||||||
site_id: '1',
|
|
||||||
site: 'example.com',
|
|
||||||
url: 'https://example.com',
|
|
||||||
lang: 'fr',
|
|
||||||
logo: 'https://example.com/logos/1TV.png'
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
it('can create channel from exist object', () => {
|
|
||||||
const channel = new Channel({
|
|
||||||
name: '1 TV',
|
|
||||||
id: '1TV.com',
|
|
||||||
site_id: '1',
|
|
||||||
site: 'example.com',
|
|
||||||
lang: 'fr',
|
|
||||||
logo: 'https://example.com/logos/1TV.png'
|
|
||||||
})
|
|
||||||
|
|
||||||
expect(channel).toMatchObject({
|
|
||||||
name: '1 TV',
|
|
||||||
id: '1TV.com',
|
|
||||||
site_id: '1',
|
site_id: '1',
|
||||||
site: 'example.com',
|
site: 'example.com',
|
||||||
url: 'https://example.com',
|
url: 'https://example.com',
|
||||||
|
|
|
@ -71,7 +71,7 @@ it('can produce multiple outputs', () => {
|
||||||
`node ${pwd}/bin/epg-grabber.js \
|
`node ${pwd}/bin/epg-grabber.js \
|
||||||
--config=tests/__data__/input/mini.config.js \
|
--config=tests/__data__/input/mini.config.js \
|
||||||
--channels=tests/__data__/input/example.channels.xml \
|
--channels=tests/__data__/input/example.channels.xml \
|
||||||
--output=tests/__data__/output/{lang}/{id}.xml`,
|
--output=tests/__data__/output/{lang}/{xmltv_id}.xml`,
|
||||||
{
|
{
|
||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue