Added generation of playlists grouped by category

This commit is contained in:
freearhey 2019-09-14 03:07:54 +03:00
parent d387a61826
commit 5cb7941155
1 changed files with 34 additions and 17 deletions

View File

@ -1,12 +1,19 @@
const util = require('./util') const util = require('./util')
const debug = false const debug = false
const types = ['full', 'country', 'content', 'sport'] const types = ['full', 'country', 'content']
const categories = util.supportedCategories.map(c => c.toLowerCase())
let stats = { let stats = {
countries: 0, countries: 0,
channels: 0 channels: 0
} }
let buffer = {}
categories.push('other')
categories.forEach(category => {
buffer[category] = []
})
function main() { function main() {
console.log(`Parsing 'index.m3u'...`) console.log(`Parsing 'index.m3u'...`)
const playlist = util.parsePlaylist('index.m3u') const playlist = util.parsePlaylist('index.m3u')
@ -22,13 +29,13 @@ function main() {
util.createFile(filename, '#EXTM3U\n') util.createFile(filename, '#EXTM3U\n')
} }
for(let country of countries) { for(let category of categories) {
const filename = `categories/${category}.m3u`
if(debug) { console.log(`Creating '${filename}'...`)
console.log(`Clear cache...`) util.createFile(filename, '#EXTM3U\n')
} }
util.clearCache()
for(let country of countries) {
console.log(`Parsing '${country.url}'...`) console.log(`Parsing '${country.url}'...`)
const playlist = util.parsePlaylist(country.url) const playlist = util.parsePlaylist(country.url)
@ -48,7 +55,7 @@ function main() {
title: item.inf.title title: item.inf.title
}) })
let category = channel.group let group = channel.group
for(const type of types) { for(const type of types) {
if(type === 'full') { if(type === 'full') {
@ -56,17 +63,17 @@ function main() {
} else if(type === 'country') { } else if(type === 'country') {
channel.group = c.name channel.group = c.name
} else { } else {
channel.group = category channel.group = group
} }
const filename = `index.${type}.m3u` util.appendToFile(`index.${type}.m3u`, channel.toString())
if(type === 'sport') {
if(channel.group === 'Sport') {
util.appendToFile(filename, channel.toString())
} }
let category = channel.group.toLowerCase()
if(buffer[category]) {
buffer[category].push(channel)
} else { } else {
util.appendToFile(filename, channel.toString()) buffer['other'].push(channel)
}
} }
stats.channels++ stats.channels++
@ -74,6 +81,16 @@ function main() {
stats.countries++ 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() main()