From 719726eeda2b5f45c8b01183585502c0e1b7f3b5 Mon Sep 17 00:00:00 2001 From: freearhey Date: Thu, 11 Feb 2021 07:38:39 +0300 Subject: [PATCH] Update update-readme.js --- scripts/update-readme.js | 85 ++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 56 deletions(-) diff --git a/scripts/update-readme.js b/scripts/update-readme.js index d25172f9bc..9d2f2cb06a 100644 --- a/scripts/update-readme.js +++ b/scripts/update-readme.js @@ -1,16 +1,10 @@ const utils = require('./utils') -const parser = require('./parser') -const categories = require('./categories') const db = require('./db') db.load() -const list = { - countries: {} -} - function main() { - parseIndex() + start() generateCountriesTable() generateLanguagesTable() generateCategoriesTable() @@ -18,42 +12,34 @@ function main() { finish() } -function parseIndex() { - console.log(`Parsing index...`) - const items = parser.parseIndex() +function generateCountriesTable() { + console.log(`Generating countries table...`) + const countries = [] - list.countries['undefined'] = { + for (const country of db.countries.sortBy(['name']).all()) { + let flag = utils.code2flag(country.code) + countries.push({ + country: flag + ' ' + country.name, + channels: db.channels.forCountry(country).count(), + playlist: `https://iptv-org.github.io/iptv/countries/${country.code}.m3u` + }) + } + + countries.push({ country: 'Undefined', - channels: 0, - playlist: `https://iptv-org.github.io/iptv/countries/undefined.m3u`, - name: 'Undefined' - } + channels: db.channels.forCountry({ code: null }).count(), + playlist: `https://iptv-org.github.io/iptv/countries/undefined.m3u` + }) - 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) - list.countries[country.code] = { - country: flag + ' ' + country.name, - channels: 1, - playlist: `https://iptv-org.github.io/iptv/countries/${country.code}.m3u`, - name: country.name - } - } - } - } - } - } + const table = utils.generateTable(countries, { + columns: [ + { name: 'Country', align: 'left' }, + { name: 'Channels', align: 'right' }, + { name: 'Playlist', align: 'left', nowrap: true } + ] + }) - list.countries = Object.values(list.countries) + utils.createFile('./.readme/_countries.md', table) } function generateCategoriesTable() { @@ -114,28 +100,15 @@ function generateLanguagesTable() { 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() { console.log(`Generating README.md...`) utils.compileMarkdown('../.readme/config.json') } +function start() { + console.log(`Starting...`) +} + function finish() { console.log(`Done.`) }