Update generate.js

This commit is contained in:
freearhey 2021-01-30 06:18:21 +03:00
parent 9b317ce5a6
commit 13f1a91afb
1 changed files with 25 additions and 20 deletions

View File

@ -40,6 +40,11 @@ function parseIndex() {
console.log(`Parsing index...`) console.log(`Parsing index...`)
const items = parser.parseIndex() const items = parser.parseIndex()
for (const category of utils.supportedCategories) {
list.categories[category.id] = []
}
list.categories['other'] = []
for (let item of items) { for (let item of items) {
const playlist = parser.parsePlaylist(item.url) const playlist = parser.parsePlaylist(item.url)
for (let channel of playlist.channels) { for (let channel of playlist.channels) {
@ -81,11 +86,12 @@ function parseIndex() {
} }
// category // category
const categoryCode = channel.category ? channel.category.toLowerCase() : 'other' const categoryId = channel.category.toLowerCase()
if (!list.categories[categoryCode]) { if (!list.categories[categoryId]) {
list.categories[categoryCode] = [] list.categories['other'].push(channel)
} else {
list.categories[categoryId].push(channel)
} }
list.categories[categoryCode].push(channel)
} }
} }
} }
@ -165,13 +171,13 @@ function generateCountries() {
const outputDir = `${ROOT_DIR}/countries` const outputDir = `${ROOT_DIR}/countries`
utils.createDir(outputDir) utils.createDir(outputDir)
for (let cid in list.countries) { for (const countryId in list.countries) {
let country = list.countries[cid] const filename = `${outputDir}/${countryId}.m3u`
const filename = `${outputDir}/${cid}.m3u`
utils.createFile(filename, '#EXTM3U\n') utils.createFile(filename, '#EXTM3U\n')
const channels = utils.sortBy(Object.values(country), ['name', 'url']) let channels = Object.values(list.countries[countryId])
for (let channel of channels) { channels = utils.sortBy(channels, ['name', 'url'])
for (const channel of channels) {
utils.appendToFile(filename, channel.toString()) utils.appendToFile(filename, channel.toString())
} }
} }
@ -182,13 +188,13 @@ function generateLanguages() {
const outputDir = `${ROOT_DIR}/languages` const outputDir = `${ROOT_DIR}/languages`
utils.createDir(outputDir) utils.createDir(outputDir)
for (let lid in list.languages) { for (const languageId in list.languages) {
let language = list.languages[lid] const filename = `${outputDir}/${languageId}.m3u`
const filename = `${outputDir}/${lid}.m3u`
utils.createFile(filename, '#EXTM3U\n') utils.createFile(filename, '#EXTM3U\n')
const channels = utils.sortBy(Object.values(language), ['name', 'url']) let channels = Object.values(list.languages[languageId])
for (let channel of channels) { channels = utils.sortBy(channels, ['name', 'url'])
for (const channel of channels) {
utils.appendToFile(filename, channel.toString()) utils.appendToFile(filename, channel.toString())
} }
} }
@ -199,14 +205,13 @@ function generateCategories() {
const outputDir = `${ROOT_DIR}/categories` const outputDir = `${ROOT_DIR}/categories`
utils.createDir(outputDir) utils.createDir(outputDir)
for (let cid in utils.supportedCategories) { for (const category of utils.supportedCategories) {
let category = list.categories[cid] const filename = `${outputDir}/${category.id}.m3u`
const filename = `${outputDir}/${cid}.m3u`
utils.createFile(filename, '#EXTM3U\n') utils.createFile(filename, '#EXTM3U\n')
if (!category) continue let channels = Object.values(list.categories[category.id])
const channels = utils.sortBy(Object.values(category), ['name', 'url']) channels = utils.sortBy(channels, ['name', 'url'])
for (let channel of channels) { for (const channel of channels) {
utils.appendToFile(filename, channel.toString()) utils.appendToFile(filename, channel.toString())
} }
} }