From 1d11c69ba46ba801466e021b21c6d9dc9623c30c Mon Sep 17 00:00:00 2001 From: freearhey Date: Wed, 10 Feb 2021 17:03:47 +0300 Subject: [PATCH] Update generate.js --- scripts/generate.js | 60 +++++++++++++++++++++++++++++---------------- 1 file changed, 39 insertions(+), 21 deletions(-) diff --git a/scripts/generate.js b/scripts/generate.js index 353074d02..89840ff24 100644 --- a/scripts/generate.js +++ b/scripts/generate.js @@ -26,7 +26,7 @@ function createRootDirectory() { } function createNoJekyllFile() { - console.log('Creating .nojekyll...') + console.log('Creating .nojekyll file...') utils.createFile(`${ROOT_DIR}/.nojekyll`) } @@ -93,13 +93,24 @@ function generateLanguageIndex() { const filename = `${ROOT_DIR}/index.language.m3u` utils.createFile(filename, '#EXTM3U\n') - const channels = db.channels.sortBy(['tvgLanguage', 'name', 'url']).all() + const channels = db.channels.sortBy(['name', 'url']).forLanguage({ code: null }) for (const channel of channels) { const category = channel.category - channel.category = channel.tvgLanguage + channel.category = '' utils.appendToFile(filename, channel.toString()) channel.category = category } + + const languages = db.languages.sortBy(['name']).all() + for (const language of languages) { + const channels = db.channels.sortBy(['name', 'url']).forLanguage(language) + for (const channel of channels) { + const category = channel.category + channel.category = language.name + utils.appendToFile(filename, channel.toString()) + channel.category = category + } + } } function generateCategoryIndex() { @@ -113,48 +124,55 @@ function generateCategoryIndex() { } } -function generateCountries() { - console.log('Generating /countries...') - const outputDir = `${ROOT_DIR}/countries` +function generateCategories() { + console.log('Generating a playlist for each category...') + const outputDir = `${ROOT_DIR}/categories` utils.createDir(outputDir) - for (const country of db.countries.all()) { - const filename = `${outputDir}/${country.code}.m3u` + for (const category of db.categories.all()) { + const filename = `${outputDir}/${category.id}.m3u` utils.createFile(filename, '#EXTM3U\n') - const channels = db.channels.sortBy(['name', 'url']).forCountry(country) + const channels = db.channels.sortBy(['name', 'url']).forCategory(category) for (const channel of channels) { utils.appendToFile(filename, channel.toString()) } } + + const other = `${outputDir}/other.m3u` + const channels = db.channels.sortBy(['name', 'url']).forCategory({ id: null }) + utils.createFile(other, '#EXTM3U\n') + for (const channel of channels) { + utils.appendToFile(other, channel.toString()) + } } -function generateLanguages() { - console.log('Generating /languages...') - const outputDir = `${ROOT_DIR}/languages` +function generateCountries() { + console.log('Generating a playlist for each country...') + const outputDir = `${ROOT_DIR}/countries` utils.createDir(outputDir) - for (const language of db.languages.all()) { - const filename = `${outputDir}/${language.code}.m3u` + for (const country of db.countries.all()) { + const filename = `${outputDir}/${country.code}.m3u` utils.createFile(filename, '#EXTM3U\n') - const channels = db.channels.sortBy(['name', 'url']).forLanguage(language) + const channels = db.channels.sortBy(['name', 'url']).forCountry(country) for (const channel of channels) { utils.appendToFile(filename, channel.toString()) } } } -function generateCategories() { - console.log('Generating /categories...') - const outputDir = `${ROOT_DIR}/categories` +function generateLanguages() { + console.log('Generating a playlist for each language...') + const outputDir = `${ROOT_DIR}/languages` utils.createDir(outputDir) - for (const category of db.categories.all()) { - const filename = `${outputDir}/${category.id}.m3u` + for (const language of db.languages.all()) { + const filename = `${outputDir}/${language.code}.m3u` utils.createFile(filename, '#EXTM3U\n') - const channels = db.channels.sortBy(['name', 'url']).forCategory(category) + const channels = db.channels.sortBy(['name', 'url']).forLanguage(language) for (const channel of channels) { utils.appendToFile(filename, channel.toString()) }