iptv/scripts/update-readme.js
freearhey 7c62d0948b Update update-readme.js
Fixes "Other, Undefined and Undefined at 0" issue #2744
2021-05-09 13:33:29 +03:00

117 lines
3.0 KiB
JavaScript

const utils = require('./utils')
const db = require('./db')
db.load()
function main() {
start()
generateCategoriesTable()
generateCountriesTable()
generateLanguagesTable()
generateReadme()
finish()
}
function generateCategoriesTable() {
console.log(`Generating categories table...`)
const categories = []
for (const category of db.categories.all()) {
categories.push({
category: category.name,
channels: db.channels.forCategory(category).count(),
playlist: `<code>https://iptv-org.github.io/iptv/categories/${category.id}.m3u</code>`
})
}
categories.push({
category: 'Other',
channels: db.channels.forCategory({ id: 'other' }).count(),
playlist: `<code>https://iptv-org.github.io/iptv/categories/other.m3u</code>`
})
const table = utils.generateTable(categories, {
columns: [
{ name: 'Category', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left' }
]
})
utils.createFile('./.readme/_categories.md', table)
}
function generateCountriesTable() {
console.log(`Generating countries table...`)
const countries = []
for (const country of db.countries.sortBy(['name']).all()) {
let flag = utils.code2flag(country.code)
countries.push({
country: flag + '&nbsp;' + country.name,
channels: db.channels.forCountry(country).count(),
playlist: `<code>https://iptv-org.github.io/iptv/countries/${country.code}.m3u</code>`
})
}
countries.push({
country: 'Undefined',
channels: db.channels.forCountry({ code: 'undefined' }).count(),
playlist: `<code>https://iptv-org.github.io/iptv/countries/undefined.m3u</code>`
})
const table = utils.generateTable(countries, {
columns: [
{ name: 'Country', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left', nowrap: true }
]
})
utils.createFile('./.readme/_countries.md', table)
}
function generateLanguagesTable() {
console.log(`Generating languages table...`)
const languages = []
for (const language of db.languages.sortBy(['name']).all()) {
languages.push({
language: language.name,
channels: db.channels.forLanguage(language).count(),
playlist: `<code>https://iptv-org.github.io/iptv/languages/${language.code}.m3u</code>`
})
}
languages.push({
language: 'Undefined',
channels: db.channels.forLanguage({ code: 'undefined' }).count(),
playlist: `<code>https://iptv-org.github.io/iptv/languages/undefined.m3u</code>`
})
const table = utils.generateTable(languages, {
columns: [
{ name: 'Language', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left' }
]
})
utils.createFile('./.readme/_languages.md', table)
}
function generateReadme() {
console.log(`Generating README.md...`)
utils.compileMarkdown('../.readme/config.json')
}
function start() {
console.log(`Starting...`)
}
function finish() {
console.log(`Done.`)
}
main()