mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Update update-codes.js
This commit is contained in:
parent
612001a43c
commit
0ad1d5099d
1 changed files with 63 additions and 42 deletions
|
@ -5,30 +5,52 @@ const convert = require('xml-js')
|
||||||
const axios = require('axios')
|
const axios = require('axios')
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
const iptvChannels = await axios.get('https://iptv-org.github.io/iptv/channels.json').then(response => response.data).catch(console.log)
|
|
||||||
|
|
||||||
let codes = {}
|
let codes = {}
|
||||||
console.log('Starting...')
|
console.log('Starting...')
|
||||||
glob('sites/**/*.xml', null, function (er, files) {
|
const files = [
|
||||||
files.forEach(filename => {
|
'telkussa.fi',
|
||||||
const channels = parseChannels(filename)
|
'andorradifusio.ad',
|
||||||
|
'mediaset.it',
|
||||||
|
'znbc.co.zm',
|
||||||
|
'hd-plus.de',
|
||||||
|
'astro.com.my',
|
||||||
|
'comteco.com.bo',
|
||||||
|
'mi.tv',
|
||||||
|
'meo.pt',
|
||||||
|
'tvgid.ua',
|
||||||
|
'm.tv.sms.cz',
|
||||||
|
'cosmote.gr',
|
||||||
|
'programetv.ro',
|
||||||
|
'programtv.onet.pl',
|
||||||
|
'digiturk.com.tr',
|
||||||
|
'programme-tv.net',
|
||||||
|
'programacion-tv.elpais.com',
|
||||||
|
'guidatv.sky.it',
|
||||||
|
'ontvtonight.com',
|
||||||
|
'tv.yandex.ru',
|
||||||
|
'tvtv.ca',
|
||||||
|
'tvtv.us',
|
||||||
|
'tv.lv',
|
||||||
|
'elcinema.com',
|
||||||
|
'maxtv.hrvatskitelekom.hr',
|
||||||
|
'mncvision.id',
|
||||||
|
'tvguide.com',
|
||||||
|
'tvprofil.com'
|
||||||
|
]
|
||||||
|
for (const filename of files) {
|
||||||
|
const url = `https://iptv-org.github.io/epg/guides/${filename}.guide.xml`
|
||||||
|
console.log(`Loading '${url}'...`)
|
||||||
|
const file = await axios
|
||||||
|
.get(url)
|
||||||
|
.then(r => r.data)
|
||||||
|
.catch(console.log)
|
||||||
|
const channels = parseChannels(file)
|
||||||
channels.forEach(channel => {
|
channels.forEach(channel => {
|
||||||
if (!codes[channel.xmltv_id + channel.name]) {
|
if (!codes[channel.tvg_id + channel.display_name]) {
|
||||||
let logo = channel.logo || ''
|
codes[channel.tvg_id + channel.display_name] = channel
|
||||||
if(!logo) {
|
|
||||||
let ch = iptvChannels.find(ch => ch.tvg.id === channel.xmltv_id)
|
|
||||||
if(ch && ch.logo) logo = ch.logo
|
|
||||||
}
|
|
||||||
|
|
||||||
codes[channel.xmltv_id + channel.name] = {
|
|
||||||
display_name: channel.name,
|
|
||||||
tvg_id: channel.xmltv_id,
|
|
||||||
country: channel.xmltv_id.split('.')[1],
|
|
||||||
logo,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
const sorted = Object.values(codes).sort((a, b) => {
|
const sorted = Object.values(codes).sort((a, b) => {
|
||||||
if (a.display_name.toLowerCase() < b.display_name.toLowerCase()) return -1
|
if (a.display_name.toLowerCase() < b.display_name.toLowerCase()) return -1
|
||||||
|
@ -36,9 +58,7 @@ async function main() {
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
writeToFile('codes.json', convertToJSON(sorted))
|
writeToFile('codes.json', convertToJSON(sorted))
|
||||||
// writeToFile('codes.csv', convertToCSV(sorted))
|
|
||||||
console.log('Done')
|
console.log('Done')
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function writeToFile(filename, data) {
|
function writeToFile(filename, data) {
|
||||||
|
@ -64,22 +84,23 @@ function convertToCSV(arr) {
|
||||||
return string
|
return string
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseChannels(filename) {
|
function parseChannels(file) {
|
||||||
if (!filename) throw new Error('Path to [site].channels.xml is missing')
|
const result = convert.xml2js(file)
|
||||||
console.log(`Loading '${filename}'...`)
|
const tv = result.elements.find(el => el.name === 'tv')
|
||||||
|
|
||||||
const xml = fs.readFileSync(path.resolve(filename), { encoding: 'utf-8' })
|
return tv.elements
|
||||||
const result = convert.xml2js(xml)
|
|
||||||
const site = result.elements.find(el => el.name === 'site')
|
|
||||||
const channels = site.elements.find(el => el.name === 'channels')
|
|
||||||
|
|
||||||
return channels.elements
|
|
||||||
.filter(el => el.name === 'channel')
|
.filter(el => el.name === 'channel')
|
||||||
.map(el => {
|
.map(channel => {
|
||||||
const channel = el.attributes
|
const tvg_id = (channel.attributes || { id: '' }).id
|
||||||
channel.name = el.elements.find(el => el.type === 'text').text
|
const logo = (channel.elements.find(el => el.name === 'icon') || { attributes: { src: '' } })
|
||||||
|
.attributes.src
|
||||||
|
const displayName = channel.elements.find(el => el.name === 'display-name')
|
||||||
|
const display_name = displayName
|
||||||
|
? displayName.elements.find(el => el.type === 'text').text
|
||||||
|
: null
|
||||||
|
const country = tvg_id.split('.')[1]
|
||||||
|
|
||||||
return channel
|
return { tvg_id, logo, display_name, country }
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue