const parser = require('epg-parser') const markdownInclude = require('markdown-include') const countries = require('./countries.json') const file = require('./file') async function main() { console.log('Starting...') file .list('.gh-pages/guides/**/*.xml') .then(files => { let data = [] files.forEach(filename => { const countryCode = filename.match(/\.gh\-pages\/guides\/(.*)\/.*/i)[1] const country = countries.find(c => c.code === countryCode) const epg = file.read(filename) const parsed = parser.parse(epg) data.push({ countryFlag: country.flag, countryName: country.name, guideUrl: filename.replace('.gh-pages', 'https://iptv-org.github.io/epg'), channelCount: parsed.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) markdownInclude.compileFiles('.readme/config.json') }) .finally(() => { console.log('Finish') }) } function generateTable(data, header) { let output = '
${column} | ` } output += '${item.countryFlag} ${item.countryName} | ` : '' output += `\t\t
---|---|
${item.channelCount} | ${item.guideUrl} |