From 2fa712c1ada9043bf413450b2314f105abadb5bc Mon Sep 17 00:00:00 2001 From: freearhey Date: Sat, 20 Feb 2021 15:46:56 +0300 Subject: [PATCH 1/3] Update db.js --- scripts/db.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/db.js b/scripts/db.js index 77ad2eda32..91795217e6 100644 --- a/scripts/db.js +++ b/scripts/db.js @@ -8,6 +8,7 @@ db.load = function () { const items = parser.parseIndex() for (const item of items) { const playlist = parser.parsePlaylist(item.url) + db.playlists.add(playlist) for (const channel of playlist.channels) { db.channels.add(channel) @@ -166,4 +167,28 @@ db.categories = { } } +db.playlists = { + list: [], + add(playlist) { + this.list.push(playlist) + }, + all() { + return this.list + }, + only(list = []) { + return this.list.filter(playlist => list.includes(playlist.name)) + }, + except(list = []) { + return this.list.filter(playlist => !list.includes(playlist.name)) + }, + sortBy(fields) { + this.list = utils.sortBy(this.list, fields) + + return this + }, + count() { + return this.list.length + } +} + module.exports = db From 4998c24d3bd4dcb72f4d0bf12f95fae296c9ba8c Mon Sep 17 00:00:00 2001 From: freearhey Date: Sat, 20 Feb 2021 15:47:05 +0300 Subject: [PATCH 2/3] Update parser.js --- scripts/parser.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scripts/parser.js b/scripts/parser.js index ca43d90c48..9af768677f 100644 --- a/scripts/parser.js +++ b/scripts/parser.js @@ -2,6 +2,7 @@ const playlistParser = require('iptv-playlist-parser') const epgParser = require('epg-parser') const utils = require('./utils') const categories = require('./categories') +const path = require('path'); const parser = {} @@ -15,8 +16,10 @@ parser.parseIndex = function () { parser.parsePlaylist = function (filename) { const content = utils.readFile(filename) const result = playlistParser.parse(content) + const name = path.parse(filename).name + const country = utils.code2name(name) - return new Playlist({ header: result.header, items: result.items, url: filename }) + return new Playlist({ header: result.header, items: result.items, url: filename, country, name }) } parser.parseEPG = async function (url) { @@ -32,8 +35,10 @@ parser.parseEPG = async function (url) { } class Playlist { - constructor({ header, items, url }) { + constructor({ header, items, url, name, country }) { this.url = url + this.name = name + this.country = country this.header = header this.channels = items .map(item => new Channel({ data: item, header, sourceUrl: url })) From 6517e9552c2dabe310cdb2c3a90a2fa5ab01b741 Mon Sep 17 00:00:00 2001 From: freearhey Date: Sat, 20 Feb 2021 15:47:41 +0300 Subject: [PATCH 3/3] Update generate.js --- scripts/generate.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/scripts/generate.js b/scripts/generate.js index 6c6a0af262..369483ecd5 100644 --- a/scripts/generate.js +++ b/scripts/generate.js @@ -67,20 +67,19 @@ function generateCountryIndex() { const filename = `${ROOT_DIR}/index.country.m3u` utils.createFile(filename, '#EXTM3U\n') - const channels = db.channels.sortBy(['name', 'url']).forCountry({ code: null }).get() - for (const channel of channels) { + const unsorted = db.playlists.only(['unsorted'])[0] + for (const channel of unsorted.channels) { const category = channel.category channel.category = '' utils.appendToFile(filename, channel.toString()) channel.category = category } - const countries = db.countries.sortBy(['name']).all() - for (const country of countries) { - const channels = db.channels.sortBy(['name', 'url']).forCountry(country).get() - for (const channel of channels) { + const playlists = db.playlists.sortBy(['country']).except(['unsorted']) + for (const playlist of playlists) { + for (const channel of playlist.channels) { const category = channel.category - channel.category = country.name + channel.category = playlist.country utils.appendToFile(filename, channel.toString()) channel.category = category }