From 1c5eae5256e664535fcca301a80c2828edd2bb44 Mon Sep 17 00:00:00 2001 From: freearhey Date: Thu, 11 Feb 2021 07:16:44 +0300 Subject: [PATCH] Update update-readme.js --- scripts/update-readme.js | 68 +++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/scripts/update-readme.js b/scripts/update-readme.js index 18b259896a..77d26c5312 100644 --- a/scripts/update-readme.js +++ b/scripts/update-readme.js @@ -1,6 +1,9 @@ const utils = require('./utils') const parser = require('./parser') const categories = require('./categories') +const db = require('./db') + +db.load() const list = { countries: {}, @@ -34,19 +37,6 @@ function parseIndex() { playlist: `https://iptv-org.github.io/iptv/languages/undefined.m3u` } - for (const category of categories) { - list.categories[category.id] = { - category: category.name, - channels: 0, - playlist: `https://iptv-org.github.io/iptv/categories/${category.id}.m3u` - } - } - list.categories['other'] = { - category: 'Other', - channels: 0, - playlist: `https://iptv-org.github.io/iptv/categories/other.m3u` - } - for (const item of items) { const playlist = parser.parsePlaylist(item.url) for (let channel of playlist.channels) { @@ -85,20 +75,40 @@ function parseIndex() { } } } - - // categories - const categoryId = channel.category.toLowerCase() - if (!categoryId) { - list.categories['other'].channels++ - } else if (list.categories[categoryId]) { - list.categories[categoryId].channels++ - } } } list.countries = Object.values(list.countries) list.languages = Object.values(list.languages) - list.categories = Object.values(list.categories) +} + +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: `https://iptv-org.github.io/iptv/categories/${category.id}.m3u` + }) + } + + categories.push({ + category: 'Other', + channels: db.channels.forCategory({ id: null }).count(), + playlist: `https://iptv-org.github.io/iptv/categories/other.m3u` + }) + + 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() { @@ -132,20 +142,6 @@ function generateLanguagesTable() { utils.createFile('./.readme/_languages.md', table) } -function generateCategoriesTable() { - console.log(`Generating categories table...`) - list.categories = utils.sortBy(list.categories, ['category']) - const table = utils.generateTable(list.categories, { - columns: [ - { name: 'Category', align: 'left' }, - { name: 'Channels', align: 'right' }, - { name: 'Playlist', align: 'left' } - ] - }) - - utils.createFile('./.readme/_categories.md', table) -} - function generateReadme() { console.log(`Generating README.md...`) utils.compileMarkdown('../.readme/config.json')