mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Create parser.js
This commit is contained in:
parent
a3133a2b26
commit
3d27fd729d
1 changed files with 30 additions and 0 deletions
30
scripts/parser.js
Normal file
30
scripts/parser.js
Normal file
|
@ -0,0 +1,30 @@
|
|||
const convert = require('xml-js')
|
||||
|
||||
const parser = {}
|
||||
|
||||
parser.parseChannels = function (xml) {
|
||||
const result = convert.xml2js(xml)
|
||||
const siteTag = result.elements.find(el => el.name === 'site')
|
||||
const channelsTags = siteTag.elements.filter(el => el.name === 'channels')
|
||||
|
||||
let output = []
|
||||
|
||||
channelsTags.forEach(channelsTag => {
|
||||
const channels = channelsTag.elements
|
||||
.filter(el => el.name === 'channel')
|
||||
.map(el => {
|
||||
const channel = el.attributes
|
||||
if (!el.elements) throw new Error(`Channel '${channel.xmltv_id}' has no valid name`)
|
||||
channel.name = el.elements.find(el => el.type === 'text').text
|
||||
channel.country = channelsTag.attributes.country
|
||||
channel.site = siteTag.attributes.site
|
||||
|
||||
return channel
|
||||
})
|
||||
output = output.concat(channels)
|
||||
})
|
||||
|
||||
return output
|
||||
}
|
||||
|
||||
module.exports = parser
|
Loading…
Add table
Add a link
Reference in a new issue