mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
Update update-readme.js
This commit is contained in:
parent
df3bb4014d
commit
c24d5ab092
1 changed files with 38 additions and 40 deletions
|
@ -2,15 +2,39 @@ const markdownInclude = require('markdown-include')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const countries = require('./countries.json')
|
const countries = require('./countries.json')
|
||||||
const file = require('./file.js')
|
const parser = require('./parser')
|
||||||
|
const file = require('./file')
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log('Starting...')
|
console.log('Starting...')
|
||||||
file
|
file
|
||||||
.list('channels/**/*.xml', [], ['us-local'])
|
.list('sites/*.channels.xml')
|
||||||
.then(files => {
|
.then(files => {
|
||||||
files = files.map(str => str.match(/channels\/(.*).xml/i)[1])
|
let data = []
|
||||||
generateTable(files)
|
files.forEach(filename => {
|
||||||
|
const channelsFile = file.read(filename)
|
||||||
|
const parsed = parser.parseChannels(channelsFile)
|
||||||
|
parsed.groups.forEach(group => {
|
||||||
|
const country = countries.find(c => c.code === group.country.toLowerCase())
|
||||||
|
data.push({
|
||||||
|
countryFlag: country.flag,
|
||||||
|
countryName: country.name,
|
||||||
|
guideUrl: `https://iptv-org.github.io/epg/guides/${country.code}/${parsed.site}.epg.xml`,
|
||||||
|
channelCount: group.channels.length
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
data = data.sort((a, b) => {
|
||||||
|
var nameA = a.countryName.toLowerCase()
|
||||||
|
var nameB = b.countryName.toLowerCase()
|
||||||
|
if (nameA < nameB) return -1
|
||||||
|
if (nameA > nameB) return 1
|
||||||
|
return b.channelCount - a.channelCount
|
||||||
|
})
|
||||||
|
|
||||||
|
const table = generateTable(data, ['Country', 'Channels', 'EPG'])
|
||||||
|
file.write('./.readme/_table.md', table)
|
||||||
generateReadme()
|
generateReadme()
|
||||||
})
|
})
|
||||||
.finally(() => {
|
.finally(() => {
|
||||||
|
@ -18,50 +42,24 @@ async function main() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateTable(files) {
|
function generateTable(data, header) {
|
||||||
console.log('Generating countries table...')
|
|
||||||
|
|
||||||
const output = []
|
|
||||||
for (const country of countries) {
|
|
||||||
if (files.includes(country.code)) {
|
|
||||||
output.push({
|
|
||||||
country: `${country.flag} ${country.name}`,
|
|
||||||
guide: `<code>https://iptv-org.github.io/epg/guides/${country.code}.xml</code>`
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const table = generateHtmlTable(output, {
|
|
||||||
columns: [
|
|
||||||
{ name: 'Country', align: 'left', nowrap: true },
|
|
||||||
{ name: 'EPG', align: 'left', nowrap: true }
|
|
||||||
]
|
|
||||||
})
|
|
||||||
|
|
||||||
fs.writeFileSync(path.resolve('./.readme/_table.md'), table)
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateHtmlTable(data, options) {
|
|
||||||
let output = '<table>\n'
|
let output = '<table>\n'
|
||||||
|
|
||||||
output += '\t<thead>\n\t\t<tr>'
|
output += '\t<thead>\n\t\t<tr>'
|
||||||
for (let column of options.columns) {
|
for (let column of header) {
|
||||||
output += `<th align="${column.align}">${column.name}</th>`
|
output += `<th align="left">${column}</th>`
|
||||||
}
|
}
|
||||||
output += '</tr>\n\t</thead>\n'
|
output += '</tr>\n\t</thead>\n'
|
||||||
|
|
||||||
output += '\t<tbody>\n'
|
output += '\t<tbody>\n'
|
||||||
for (let item of data) {
|
for (let item of data) {
|
||||||
output += '\t\t<tr>'
|
const size = data.filter(i => i.countryName === item.countryName).length
|
||||||
let i = 0
|
let root = output.indexOf(item.countryName) === -1
|
||||||
for (let prop in item) {
|
const rowspan = root && size > 1 ? ` rowspan="${size}"` : ''
|
||||||
const column = options.columns[i]
|
const cell1 = root
|
||||||
let nowrap = column.nowrap
|
? `<td align="left" valign="top" nowrap${rowspan}>${item.countryFlag} ${item.countryName}</td>`
|
||||||
let align = column.align
|
: ''
|
||||||
output += `<td align="${align}"${nowrap ? ' nowrap' : ''}>${item[prop]}</td>`
|
output += `\t\t<tr>${cell1}<td align="right" nowrap>${item.channelCount}</td><td align="left" nowrap><code>${item.guideUrl}</code></td></tr>\n`
|
||||||
i++
|
|
||||||
}
|
|
||||||
output += '</tr>\n'
|
|
||||||
}
|
}
|
||||||
output += '\t</tbody>\n'
|
output += '\t</tbody>\n'
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue