@ -9,14 +9,13 @@ function main() {
createRootDirectory ( )
createNoJekyllFile ( )
generateIndex ( )
generateSFWIndex ( )
generateChannelsJson ( )
generateCategoryIndex ( )
generateCountryIndex ( )
generateLanguageIndex ( )
generateCategoryIndex ( )
generateCategories ( )
generateLanguages ( )
generateCountries ( )
generateChannelsJson ( )
finish ( )
}
@ -35,43 +34,52 @@ function generateIndex() {
const filename = ` ${ ROOT _DIR } /index.m3u `
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 ( )
for ( const channel of channels ) {
utils . appendToFile ( filename , channel . toString ( ) )
if ( channel . isSFW ( ) ) {
utils . appendToFile ( sfwFilename , channel . toString ( ) )
}
}
}
function generate SFW Index( ) {
console . log ( 'Generating index. sfw .m3u...')
const filename = ` ${ ROOT _DIR } /index. sfw .m3u`
function generate Category Index( ) {
console . log ( 'Generating index. category .m3u...')
const filename = ` ${ ROOT _DIR } /index. category .m3u`
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 ) {
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 . toJSON ( ) )
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 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
}
@ -79,8 +87,12 @@ 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
utils . appendToFile ( filename , channel . toString ( ) )
if ( sfw ) {
utils . appendToFile ( sfwFilename , channel . toString ( ) )
}
channel . category = category
}
}
@ -91,11 +103,18 @@ function generateLanguageIndex() {
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
}
@ -104,30 +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
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 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 ( ) ) {
for ( const category of [ ... db . categories . all ( ) , { id : 'other' } ] ) {
const filename = ` ${ outputDir } / ${ category . id } .m3u `
utils . createFile ( filename , '#EXTM3U\n' )
@ -136,13 +148,6 @@ function generateCategories() {
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 ( ) {
@ -150,22 +155,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 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 ( ) )
}
}
}
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 ( ) {
@ -173,22 +177,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 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 ( ) )
}
}
}
}
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 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 ( ) {