Update update-readme.js

This commit is contained in:
freearhey 2021-02-11 07:38:39 +03:00
parent c10c6a3ef1
commit 719726eeda

View File

@ -1,16 +1,10 @@
const utils = require('./utils') const utils = require('./utils')
const parser = require('./parser')
const categories = require('./categories')
const db = require('./db') const db = require('./db')
db.load() db.load()
const list = {
countries: {}
}
function main() { function main() {
parseIndex() start()
generateCountriesTable() generateCountriesTable()
generateLanguagesTable() generateLanguagesTable()
generateCategoriesTable() generateCategoriesTable()
@ -18,42 +12,34 @@ function main() {
finish() finish()
} }
function parseIndex() { function generateCountriesTable() {
console.log(`Parsing index...`) console.log(`Generating countries table...`)
const items = parser.parseIndex() const countries = []
list.countries['undefined'] = { for (const country of db.countries.sortBy(['name']).all()) {
country: 'Undefined',
channels: 0,
playlist: `<code>https://iptv-org.github.io/iptv/countries/undefined.m3u</code>`,
name: 'Undefined'
}
for (const item of items) {
const playlist = parser.parsePlaylist(item.url)
for (let channel of playlist.channels) {
// countries
if (!channel.countries.length) {
list.countries['undefined'].channels++
} else {
for (let country of channel.countries) {
if (list.countries[country.code]) {
list.countries[country.code].channels++
} else {
let flag = utils.code2flag(country.code) let flag = utils.code2flag(country.code)
list.countries[country.code] = { countries.push({
country: flag + '&nbsp;' + country.name, country: flag + '&nbsp;' + country.name,
channels: 1, channels: db.channels.forCountry(country).count(),
playlist: `<code>https://iptv-org.github.io/iptv/countries/${country.code}.m3u</code>`, playlist: `<code>https://iptv-org.github.io/iptv/countries/${country.code}.m3u</code>`
name: country.name })
}
}
}
}
}
} }
list.countries = Object.values(list.countries) countries.push({
country: 'Undefined',
channels: db.channels.forCountry({ code: null }).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 generateCategoriesTable() { function generateCategoriesTable() {
@ -114,28 +100,15 @@ function generateLanguagesTable() {
utils.createFile('./.readme/_languages.md', table) utils.createFile('./.readme/_languages.md', table)
} }
function generateCountriesTable() {
console.log(`Generating countries table...`)
list.countries = utils.sortBy(list.countries, ['name'])
list.countries.forEach(function (i) {
delete i.name
})
const table = utils.generateTable(list.countries, {
columns: [
{ name: 'Country', align: 'left' },
{ name: 'Channels', align: 'right' },
{ name: 'Playlist', align: 'left', nowrap: true }
]
})
utils.createFile('./.readme/_countries.md', table)
}
function generateReadme() { function generateReadme() {
console.log(`Generating README.md...`) console.log(`Generating README.md...`)
utils.compileMarkdown('../.readme/config.json') utils.compileMarkdown('../.readme/config.json')
} }
function start() {
console.log(`Starting...`)
}
function finish() { function finish() {
console.log(`Done.`) console.log(`Done.`)
} }