Update generate.js

This commit is contained in:
freearhey 2021-05-08 15:43:34 +03:00
parent 246d4a9b48
commit debf3c4170
1 changed files with 45 additions and 7 deletions

View File

@ -37,8 +37,13 @@ function generateIndex() {
const sfwFilename = `${ROOT_DIR}/index.sfw.m3u` const sfwFilename = `${ROOT_DIR}/index.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n') utils.createFile(sfwFilename, '#EXTM3U\n')
const buffer = []
const channels = db.channels.sortBy(['name', 'url']).all() const channels = db.channels.sortBy(['name', 'url']).all()
for (const channel of channels) { for (const channel of channels) {
const info = channel.getInfo()
if (buffer.includes(info)) continue
buffer.push(info)
utils.appendToFile(filename, channel.toString()) utils.appendToFile(filename, channel.toString())
if (channel.isSFW()) { if (channel.isSFW()) {
utils.appendToFile(sfwFilename, channel.toString()) utils.appendToFile(sfwFilename, channel.toString())
@ -54,8 +59,13 @@ function generateCategoryIndex() {
const sfwFilename = `${ROOT_DIR}/index.category.sfw.m3u` const sfwFilename = `${ROOT_DIR}/index.category.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n') utils.createFile(sfwFilename, '#EXTM3U\n')
const buffer = []
const channels = db.channels.sortBy(['category', 'name', 'url']).all() const channels = db.channels.sortBy(['category', 'name', 'url']).all()
for (const channel of channels) { for (const channel of channels) {
const info = channel.getInfo()
if (buffer.includes(info)) continue
buffer.push(info)
utils.appendToFile(filename, channel.toString()) utils.appendToFile(filename, channel.toString())
if (channel.isSFW()) { if (channel.isSFW()) {
utils.appendToFile(sfwFilename, channel.toString()) utils.appendToFile(sfwFilename, channel.toString())
@ -71,8 +81,13 @@ function generateCountryIndex() {
const sfwFilename = `${ROOT_DIR}/index.country.sfw.m3u` const sfwFilename = `${ROOT_DIR}/index.country.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n') utils.createFile(sfwFilename, '#EXTM3U\n')
const buffer = []
const unsorted = db.playlists.only(['unsorted'])[0] const unsorted = db.playlists.only(['unsorted'])[0]
for (const channel of unsorted.channels) { for (const channel of unsorted.channels) {
const info = channel.getInfo()
if (buffer.includes(info)) continue
buffer.push(info)
const category = channel.category const category = channel.category
const sfw = channel.isSFW() const sfw = channel.isSFW()
channel.category = '' channel.category = ''
@ -86,6 +101,10 @@ function generateCountryIndex() {
const playlists = db.playlists.sortBy(['country']).except(['unsorted']) const playlists = db.playlists.sortBy(['country']).except(['unsorted'])
for (const playlist of playlists) { for (const playlist of playlists) {
for (const channel of playlist.channels) { for (const channel of playlist.channels) {
const info = channel.getInfo()
if (buffer.includes(info)) continue
buffer.push(info)
const category = channel.category const category = channel.category
const sfw = channel.isSFW() const sfw = channel.isSFW()
channel.category = playlist.country channel.category = playlist.country
@ -106,8 +125,13 @@ function generateLanguageIndex() {
const sfwFilename = `${ROOT_DIR}/index.language.sfw.m3u` const sfwFilename = `${ROOT_DIR}/index.language.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n') utils.createFile(sfwFilename, '#EXTM3U\n')
const channels = db.channels.sortBy(['name', 'url']).forLanguage({ code: null }).get() const buffer = []
const channels = db.channels.sortBy(['name', 'url']).forLanguage({ code: 'undefined' }).get()
for (const channel of channels) { for (const channel of channels) {
const info = channel.getInfo()
if (buffer.includes(info)) continue
buffer.push(info)
const category = channel.category const category = channel.category
const sfw = channel.isSFW() const sfw = channel.isSFW()
channel.category = '' channel.category = ''
@ -122,6 +146,10 @@ function generateLanguageIndex() {
for (const language of languages) { for (const language of languages) {
const channels = db.channels.sortBy(['name', 'url']).forLanguage(language).get() const channels = db.channels.sortBy(['name', 'url']).forLanguage(language).get()
for (const channel of channels) { for (const channel of channels) {
const info = channel.getInfo()
if (buffer.includes(info)) continue
buffer.push(info)
const category = channel.category const category = channel.category
const sfw = channel.isSFW() const sfw = channel.isSFW()
channel.category = language.name channel.category = language.name
@ -139,18 +167,18 @@ function generateCategories() {
const outputDir = `${ROOT_DIR}/categories` const outputDir = `${ROOT_DIR}/categories`
utils.createDir(outputDir) utils.createDir(outputDir)
const buffer = []
for (const category of [...db.categories.all(), { id: 'other' }]) { for (const category of [...db.categories.all(), { id: 'other' }]) {
const filename = `${outputDir}/${category.id}.m3u` const filename = `${outputDir}/${category.id}.m3u`
utils.createFile(filename, '#EXTM3U\n') utils.createFile(filename, '#EXTM3U\n')
const buffer = []
const channels = db.channels.sortBy(['name', 'url']).forCategory(category).get() const channels = db.channels.sortBy(['name', 'url']).forCategory(category).get()
for (const channel of channels) { for (const channel of channels) {
const info = channel.toString() const info = channel.getInfo()
if (!buffer.includes(info)) { if (buffer.includes(info)) continue
utils.appendToFile(filename, channel.toString()) buffer.push(info)
buffer.push(info)
} utils.appendToFile(filename, channel.toString())
} }
} }
} }
@ -160,6 +188,7 @@ function generateCountries() {
const outputDir = `${ROOT_DIR}/countries` const outputDir = `${ROOT_DIR}/countries`
utils.createDir(outputDir) utils.createDir(outputDir)
const buffer = []
for (const country of [...db.countries.all(), { code: 'undefined' }]) { for (const country of [...db.countries.all(), { code: 'undefined' }]) {
const filename = `${outputDir}/${country.code}.m3u` const filename = `${outputDir}/${country.code}.m3u`
utils.createFile(filename, '#EXTM3U\n') utils.createFile(filename, '#EXTM3U\n')
@ -169,6 +198,10 @@ function generateCountries() {
const channels = db.channels.sortBy(['name', 'url']).forCountry(country).get() const channels = db.channels.sortBy(['name', 'url']).forCountry(country).get()
for (const channel of channels) { for (const channel of channels) {
const info = channel.getInfo()
if (buffer.includes(info)) continue
buffer.push(info)
utils.appendToFile(filename, channel.toString()) utils.appendToFile(filename, channel.toString())
if (channel.isSFW()) { if (channel.isSFW()) {
utils.appendToFile(sfwFilename, channel.toString()) utils.appendToFile(sfwFilename, channel.toString())
@ -182,6 +215,7 @@ function generateLanguages() {
const outputDir = `${ROOT_DIR}/languages` const outputDir = `${ROOT_DIR}/languages`
utils.createDir(outputDir) utils.createDir(outputDir)
const buffer = []
for (const language of [...db.languages.all(), { code: 'undefined' }]) { for (const language of [...db.languages.all(), { code: 'undefined' }]) {
const filename = `${outputDir}/${language.code}.m3u` const filename = `${outputDir}/${language.code}.m3u`
utils.createFile(filename, '#EXTM3U\n') utils.createFile(filename, '#EXTM3U\n')
@ -191,6 +225,10 @@ function generateLanguages() {
const channels = db.channels.sortBy(['name', 'url']).forLanguage(language).get() const channels = db.channels.sortBy(['name', 'url']).forLanguage(language).get()
for (const channel of channels) { for (const channel of channels) {
const info = channel.getInfo()
if (buffer.includes(info)) continue
buffer.push(info)
utils.appendToFile(filename, channel.toString()) utils.appendToFile(filename, channel.toString())
if (channel.isSFW()) { if (channel.isSFW()) {
utils.appendToFile(sfwFilename, channel.toString()) utils.appendToFile(sfwFilename, channel.toString())