Merge branch 'master' into remove-duplicates-from-generated-playlists

This commit is contained in:
freearhey 2021-05-08 14:50:18 +03:00
commit b0d510fc7f
31 changed files with 343 additions and 382 deletions

View file

@ -2,6 +2,8 @@ const categories = require('./categories')
const parser = require('./parser')
const utils = require('./utils')
const sfwCategories = categories.filter(c => !c.nsfw).map(c => c.name)
const db = {}
db.load = function () {
@ -38,7 +40,7 @@ db.channels = {
if (this.filter) {
switch (this.filter.field) {
case 'countries':
if (!this.filter.value) {
if (this.filter.value === 'undefined') {
output = this.list.filter(channel => !channel.countries.length)
} else {
output = this.list.filter(channel =>
@ -47,7 +49,7 @@ db.channels = {
}
break
case 'languages':
if (!this.filter.value) {
if (this.filter.value === 'undefined') {
output = this.list.filter(channel => !channel.languages.length)
} else {
output = this.list.filter(channel =>
@ -56,7 +58,7 @@ db.channels = {
}
break
case 'category':
if (!this.filter.value) {
if (this.filter.value === 'other') {
output = this.list.filter(channel => !channel.category)
} else {
output = this.list.filter(
@ -77,8 +79,6 @@ db.channels = {
return this.list
},
sfw() {
const sfwCategories = categories.filter(c => !c.nsfw).map(c => c.name)
return this.list.filter(i => sfwCategories.includes(i.category))
},
forCountry(country) {

View file

@ -9,14 +9,13 @@ function main() {
createRootDirectory()
createNoJekyllFile()
generateIndex()
generateSFWIndex()
generateChannelsJson()
generateCategoryIndex()
generateCountryIndex()
generateLanguageIndex()
generateCategoryIndex()
generateCategories()
generateLanguages()
generateCountries()
generateChannelsJson()
finish()
}
@ -35,57 +34,51 @@ function generateIndex() {
const filename = `${ROOT_DIR}/index.m3u`
utils.createFile(filename, '#EXTM3U\n')
const buffer = []
const sfwFilename = `${ROOT_DIR}/index.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n')
const channels = db.channels.sortBy(['name', 'url']).all()
for (const channel of channels) {
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
utils.appendToFile(filename, channel.toString())
if (channel.isSFW()) {
utils.appendToFile(sfwFilename, channel.toString())
}
}
}
function generateSFWIndex() {
console.log('Generating index.sfw.m3u...')
const filename = `${ROOT_DIR}/index.sfw.m3u`
function generateCategoryIndex() {
console.log('Generating index.category.m3u...')
const filename = `${ROOT_DIR}/index.category.m3u`
utils.createFile(filename, '#EXTM3U\n')
const buffer = []
const channels = db.channels.sortBy(['name', 'url']).sfw()
const sfwFilename = `${ROOT_DIR}/index.category.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n')
const channels = db.channels.sortBy(['category', 'name', 'url']).all()
for (const channel of channels) {
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
utils.appendToFile(filename, channel.toString())
if (channel.isSFW()) {
utils.appendToFile(sfwFilename, channel.toString())
}
}
}
function generateChannelsJson() {
console.log('Generating channels.json...')
const filename = `${ROOT_DIR}/channels.json`
const channels = db.channels
.sortBy(['name', 'url'])
.all()
.map(c => c.toObject())
utils.createFile(filename, JSON.stringify(channels))
}
function generateCountryIndex() {
console.log('Generating index.country.m3u...')
const filename = `${ROOT_DIR}/index.country.m3u`
utils.createFile(filename, '#EXTM3U\n')
const buffer = []
const sfwFilename = `${ROOT_DIR}/index.country.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n')
const unsorted = db.playlists.only(['unsorted'])[0]
for (const channel of unsorted.channels) {
const category = channel.category
const sfw = channel.isSFW()
channel.category = ''
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
utils.appendToFile(filename, channel.toString())
if (sfw) {
utils.appendToFile(sfwFilename, channel.toString())
}
channel.category = category
}
@ -94,11 +87,11 @@ function generateCountryIndex() {
for (const playlist of playlists) {
for (const channel of playlist.channels) {
const category = channel.category
const sfw = channel.isSFW()
channel.category = playlist.country
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
utils.appendToFile(filename, channel.toString())
if (sfw) {
utils.appendToFile(sfwFilename, channel.toString())
}
channel.category = category
}
@ -110,15 +103,17 @@ function generateLanguageIndex() {
const filename = `${ROOT_DIR}/index.language.m3u`
utils.createFile(filename, '#EXTM3U\n')
const buffer = []
const sfwFilename = `${ROOT_DIR}/index.language.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n')
const channels = db.channels.sortBy(['name', 'url']).forLanguage({ code: null }).get()
for (const channel of channels) {
const category = channel.category
const sfw = channel.isSFW()
channel.category = ''
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
utils.appendToFile(filename, channel.toString())
if (sfw) {
utils.appendToFile(sfwFilename, channel.toString())
}
channel.category = category
}
@ -128,39 +123,23 @@ function generateLanguageIndex() {
const channels = db.channels.sortBy(['name', 'url']).forLanguage(language).get()
for (const channel of channels) {
const category = channel.category
const sfw = channel.isSFW()
channel.category = language.name
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
utils.appendToFile(filename, channel.toString())
if (sfw) {
utils.appendToFile(sfwFilename, channel.toString())
}
channel.category = category
}
}
}
function generateCategoryIndex() {
console.log('Generating index.category.m3u...')
const filename = `${ROOT_DIR}/index.category.m3u`
utils.createFile(filename, '#EXTM3U\n')
const buffer = []
const channels = db.channels.sortBy(['category', 'name', 'url']).all()
for (const channel of channels) {
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
}
}
}
function generateCategories() {
console.log(`Generating /categories...`)
const outputDir = `${ROOT_DIR}/categories`
utils.createDir(outputDir)
for (const category of db.categories.all()) {
for (const category of [...db.categories.all(), { id: 'other' }]) {
const filename = `${outputDir}/${category.id}.m3u`
utils.createFile(filename, '#EXTM3U\n')
@ -174,18 +153,6 @@ function generateCategories() {
}
}
}
const buffer = []
const other = `${outputDir}/other.m3u`
const channels = db.channels.sortBy(['name', 'url']).forCategory({ id: null }).get()
utils.createFile(other, '#EXTM3U\n')
for (const channel of channels) {
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(other, channel.toString())
buffer.push(info)
}
}
}
function generateCountries() {
@ -193,32 +160,21 @@ function generateCountries() {
const outputDir = `${ROOT_DIR}/countries`
utils.createDir(outputDir)
for (const country of db.countries.all()) {
for (const country of [...db.countries.all(), { code: 'undefined' }]) {
const filename = `${outputDir}/${country.code}.m3u`
utils.createFile(filename, '#EXTM3U\n')
const buffer = []
const sfwFilename = `${outputDir}/${country.code}.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n')
const channels = db.channels.sortBy(['name', 'url']).forCountry(country).get()
for (const channel of channels) {
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
utils.appendToFile(filename, channel.toString())
if (channel.isSFW()) {
utils.appendToFile(sfwFilename, channel.toString())
}
}
}
const buffer = []
const other = `${outputDir}/undefined.m3u`
const channels = db.channels.sortBy(['name', 'url']).forCountry({ code: null }).get()
utils.createFile(other, '#EXTM3U\n')
for (const channel of channels) {
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(other, channel.toString())
buffer.push(info)
}
}
}
function generateLanguages() {
@ -226,32 +182,31 @@ function generateLanguages() {
const outputDir = `${ROOT_DIR}/languages`
utils.createDir(outputDir)
for (const language of db.languages.all()) {
for (const language of [...db.languages.all(), { code: 'undefined' }]) {
const filename = `${outputDir}/${language.code}.m3u`
utils.createFile(filename, '#EXTM3U\n')
const buffer = []
const sfwFilename = `${outputDir}/${language.code}.sfw.m3u`
utils.createFile(sfwFilename, '#EXTM3U\n')
const channels = db.channels.sortBy(['name', 'url']).forLanguage(language).get()
for (const channel of channels) {
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(filename, channel.toString())
buffer.push(info)
utils.appendToFile(filename, channel.toString())
if (channel.isSFW()) {
utils.appendToFile(sfwFilename, channel.toString())
}
}
}
}
const buffer = []
const other = `${outputDir}/undefined.m3u`
const channels = db.channels.sortBy(['name', 'url']).forLanguage({ code: null }).get()
utils.createFile(other, '#EXTM3U\n')
for (const channel of channels) {
const info = channel.toString()
if (!buffer.includes(info)) {
utils.appendToFile(other, channel.toString())
buffer.push(info)
}
}
function generateChannelsJson() {
console.log('Generating channels.json...')
const filename = `${ROOT_DIR}/channels.json`
const channels = db.channels
.sortBy(['name', 'url'])
.all()
.map(c => c.toJSON())
utils.createFile(filename, JSON.stringify(channels))
}
function finish() {

View file

@ -3,6 +3,8 @@ const utils = require('./utils')
const categories = require('./categories')
const path = require('path')
const sfwCategories = categories.filter(c => !c.nsfw).map(c => c.name)
const parser = {}
parser.parseIndex = function () {
@ -232,6 +234,10 @@ class Channel {
}
}
}
isSFW() {
return sfwCategories.includes(this.category)
}
}
module.exports = parser