2021-02-10 14:39:40 +01:00
|
|
|
const db = require('./db')
|
2021-01-30 00:26:23 +01:00
|
|
|
const utils = require('./utils')
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-11-02 11:26:21 +01:00
|
|
|
const ROOT_DIR = './.gh-pages'
|
|
|
|
|
2021-02-10 14:39:40 +01:00
|
|
|
db.load()
|
2019-04-23 20:49:09 +02:00
|
|
|
|
2019-11-01 22:27:05 +01:00
|
|
|
function main() {
|
2019-11-03 18:25:33 +01:00
|
|
|
createRootDirectory()
|
2019-11-13 15:27:59 +01:00
|
|
|
createNoJekyllFile()
|
2019-11-02 11:50:56 +01:00
|
|
|
generateIndex()
|
2021-05-07 17:34:14 +02:00
|
|
|
generateCategoryIndex()
|
2019-11-01 22:27:05 +01:00
|
|
|
generateCountryIndex()
|
|
|
|
generateLanguageIndex()
|
2021-01-30 00:26:23 +01:00
|
|
|
generateCategories()
|
2021-02-11 05:55:54 +01:00
|
|
|
generateCountries()
|
2021-05-08 13:53:42 +02:00
|
|
|
generateLanguages()
|
2021-05-07 17:34:14 +02:00
|
|
|
generateChannelsJson()
|
2021-01-30 00:26:23 +01:00
|
|
|
finish()
|
2019-11-01 22:27:05 +01:00
|
|
|
}
|
|
|
|
|
2019-11-03 18:25:33 +01:00
|
|
|
function createRootDirectory() {
|
2021-02-10 14:39:40 +01:00
|
|
|
console.log('Creating .gh-pages folder...')
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createDir(ROOT_DIR)
|
2019-11-02 11:26:21 +01:00
|
|
|
}
|
|
|
|
|
2019-11-13 15:27:59 +01:00
|
|
|
function createNoJekyllFile() {
|
2021-02-11 05:55:54 +01:00
|
|
|
console.log('Creating .nojekyll...')
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createFile(`${ROOT_DIR}/.nojekyll`)
|
2019-11-13 15:27:59 +01:00
|
|
|
}
|
|
|
|
|
2019-11-02 11:50:56 +01:00
|
|
|
function generateIndex() {
|
2021-01-30 00:26:23 +01:00
|
|
|
console.log('Generating index.m3u...')
|
2019-11-02 11:50:56 +01:00
|
|
|
const filename = `${ROOT_DIR}/index.m3u`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createFile(filename, '#EXTM3U\n')
|
2019-11-02 11:50:56 +01:00
|
|
|
|
2021-06-05 16:13:09 +02:00
|
|
|
const nsfwFilename = `${ROOT_DIR}/index.nsfw.m3u`
|
|
|
|
utils.createFile(nsfwFilename, '#EXTM3U\n')
|
2021-05-07 17:34:14 +02:00
|
|
|
|
2021-05-10 15:25:26 +02:00
|
|
|
const channels = db.channels.sortBy(['name', 'url']).removeDuplicates().get()
|
2021-02-10 15:10:30 +01:00
|
|
|
for (const channel of channels) {
|
2021-06-05 16:13:09 +02:00
|
|
|
if (!channel.isNSFW()) {
|
|
|
|
utils.appendToFile(filename, channel.toString())
|
2021-04-24 14:44:04 +02:00
|
|
|
}
|
2021-06-05 16:13:09 +02:00
|
|
|
utils.appendToFile(nsfwFilename, channel.toString())
|
2019-11-02 11:50:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-07 17:34:14 +02:00
|
|
|
function generateCategoryIndex() {
|
|
|
|
console.log('Generating index.category.m3u...')
|
|
|
|
const filename = `${ROOT_DIR}/index.category.m3u`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createFile(filename, '#EXTM3U\n')
|
2021-01-27 16:54:08 +01:00
|
|
|
|
2021-05-10 15:25:26 +02:00
|
|
|
const channels = db.channels.sortBy(['category', 'name', 'url']).removeDuplicates().get()
|
2021-02-10 15:10:30 +01:00
|
|
|
for (const channel of channels) {
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.appendToFile(filename, channel.toString())
|
2021-01-27 16:54:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
function generateCountryIndex() {
|
2021-01-30 00:26:23 +01:00
|
|
|
console.log('Generating index.country.m3u...')
|
2019-11-02 11:26:21 +01:00
|
|
|
const filename = `${ROOT_DIR}/index.country.m3u`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createFile(filename, '#EXTM3U\n')
|
2019-11-01 22:08:27 +01:00
|
|
|
|
2021-05-10 15:25:26 +02:00
|
|
|
for (const country of [{ code: 'undefined' }, ...db.countries.sortBy(['name']).all()]) {
|
|
|
|
const channels = db.channels
|
|
|
|
.sortBy(['name', 'url'])
|
|
|
|
.forCountry(country)
|
|
|
|
.removeDuplicates()
|
|
|
|
.get()
|
|
|
|
for (const channel of channels) {
|
2021-02-10 09:57:56 +01:00
|
|
|
const category = channel.category
|
2021-06-05 16:13:09 +02:00
|
|
|
const nsfw = channel.isNSFW()
|
2021-05-10 15:25:26 +02:00
|
|
|
channel.category = country.name || ''
|
2021-06-05 16:13:09 +02:00
|
|
|
if (!nsfw) {
|
|
|
|
utils.appendToFile(filename, channel.toString())
|
2021-04-24 14:44:04 +02:00
|
|
|
}
|
2021-02-10 09:57:56 +01:00
|
|
|
channel.category = category
|
|
|
|
}
|
2019-04-23 20:49:09 +02:00
|
|
|
}
|
2019-11-01 22:08:27 +01:00
|
|
|
}
|
2019-09-14 02:07:54 +02:00
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
function generateLanguageIndex() {
|
2021-01-30 00:26:23 +01:00
|
|
|
console.log('Generating index.language.m3u...')
|
2019-11-02 11:26:21 +01:00
|
|
|
const filename = `${ROOT_DIR}/index.language.m3u`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createFile(filename, '#EXTM3U\n')
|
2019-11-01 22:08:27 +01:00
|
|
|
|
2021-05-10 15:25:26 +02:00
|
|
|
for (const language of [{ code: 'undefined' }, ...db.languages.sortBy(['name']).all()]) {
|
|
|
|
const channels = db.channels
|
|
|
|
.sortBy(['name', 'url'])
|
|
|
|
.forLanguage(language)
|
|
|
|
.removeDuplicates()
|
|
|
|
.get()
|
2021-02-10 15:03:47 +01:00
|
|
|
for (const channel of channels) {
|
|
|
|
const category = channel.category
|
2021-06-05 16:13:09 +02:00
|
|
|
const nsfw = channel.isNSFW()
|
2021-05-10 15:25:26 +02:00
|
|
|
channel.category = language.name || ''
|
2021-06-05 16:13:09 +02:00
|
|
|
if (!nsfw) {
|
|
|
|
utils.appendToFile(filename, channel.toString())
|
2021-04-24 14:44:04 +02:00
|
|
|
}
|
2021-02-10 15:03:47 +01:00
|
|
|
channel.category = category
|
|
|
|
}
|
|
|
|
}
|
2019-11-01 22:08:27 +01:00
|
|
|
}
|
2019-10-31 12:58:34 +01:00
|
|
|
|
2021-02-10 15:03:47 +01:00
|
|
|
function generateCategories() {
|
2021-02-11 05:55:54 +01:00
|
|
|
console.log(`Generating /categories...`)
|
2021-02-10 15:03:47 +01:00
|
|
|
const outputDir = `${ROOT_DIR}/categories`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createDir(outputDir)
|
2019-11-02 11:50:56 +01:00
|
|
|
|
2021-05-07 17:34:14 +02:00
|
|
|
for (const category of [...db.categories.all(), { id: 'other' }]) {
|
2021-02-10 15:03:47 +01:00
|
|
|
const filename = `${outputDir}/${category.id}.m3u`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createFile(filename, '#EXTM3U\n')
|
2019-11-02 13:43:41 +01:00
|
|
|
|
2021-05-10 15:25:26 +02:00
|
|
|
const channels = db.channels
|
|
|
|
.sortBy(['name', 'url'])
|
|
|
|
.forCategory(category)
|
|
|
|
.removeDuplicates()
|
|
|
|
.get()
|
2021-01-30 04:18:21 +01:00
|
|
|
for (const channel of channels) {
|
2021-05-08 14:43:34 +02:00
|
|
|
utils.appendToFile(filename, channel.toString())
|
2019-11-02 11:50:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 15:03:47 +01:00
|
|
|
function generateCountries() {
|
2021-02-11 05:55:54 +01:00
|
|
|
console.log(`Generating /countries...`)
|
2021-02-10 15:03:47 +01:00
|
|
|
const outputDir = `${ROOT_DIR}/countries`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createDir(outputDir)
|
2019-11-02 11:26:21 +01:00
|
|
|
|
2021-05-07 17:34:14 +02:00
|
|
|
for (const country of [...db.countries.all(), { code: 'undefined' }]) {
|
2021-02-10 15:03:47 +01:00
|
|
|
const filename = `${outputDir}/${country.code}.m3u`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createFile(filename, '#EXTM3U\n')
|
2019-11-02 13:43:41 +01:00
|
|
|
|
2021-05-10 15:25:26 +02:00
|
|
|
const channels = db.channels
|
|
|
|
.sortBy(['name', 'url'])
|
|
|
|
.forCountry(country)
|
|
|
|
.removeDuplicates()
|
|
|
|
.get()
|
2021-01-30 04:18:21 +01:00
|
|
|
for (const channel of channels) {
|
2021-06-05 16:13:09 +02:00
|
|
|
if (!channel.isNSFW()) {
|
|
|
|
utils.appendToFile(filename, channel.toString())
|
2021-04-24 14:44:04 +02:00
|
|
|
}
|
2019-11-01 22:21:08 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-10 15:03:47 +01:00
|
|
|
function generateLanguages() {
|
2021-02-11 05:55:54 +01:00
|
|
|
console.log(`Generating /languages...`)
|
2021-02-10 15:03:47 +01:00
|
|
|
const outputDir = `${ROOT_DIR}/languages`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createDir(outputDir)
|
2019-11-02 11:50:56 +01:00
|
|
|
|
2021-05-07 17:34:14 +02:00
|
|
|
for (const language of [...db.languages.all(), { code: 'undefined' }]) {
|
2021-02-10 15:03:47 +01:00
|
|
|
const filename = `${outputDir}/${language.code}.m3u`
|
2021-01-30 00:26:23 +01:00
|
|
|
utils.createFile(filename, '#EXTM3U\n')
|
2019-11-02 13:43:41 +01:00
|
|
|
|
2021-05-10 15:25:26 +02:00
|
|
|
const channels = db.channels
|
|
|
|
.sortBy(['name', 'url'])
|
|
|
|
.forLanguage(language)
|
|
|
|
.removeDuplicates()
|
|
|
|
.get()
|
2021-01-30 04:18:21 +01:00
|
|
|
for (const channel of channels) {
|
2021-06-05 16:13:09 +02:00
|
|
|
if (!channel.isNSFW()) {
|
|
|
|
utils.appendToFile(filename, channel.toString())
|
2021-04-24 14:44:04 +02:00
|
|
|
}
|
2019-11-01 22:21:08 +01:00
|
|
|
}
|
|
|
|
}
|
2021-05-07 17:34:14 +02:00
|
|
|
}
|
2021-02-10 15:14:43 +01:00
|
|
|
|
2021-05-07 17:34:14 +02:00
|
|
|
function generateChannelsJson() {
|
|
|
|
console.log('Generating channels.json...')
|
|
|
|
const filename = `${ROOT_DIR}/channels.json`
|
|
|
|
const channels = db.channels
|
|
|
|
.sortBy(['name', 'url'])
|
2021-05-10 15:25:26 +02:00
|
|
|
.get()
|
2021-05-08 13:53:42 +02:00
|
|
|
.map(c => c.toObject())
|
2021-05-07 17:34:14 +02:00
|
|
|
utils.createFile(filename, JSON.stringify(channels))
|
2019-11-01 22:21:08 +01:00
|
|
|
}
|
|
|
|
|
2021-01-30 00:26:23 +01:00
|
|
|
function finish() {
|
|
|
|
console.log(
|
2021-02-11 05:55:54 +01:00
|
|
|
`\nTotal: ${db.channels.count()} channels, ${db.countries.count()} countries, ${db.languages.count()} languages, ${db.categories.count()} categories.`
|
2021-01-30 00:26:23 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2019-11-01 22:08:27 +01:00
|
|
|
main()
|