From 5cb7941155e83c425036b4825e81befca4c94a0b Mon Sep 17 00:00:00 2001 From: freearhey Date: Sat, 14 Sep 2019 03:07:54 +0300 Subject: [PATCH] Added generation of playlists grouped by category --- helpers/generate.js | 51 ++++++++++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/helpers/generate.js b/helpers/generate.js index fd984090ef..7a10996ab5 100644 --- a/helpers/generate.js +++ b/helpers/generate.js @@ -1,12 +1,19 @@ const util = require('./util') const debug = false -const types = ['full', 'country', 'content', 'sport'] +const types = ['full', 'country', 'content'] +const categories = util.supportedCategories.map(c => c.toLowerCase()) let stats = { countries: 0, channels: 0 } +let buffer = {} +categories.push('other') +categories.forEach(category => { + buffer[category] = [] +}) + function main() { console.log(`Parsing 'index.m3u'...`) const playlist = util.parsePlaylist('index.m3u') @@ -22,13 +29,13 @@ function main() { util.createFile(filename, '#EXTM3U\n') } + for(let category of categories) { + const filename = `categories/${category}.m3u` + console.log(`Creating '${filename}'...`) + util.createFile(filename, '#EXTM3U\n') + } + for(let country of countries) { - - if(debug) { - console.log(`Clear cache...`) - } - util.clearCache() - console.log(`Parsing '${country.url}'...`) const playlist = util.parsePlaylist(country.url) @@ -48,7 +55,7 @@ function main() { title: item.inf.title }) - let category = channel.group + let group = channel.group for(const type of types) { if(type === 'full') { @@ -56,17 +63,17 @@ function main() { } else if(type === 'country') { channel.group = c.name } else { - channel.group = category + channel.group = group } - const filename = `index.${type}.m3u` - if(type === 'sport') { - if(channel.group === 'Sport') { - util.appendToFile(filename, channel.toString()) - } - } else { - util.appendToFile(filename, channel.toString()) - } + util.appendToFile(`index.${type}.m3u`, channel.toString()) + } + + let category = channel.group.toLowerCase() + if(buffer[category]) { + buffer[category].push(channel) + } else { + buffer['other'].push(channel) } stats.channels++ @@ -74,6 +81,16 @@ function main() { stats.countries++ } + + for(const category in buffer) { + let channels = util.sortByTitleAndUrl(buffer[category]) + for(const channel of channels) { + if(!util.checkCache(channel.url)) { + util.appendToFile(`categories/${category}.m3u`, channel.toString()) + util.addToCache(channel.url) + } + } + } } main()