Files
epg/scripts/commands/readme/update.js

83 lines
2.8 KiB
JavaScript
Raw Normal View History

2022-02-26 23:21:44 +03:00
const { file, markdown, parser, logger, api, table } = require('../../core')
2022-01-14 23:57:03 +03:00
const { program } = require('commander')
const _ = require('lodash')
2022-02-03 06:22:42 +03:00
const CHANNELS_PATH = process.env.CHANNELS_PATH || 'sites/**/*.channels.xml'
2022-01-15 18:27:19 +03:00
2022-01-14 23:57:03 +03:00
const options = program
.option('-c, --config <config>', 'Set path to config file', '.readme/config.json')
.parse(process.argv)
.opts()
async function main() {
2022-02-03 06:22:42 +03:00
const items = []
2022-02-27 18:04:20 +03:00
2022-05-09 12:58:01 +03:00
await api.countries.load().catch(console.error)
const files = await file.list(CHANNELS_PATH).catch(console.error)
for (const filepath of files) {
try {
2022-02-27 18:04:20 +03:00
const { site, channels } = await parser.parseChannels(filepath)
const dir = file.dirname(filepath)
const config = require(file.resolve(`${dir}/${site}.config.js`))
if (config.ignore) continue
const filename = file.basename(filepath)
const [__, suffix] = filename.match(/\_(.*)\.channels\.xml$/) || [null, null]
const [code] = suffix.split('-')
items.push({
code,
site,
count: channels.length,
group: `${suffix}/${site}`
})
2022-05-09 12:58:01 +03:00
} catch (err) {
console.error(err)
continue
2022-02-27 18:04:20 +03:00
}
2022-02-03 06:22:42 +03:00
}
await generateCountriesTable(items)
2022-01-14 23:57:03 +03:00
await updateReadme()
}
main()
2022-01-21 23:15:39 +03:00
async function generateCountriesTable(items = []) {
2022-02-03 06:22:42 +03:00
logger.info('generating countries table...')
2022-01-14 23:57:03 +03:00
let rows = []
for (const item of items) {
2022-02-03 06:22:42 +03:00
const country = api.countries.find({ code: item.code.toUpperCase() })
2022-01-21 23:15:39 +03:00
if (!country) continue
2022-01-14 23:57:03 +03:00
rows.push({
2022-01-15 19:46:04 +03:00
flag: country.flag,
name: country.name,
2022-01-14 23:57:03 +03:00
channels: item.count,
2022-01-30 20:24:14 +03:00
epg: `<code>https://iptv-org.github.io/epg/guides/${item.group}.epg.xml</code>`,
2022-02-03 06:22:42 +03:00
status: `<a href="https://github.com/iptv-org/epg/actions/workflows/${item.site}.yml"><img src="https://github.com/iptv-org/epg/actions/workflows/${item.site}.yml/badge.svg" alt="${item.site}" style="max-width: 100%;"></a>`
2022-01-14 23:57:03 +03:00
})
}
rows = _.orderBy(rows, ['name', 'channels'], ['asc', 'desc'])
rows = _.groupBy(rows, 'name')
2022-02-03 06:22:42 +03:00
const output = table.create(rows, [
2022-02-03 06:50:13 +03:00
'Country&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;',
2022-02-03 06:22:42 +03:00
'Channels',
'EPG',
'Status&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'
])
2022-01-14 23:57:03 +03:00
2022-02-03 06:22:42 +03:00
await file.create('./.readme/_countries.md', output)
2022-01-14 23:57:03 +03:00
}
async function updateReadme() {
2022-02-03 06:22:42 +03:00
logger.info('updating readme.md...')
2022-01-14 23:57:03 +03:00
const config = require(file.resolve(options.config))
await file.createDir(file.dirname(config.build))
await markdown.compile(options.config)
}