Update generate.js
This commit is contained in:
parent
9e29c55e55
commit
cdcd0b0907
|
@ -9,14 +9,13 @@ function main() {
|
||||||
createRootDirectory()
|
createRootDirectory()
|
||||||
createNoJekyllFile()
|
createNoJekyllFile()
|
||||||
generateIndex()
|
generateIndex()
|
||||||
generateSFWIndex()
|
generateCategoryIndex()
|
||||||
generateChannelsJson()
|
|
||||||
generateCountryIndex()
|
generateCountryIndex()
|
||||||
generateLanguageIndex()
|
generateLanguageIndex()
|
||||||
generateCategoryIndex()
|
|
||||||
generateCategories()
|
generateCategories()
|
||||||
generateLanguages()
|
generateLanguages()
|
||||||
generateCountries()
|
generateCountries()
|
||||||
|
generateChannelsJson()
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,20 +34,163 @@ function generateIndex() {
|
||||||
const filename = `${ROOT_DIR}/index.m3u`
|
const filename = `${ROOT_DIR}/index.m3u`
|
||||||
utils.createFile(filename, '#EXTM3U\n')
|
utils.createFile(filename, '#EXTM3U\n')
|
||||||
|
|
||||||
|
const sfwFilename = `${ROOT_DIR}/index.sfw.m3u`
|
||||||
|
utils.createFile(sfwFilename, '#EXTM3U\n')
|
||||||
|
|
||||||
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) {
|
||||||
utils.appendToFile(filename, channel.toString())
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
if (channel.isSFW()) {
|
||||||
|
utils.appendToFile(sfwFilename, channel.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateSFWIndex() {
|
function generateCategoryIndex() {
|
||||||
console.log('Generating index.sfw.m3u...')
|
console.log('Generating index.category.m3u...')
|
||||||
const filename = `${ROOT_DIR}/index.sfw.m3u`
|
const filename = `${ROOT_DIR}/index.category.m3u`
|
||||||
utils.createFile(filename, '#EXTM3U\n')
|
utils.createFile(filename, '#EXTM3U\n')
|
||||||
|
|
||||||
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) {
|
for (const channel of channels) {
|
||||||
utils.appendToFile(filename, channel.toString())
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
if (channel.isSFW()) {
|
||||||
|
utils.appendToFile(sfwFilename, channel.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateCountryIndex() {
|
||||||
|
console.log('Generating index.country.m3u...')
|
||||||
|
const filename = `${ROOT_DIR}/index.country.m3u`
|
||||||
|
utils.createFile(filename, '#EXTM3U\n')
|
||||||
|
|
||||||
|
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 = ''
|
||||||
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
if (sfw) {
|
||||||
|
utils.appendToFile(sfwFilename, channel.toString())
|
||||||
|
}
|
||||||
|
channel.category = category
|
||||||
|
}
|
||||||
|
|
||||||
|
const playlists = db.playlists.sortBy(['country']).except(['unsorted'])
|
||||||
|
for (const playlist of playlists) {
|
||||||
|
for (const channel of playlist.channels) {
|
||||||
|
const category = channel.category
|
||||||
|
const sfw = channel.isSFW()
|
||||||
|
channel.category = playlist.country
|
||||||
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
if (sfw) {
|
||||||
|
utils.appendToFile(sfwFilename, channel.toString())
|
||||||
|
}
|
||||||
|
channel.category = category
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateLanguageIndex() {
|
||||||
|
console.log('Generating index.language.m3u...')
|
||||||
|
const filename = `${ROOT_DIR}/index.language.m3u`
|
||||||
|
utils.createFile(filename, '#EXTM3U\n')
|
||||||
|
|
||||||
|
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 = ''
|
||||||
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
if (sfw) {
|
||||||
|
utils.appendToFile(sfwFilename, channel.toString())
|
||||||
|
}
|
||||||
|
channel.category = category
|
||||||
|
}
|
||||||
|
|
||||||
|
const languages = db.languages.sortBy(['name']).all()
|
||||||
|
for (const language of languages) {
|
||||||
|
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
|
||||||
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
if (sfw) {
|
||||||
|
utils.appendToFile(sfwFilename, channel.toString())
|
||||||
|
}
|
||||||
|
channel.category = category
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateCategories() {
|
||||||
|
console.log(`Generating /categories...`)
|
||||||
|
const outputDir = `${ROOT_DIR}/categories`
|
||||||
|
utils.createDir(outputDir)
|
||||||
|
|
||||||
|
for (const category of [...db.categories.all(), { id: 'other' }]) {
|
||||||
|
const filename = `${outputDir}/${category.id}.m3u`
|
||||||
|
utils.createFile(filename, '#EXTM3U\n')
|
||||||
|
|
||||||
|
const channels = db.channels.sortBy(['name', 'url']).forCategory(category).get()
|
||||||
|
for (const channel of channels) {
|
||||||
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateCountries() {
|
||||||
|
console.log(`Generating /countries...`)
|
||||||
|
const outputDir = `${ROOT_DIR}/countries`
|
||||||
|
utils.createDir(outputDir)
|
||||||
|
|
||||||
|
for (const country of [...db.countries.all(), { code: 'undefined' }]) {
|
||||||
|
const filename = `${outputDir}/${country.code}.m3u`
|
||||||
|
utils.createFile(filename, '#EXTM3U\n')
|
||||||
|
|
||||||
|
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) {
|
||||||
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
if (channel.isSFW()) {
|
||||||
|
utils.appendToFile(sfwFilename, channel.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function generateLanguages() {
|
||||||
|
console.log(`Generating /languages...`)
|
||||||
|
const outputDir = `${ROOT_DIR}/languages`
|
||||||
|
utils.createDir(outputDir)
|
||||||
|
|
||||||
|
for (const language of [...db.languages.all(), { code: 'undefined' }]) {
|
||||||
|
const filename = `${outputDir}/${language.code}.m3u`
|
||||||
|
utils.createFile(filename, '#EXTM3U\n')
|
||||||
|
|
||||||
|
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) {
|
||||||
|
utils.appendToFile(filename, channel.toString())
|
||||||
|
if (channel.isSFW()) {
|
||||||
|
utils.appendToFile(sfwFilename, channel.toString())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,135 +204,6 @@ function generateChannelsJson() {
|
||||||
utils.createFile(filename, JSON.stringify(channels))
|
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 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 playlists = db.playlists.sortBy(['country']).except(['unsorted'])
|
|
||||||
for (const playlist of playlists) {
|
|
||||||
for (const channel of playlist.channels) {
|
|
||||||
const category = channel.category
|
|
||||||
channel.category = playlist.country
|
|
||||||
utils.appendToFile(filename, channel.toString())
|
|
||||||
channel.category = category
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateLanguageIndex() {
|
|
||||||
console.log('Generating index.language.m3u...')
|
|
||||||
const filename = `${ROOT_DIR}/index.language.m3u`
|
|
||||||
utils.createFile(filename, '#EXTM3U\n')
|
|
||||||
|
|
||||||
const channels = db.channels.sortBy(['name', 'url']).forLanguage({ code: null }).get()
|
|
||||||
for (const channel of channels) {
|
|
||||||
const category = channel.category
|
|
||||||
channel.category = ''
|
|
||||||
utils.appendToFile(filename, channel.toString())
|
|
||||||
channel.category = category
|
|
||||||
}
|
|
||||||
|
|
||||||
const languages = db.languages.sortBy(['name']).all()
|
|
||||||
for (const language of languages) {
|
|
||||||
const channels = db.channels.sortBy(['name', 'url']).forLanguage(language).get()
|
|
||||||
for (const channel of channels) {
|
|
||||||
const category = channel.category
|
|
||||||
channel.category = language.name
|
|
||||||
utils.appendToFile(filename, 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 channels = db.channels.sortBy(['category', 'name', 'url']).all()
|
|
||||||
for (const channel of channels) {
|
|
||||||
utils.appendToFile(filename, channel.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateCategories() {
|
|
||||||
console.log(`Generating /categories...`)
|
|
||||||
const outputDir = `${ROOT_DIR}/categories`
|
|
||||||
utils.createDir(outputDir)
|
|
||||||
|
|
||||||
for (const category of db.categories.all()) {
|
|
||||||
const filename = `${outputDir}/${category.id}.m3u`
|
|
||||||
utils.createFile(filename, '#EXTM3U\n')
|
|
||||||
|
|
||||||
const channels = db.channels.sortBy(['name', 'url']).forCategory(category).get()
|
|
||||||
for (const channel of channels) {
|
|
||||||
utils.appendToFile(filename, channel.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
utils.appendToFile(other, channel.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateCountries() {
|
|
||||||
console.log(`Generating /countries...`)
|
|
||||||
const outputDir = `${ROOT_DIR}/countries`
|
|
||||||
utils.createDir(outputDir)
|
|
||||||
|
|
||||||
for (const country of db.countries.all()) {
|
|
||||||
const filename = `${outputDir}/${country.code}.m3u`
|
|
||||||
utils.createFile(filename, '#EXTM3U\n')
|
|
||||||
|
|
||||||
const channels = db.channels.sortBy(['name', 'url']).forCountry(country).get()
|
|
||||||
for (const channel of channels) {
|
|
||||||
utils.appendToFile(filename, channel.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
utils.appendToFile(other, channel.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function generateLanguages() {
|
|
||||||
console.log(`Generating /languages...`)
|
|
||||||
const outputDir = `${ROOT_DIR}/languages`
|
|
||||||
utils.createDir(outputDir)
|
|
||||||
|
|
||||||
for (const language of db.languages.all()) {
|
|
||||||
const filename = `${outputDir}/${language.code}.m3u`
|
|
||||||
utils.createFile(filename, '#EXTM3U\n')
|
|
||||||
|
|
||||||
const channels = db.channels.sortBy(['name', 'url']).forLanguage(language).get()
|
|
||||||
for (const channel of channels) {
|
|
||||||
utils.appendToFile(filename, channel.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
utils.appendToFile(other, channel.toString())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function finish() {
|
function finish() {
|
||||||
console.log(
|
console.log(
|
||||||
`\nTotal: ${db.channels.count()} channels, ${db.countries.count()} countries, ${db.languages.count()} languages, ${db.categories.count()} categories.`
|
`\nTotal: ${db.channels.count()} channels, ${db.countries.count()} countries, ${db.languages.count()} languages, ${db.categories.count()} categories.`
|
||||||
|
|
Loading…
Reference in New Issue