2022-02-07 06:39:55 +01:00
|
|
|
const { file, markdown, parser, logger, api } = require('../core')
|
|
|
|
const { create: createTable } = require('../core/table')
|
2021-12-12 05:10:03 +01:00
|
|
|
const { program } = require('commander')
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs/generators'
|
2021-12-12 05:10:03 +01: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-07 06:39:55 +01:00
|
|
|
await createCategoryTable()
|
|
|
|
await createCountryTable()
|
|
|
|
await createLanguageTable()
|
|
|
|
await createRegionTable()
|
2021-12-12 05:10:03 +01:00
|
|
|
await updateReadme()
|
|
|
|
}
|
|
|
|
|
|
|
|
main()
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
async function createCategoryTable() {
|
|
|
|
logger.info('creating category table...')
|
2021-12-12 05:10:03 +01:00
|
|
|
const rows = []
|
2022-02-07 06:39:55 +01:00
|
|
|
await api.categories.load()
|
|
|
|
const items = await parser.parseLogs(`${LOGS_DIR}/categories.log`)
|
|
|
|
for (const item of items) {
|
|
|
|
const id = file.getFilename(item.filepath)
|
|
|
|
const category = await api.categories.find({ id })
|
2021-12-12 05:10:03 +01:00
|
|
|
rows.push({
|
2022-02-07 06:39:55 +01:00
|
|
|
name: category ? category.name : 'Undefined',
|
|
|
|
channels: item.count,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/${item.filepath}</code>`
|
2021-12-12 05:10:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
const table = createTable(rows, [
|
|
|
|
{ name: 'Category' },
|
2021-12-12 05:10:03 +01:00
|
|
|
{ name: 'Channels', align: 'right' },
|
2022-02-07 06:39:55 +01:00
|
|
|
{ name: 'Playlist', nowrap: true }
|
2021-12-12 05:10:03 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
await file.create('./.readme/_categories.md', table)
|
|
|
|
}
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
async function createCountryTable() {
|
|
|
|
logger.info('creating country table...')
|
2021-12-12 05:10:03 +01:00
|
|
|
const rows = []
|
2022-02-07 06:39:55 +01:00
|
|
|
await api.countries.load()
|
|
|
|
const items = await parser.parseLogs(`${LOGS_DIR}/countries.log`)
|
|
|
|
for (const item of items) {
|
|
|
|
const code = file.getFilename(item.filepath)
|
|
|
|
const country = await api.countries.find({ code: code.toUpperCase() })
|
2021-12-12 05:10:03 +01:00
|
|
|
rows.push({
|
2022-02-07 06:39:55 +01:00
|
|
|
name: country ? `${country.flag} ${country.name}` : 'Undefined',
|
|
|
|
channels: item.count,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/${item.filepath}</code>`
|
2021-12-12 05:10:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
const table = createTable(rows, [
|
|
|
|
{ name: 'Country' },
|
2021-12-12 05:10:03 +01:00
|
|
|
{ name: 'Channels', align: 'right' },
|
2022-02-07 06:39:55 +01:00
|
|
|
{ name: 'Playlist', nowrap: true }
|
2021-12-12 05:10:03 +01:00
|
|
|
])
|
|
|
|
|
|
|
|
await file.create('./.readme/_countries.md', table)
|
|
|
|
}
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
async function createLanguageTable() {
|
|
|
|
logger.info('creating language table...')
|
2021-12-12 05:10:03 +01:00
|
|
|
const rows = []
|
2022-02-07 06:39:55 +01:00
|
|
|
await api.languages.load()
|
|
|
|
const items = await parser.parseLogs(`${LOGS_DIR}/languages.log`)
|
|
|
|
for (const item of items) {
|
|
|
|
const code = file.getFilename(item.filepath)
|
|
|
|
const language = await api.languages.find({ code })
|
2021-12-12 05:10:03 +01:00
|
|
|
rows.push({
|
2022-02-07 06:39:55 +01:00
|
|
|
name: language ? language.name : 'Undefined',
|
|
|
|
channels: item.count,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/${item.filepath}</code>`
|
2021-12-12 05:10:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
const table = createTable(rows, [
|
|
|
|
{ name: 'Language', align: 'left' },
|
2021-12-12 05:10:03 +01:00
|
|
|
{ name: 'Channels', align: 'right' },
|
2021-12-14 22:19:47 +01:00
|
|
|
{ name: 'Playlist', align: 'left', nowrap: true }
|
2021-12-12 05:10:03 +01:00
|
|
|
])
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
await file.create('./.readme/_languages.md', table)
|
2021-12-12 05:10:03 +01:00
|
|
|
}
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
async function createRegionTable() {
|
|
|
|
logger.info('creating region table...')
|
2021-12-12 05:10:03 +01:00
|
|
|
const rows = []
|
2022-02-07 06:39:55 +01:00
|
|
|
await api.regions.load()
|
|
|
|
const items = await parser.parseLogs(`${LOGS_DIR}/regions.log`)
|
|
|
|
for (const item of items) {
|
|
|
|
const code = file.getFilename(item.filepath)
|
|
|
|
const region = await api.regions.find({ code: code.toUpperCase() })
|
2021-12-12 05:10:03 +01:00
|
|
|
rows.push({
|
2022-02-07 06:39:55 +01:00
|
|
|
name: region ? region.name : 'Undefined',
|
|
|
|
channels: item.count,
|
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/${item.filepath}</code>`
|
2021-12-12 05:10:03 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
const table = createTable(rows, [
|
|
|
|
{ name: 'Region', align: 'left' },
|
2021-12-12 05:10:03 +01:00
|
|
|
{ name: 'Channels', align: 'right' },
|
2021-12-14 22:19:47 +01:00
|
|
|
{ name: 'Playlist', align: 'left', nowrap: true }
|
2021-12-12 05:10:03 +01:00
|
|
|
])
|
|
|
|
|
2022-02-07 06:39:55 +01:00
|
|
|
await file.create('./.readme/_regions.md', table)
|
2021-12-12 05:10:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async function updateReadme() {
|
2022-02-07 06:39:55 +01:00
|
|
|
logger.info('updating readme.md...')
|
2021-12-12 05:10:03 +01:00
|
|
|
const config = require(file.resolve(options.config))
|
|
|
|
await file.createDir(file.dirname(config.build))
|
|
|
|
await markdown.compile(options.config)
|
|
|
|
}
|