2021-08-01 19:42:11 +02:00
|
|
|
const utils = require('./helpers/utils')
|
|
|
|
const file = require('./helpers/file')
|
|
|
|
const log = require('./helpers/log')
|
|
|
|
const db = require('./helpers/db')
|
|
|
|
|
|
|
|
async function main() {
|
|
|
|
log.start()
|
|
|
|
await loadDatabase()
|
2021-05-09 12:33:29 +02:00
|
|
|
generateCategoriesTable()
|
2019-11-01 19:13:15 +01:00
|
|
|
generateCountriesTable()
|
|
|
|
generateLanguagesTable()
|
|
|
|
generateReadme()
|
2021-08-01 19:42:11 +02:00
|
|
|
log.finish()
|
|
|
|
}
|
|
|
|
|
|
|
|
async function loadDatabase() {
|
|
|
|
log.print('Loading database...\n')
|
|
|
|
await db.load()
|
2019-11-01 17:34:05 +01:00
|
|
|
}
|
|
|
|
|
2021-05-09 12:33:29 +02:00
|
|
|
function generateCategoriesTable() {
|
2021-08-01 19:42:11 +02:00
|
|
|
log.print('Generating categories table...\n')
|
2021-05-09 12:33:29 +02:00
|
|
|
|
2021-05-10 15:25:23 +02:00
|
|
|
const categories = []
|
|
|
|
for (const category of [...db.categories.all(), { name: 'Other', id: 'other' }]) {
|
2021-05-09 12:33:29 +02:00
|
|
|
categories.push({
|
|
|
|
category: category.name,
|
2021-08-12 06:24:00 +02:00
|
|
|
channels: db.channels.forCategory(category).removeOffline().removeDuplicates().count(),
|
2021-05-09 12:33:29 +02:00
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/categories/${category.id}.m3u</code>`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-01 19:42:11 +02:00
|
|
|
const table = generateTable(categories, {
|
2021-05-09 12:33:29 +02:00
|
|
|
columns: [
|
|
|
|
{ name: 'Category', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2021-08-01 19:42:11 +02:00
|
|
|
file.create('./.readme/_categories.md', table)
|
2021-05-09 12:33:29 +02:00
|
|
|
}
|
|
|
|
|
2021-02-11 05:38:39 +01:00
|
|
|
function generateCountriesTable() {
|
2021-08-01 19:42:11 +02:00
|
|
|
log.print('Generating countries table...\n')
|
2021-02-11 05:38:39 +01:00
|
|
|
|
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} ` : ''
|
2021-02-11 05:38:39 +01:00
|
|
|
countries.push({
|
2021-05-10 15:25:23 +02:00
|
|
|
country: prefix + country.name,
|
2021-08-12 06:24:00 +02:00
|
|
|
channels: db.channels
|
|
|
|
.forCountry(country)
|
|
|
|
.removeOffline()
|
|
|
|
.removeDuplicates()
|
|
|
|
.removeNSFW()
|
|
|
|
.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-08-01 19:42:11 +02:00
|
|
|
const table = generateTable(countries, {
|
2021-02-11 05:38:39 +01:00
|
|
|
columns: [
|
|
|
|
{ name: 'Country', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left', nowrap: true }
|
|
|
|
]
|
|
|
|
})
|
2019-11-01 17:34:05 +01:00
|
|
|
|
2021-08-01 19:42:11 +02:00
|
|
|
file.create('./.readme/_countries.md', table)
|
2021-02-11 05:16:44 +01:00
|
|
|
}
|
|
|
|
|
2021-02-11 05:28:35 +01:00
|
|
|
function generateLanguagesTable() {
|
2021-08-01 19:42:11 +02:00
|
|
|
log.print('Generating languages table...\n')
|
2021-02-11 05:28:35 +01:00
|
|
|
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-08-12 06:24:00 +02:00
|
|
|
channels: db.channels
|
|
|
|
.forLanguage(language)
|
|
|
|
.removeOffline()
|
|
|
|
.removeDuplicates()
|
|
|
|
.removeNSFW()
|
|
|
|
.count(),
|
2021-02-11 05:28:35 +01:00
|
|
|
playlist: `<code>https://iptv-org.github.io/iptv/languages/${language.code}.m3u</code>`
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-01 19:42:11 +02:00
|
|
|
const table = generateTable(languages, {
|
2021-02-11 05:28:35 +01:00
|
|
|
columns: [
|
|
|
|
{ name: 'Language', align: 'left' },
|
|
|
|
{ name: 'Channels', align: 'right' },
|
|
|
|
{ name: 'Playlist', align: 'left' }
|
|
|
|
]
|
|
|
|
})
|
|
|
|
|
2021-08-01 19:42:11 +02:00
|
|
|
file.create('./.readme/_languages.md', table)
|
2021-02-11 05:28:35 +01:00
|
|
|
}
|
|
|
|
|
2021-08-01 19:42:11 +02:00
|
|
|
function generateTable(data, options) {
|
|
|
|
let output = '<table>\n'
|
2021-01-30 04:26:15 +01:00
|
|
|
|
2021-08-01 19:42:11 +02:00
|
|
|
output += '\t<thead>\n\t\t<tr>'
|
|
|
|
for (let column of options.columns) {
|
|
|
|
output += `<th align="${column.align}">${column.name}</th>`
|
|
|
|
}
|
|
|
|
output += '</tr>\n\t</thead>\n'
|
|
|
|
|
|
|
|
output += '\t<tbody>\n'
|
|
|
|
for (let item of data) {
|
|
|
|
output += '\t\t<tr>'
|
|
|
|
let i = 0
|
|
|
|
for (let prop in item) {
|
|
|
|
const column = options.columns[i]
|
|
|
|
let nowrap = column.nowrap
|
|
|
|
let align = column.align
|
|
|
|
output += `<td align="${align}"${nowrap ? ' nowrap' : ''}>${item[prop]}</td>`
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
output += '</tr>\n'
|
|
|
|
}
|
|
|
|
output += '\t</tbody>\n'
|
|
|
|
|
|
|
|
output += '</table>'
|
|
|
|
|
|
|
|
return output
|
2021-02-11 05:38:39 +01:00
|
|
|
}
|
|
|
|
|
2021-08-01 19:42:11 +02:00
|
|
|
function generateReadme() {
|
|
|
|
log.print('Generating README.md...\n')
|
|
|
|
file.compileMarkdown('.readme/config.json')
|
2019-11-01 17:34:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main()
|