diff --git a/scripts/update-readme.js b/scripts/update-readme.js
index 714b04a4..dc2e5b0f 100644
--- a/scripts/update-readme.js
+++ b/scripts/update-readme.js
@@ -2,15 +2,39 @@ const markdownInclude = require('markdown-include')
const path = require('path')
const fs = require('fs')
const countries = require('./countries.json')
-const file = require('./file.js')
+const parser = require('./parser')
+const file = require('./file')
async function main() {
console.log('Starting...')
file
- .list('channels/**/*.xml', [], ['us-local'])
+ .list('sites/*.channels.xml')
.then(files => {
- files = files.map(str => str.match(/channels\/(.*).xml/i)[1])
- generateTable(files)
+ let data = []
+ 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()
})
.finally(() => {
@@ -18,50 +42,24 @@ async function main() {
})
}
-function generateTable(files) {
- 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: `https://iptv-org.github.io/epg/guides/${country.code}.xml
`
- })
- }
- }
-
- 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) {
+function generateTable(data, header) {
let output = '
${column.name} | ` + for (let column of header) { + output += `${column} | ` } output += '
---|---|
${item[prop]} | ` - i++ - } - output += '${item.countryFlag} ${item.countryName} | ` + : '' + output += `\t\t
${item.channelCount} | ${item.guideUrl} |