iptv/scripts/update-readme.js

107 lines
2.7 KiB
JavaScript
Raw Normal View History

2021-01-30 04:26:15 +01:00
const utils = require('./utils')
2021-02-11 05:16:44 +01:00
const db = require('./db')
2021-05-10 15:25:23 +02:00
const parser = require('./parser')
2021-02-11 05:16:44 +01:00
db.load()
2019-11-01 17:34:05 +01:00
2019-11-01 19:13:15 +01:00
function main() {
2021-02-11 05:38:39 +01:00
start()
generateCategoriesTable()
2019-11-01 19:13:15 +01:00
generateCountriesTable()
generateLanguagesTable()
generateReadme()
2021-01-30 04:26:15 +01:00
finish()
2019-11-01 17:34:05 +01:00
}
function generateCategoriesTable() {
console.log(`Generating categories table...`)
2021-05-10 15:25:23 +02:00
const categories = []
for (const category of [...db.categories.all(), { name: 'Other', id: 'other' }]) {
categories.push({
category: category.name,
2021-05-10 15:25:23 +02:00
channels: db.channels.forCategory(category).removeDuplicates().count(),
playlist: `<code>https://iptv-org.github.io/iptv/categories/${category.id}.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)
}
2021-02-11 05:38:39 +01:00
function generateCountriesTable() {
console.log(`Generating countries table...`)
2021-05-10 15:25:23 +02:00
const countries = []
for (const country of [
...db.countries.sortBy(['name']).all(),
{ name: 'Undefined', code: 'undefined' }
]) {
2021-02-11 05:38:39 +01:00
let flag = utils.code2flag(country.code)
2021-05-10 15:25:23 +02:00
const prefix = flag ? `${flag}&nbsp;` : ''
2021-02-11 05:38:39 +01:00
countries.push({
2021-05-10 15:25:23 +02:00
country: prefix + country.name,
channels: db.channels.forCountry(country).removeDuplicates().count(),
2021-02-11 05:38:39 +01:00
playlist: `<code>https://iptv-org.github.io/iptv/countries/${country.code}.m3u</code>`
})
}
2021-01-30 04:26:15 +01:00
2021-02-11 05:38:39 +01:00
const table = utils.generateTable(countries, {
columns: [
{ name: 'Country', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left', nowrap: true }
]
})
2019-11-01 17:34:05 +01:00
2021-02-11 05:38:39 +01:00
utils.createFile('./.readme/_countries.md', table)
2021-02-11 05:16:44 +01:00
}
2021-02-11 05:28:35 +01:00
function generateLanguagesTable() {
console.log(`Generating languages table...`)
const languages = []
2021-05-10 15:25:23 +02:00
for (const language of [
...db.languages.sortBy(['name']).all(),
{ name: 'Undefined', code: 'undefined' }
]) {
2021-02-11 05:28:35 +01:00
languages.push({
language: language.name,
2021-05-10 15:25:23 +02:00
channels: db.channels.forLanguage(language).removeDuplicates().count(),
2021-02-11 05:28:35 +01:00
playlist: `<code>https://iptv-org.github.io/iptv/languages/${language.code}.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)
}
2019-11-01 19:13:15 +01:00
function generateReadme() {
2021-01-30 04:26:15 +01:00
console.log(`Generating README.md...`)
utils.compileMarkdown('../.readme/config.json')
}
2021-02-11 05:38:39 +01:00
function start() {
console.log(`Starting...`)
}
2021-01-30 04:26:15 +01:00
function finish() {
console.log(`Done.`)
2019-11-01 17:34:05 +01:00
}
main()