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
6108d6b645
commit
62c69407b8
1 changed files with 18 additions and 7 deletions
|
@ -2,8 +2,11 @@ const fs = require('fs')
|
||||||
const glob = require('glob')
|
const glob = require('glob')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const convert = require('xml-js')
|
const convert = require('xml-js')
|
||||||
|
const axios = require('axios')
|
||||||
|
|
||||||
|
async function main() {
|
||||||
|
const iptvChannels = await axios.get('https://iptv-org.github.io/iptv/channels.json').then(response => response.data).catch(console.log)
|
||||||
|
|
||||||
function main() {
|
|
||||||
let codes = {}
|
let codes = {}
|
||||||
console.log('Starting...')
|
console.log('Starting...')
|
||||||
glob('sites/**/*.xml', null, function (er, files) {
|
glob('sites/**/*.xml', null, function (er, files) {
|
||||||
|
@ -11,17 +14,25 @@ function main() {
|
||||||
const channels = parseChannels(filename)
|
const channels = parseChannels(filename)
|
||||||
channels.forEach(channel => {
|
channels.forEach(channel => {
|
||||||
if (!codes[channel.xmltv_id + channel.name]) {
|
if (!codes[channel.xmltv_id + channel.name]) {
|
||||||
|
let logo = channel.logo || ''
|
||||||
|
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] = {
|
codes[channel.xmltv_id + channel.name] = {
|
||||||
name: channel.name,
|
display_name: channel.name,
|
||||||
code: channel.xmltv_id
|
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.name.toLowerCase() < b.name.toLowerCase()) return -1
|
if (a.display_name.toLowerCase() < b.display_name.toLowerCase()) return -1
|
||||||
if (a.name.toLowerCase() > b.name.toLowerCase()) return 1
|
if (a.display_name.toLowerCase() > b.display_name.toLowerCase()) return 1
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
writeToFile('codes.csv', convertToCSV(sorted))
|
writeToFile('codes.csv', convertToCSV(sorted))
|
||||||
|
@ -40,9 +51,9 @@ function writeToFile(filename, data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToCSV(arr) {
|
function convertToCSV(arr) {
|
||||||
let string = 'Channel Name,EPG Code (tvg-id)\n'
|
let string = 'display_name,tvg_id,country,logo\n'
|
||||||
for (const item of arr) {
|
for (const item of arr) {
|
||||||
string += `${item.name},${item.code}\n`
|
string += `${item.display_name},${item.tvg_id},${item.country},${item.logo}\n`
|
||||||
}
|
}
|
||||||
|
|
||||||
return string
|
return string
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue