Update scripts

This commit is contained in:
freearhey
2025-07-10 21:13:43 +03:00
parent 9de968a18d
commit acb19e72ee
36 changed files with 342 additions and 85 deletions

View File

@@ -17,7 +17,7 @@ export class CategoriesGenerator implements Generator {
logFile: File
constructor({ streams, categories, logFile }: CategoriesGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.categories = categories
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile
@@ -30,7 +30,8 @@ export class CategoriesGenerator implements Generator {
const categoryStreams = streams
.filter((stream: Stream) => stream.hasCategory(category))
.map((stream: Stream) => {
stream.groupTitle = stream.getCategoryNames().join(';')
const groupTitle = stream.getCategoryNames().join(';')
if (groupTitle) stream.groupTitle = groupTitle
return stream
})

View File

@@ -17,7 +17,7 @@ export class CountriesGenerator implements Generator {
logFile: File
constructor({ streams, countries, logFile }: CountriesGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.countries = countries
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile

View File

@@ -1,10 +1,11 @@
export * from './categoriesGenerator'
export * from './countriesGenerator'
export * from './languagesGenerator'
export * from './regionsGenerator'
export * from './indexGenerator'
export * from './indexNsfwGenerator'
export * from './indexCategoryGenerator'
export * from './indexCountryGenerator'
export * from './indexGenerator'
export * from './indexLanguageGenerator'
export * from './indexNsfwGenerator'
export * from './indexRegionGenerator'
export * from './languagesGenerator'
export * from './regionsGenerator'
export * from './sourcesGenerator'

View File

@@ -15,7 +15,7 @@ export class IndexCategoryGenerator implements Generator {
logFile: File
constructor({ streams, logFile }: IndexCategoryGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile
}

View File

@@ -15,7 +15,7 @@ export class IndexCountryGenerator implements Generator {
logFile: File
constructor({ streams, logFile }: IndexCountryGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile
}

View File

@@ -15,7 +15,7 @@ export class IndexGenerator implements Generator {
logFile: File
constructor({ streams, logFile }: IndexGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile
}
@@ -24,6 +24,12 @@ export class IndexGenerator implements Generator {
const sfwStreams = this.streams
.orderBy(stream => stream.getTitle())
.filter((stream: Stream) => stream.isSFW())
.map((stream: Stream) => {
const groupTitle = stream.getCategoryNames().join(';')
if (groupTitle) stream.groupTitle = groupTitle
return stream
})
const playlist = new Playlist(sfwStreams, { public: true })
const filepath = 'index.m3u'

View File

@@ -15,7 +15,7 @@ export class IndexLanguageGenerator implements Generator {
logFile: File
constructor({ streams, logFile }: IndexLanguageGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile
}

View File

@@ -15,7 +15,7 @@ export class IndexNsfwGenerator implements Generator {
logFile: File
constructor({ streams, logFile }: IndexNsfwGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile
}

View File

@@ -17,7 +17,7 @@ export class IndexRegionGenerator implements Generator {
logFile: File
constructor({ streams, regions, logFile }: IndexRegionGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.regions = regions
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile

View File

@@ -12,7 +12,7 @@ export class LanguagesGenerator implements Generator {
logFile: File
constructor({ streams, logFile }: LanguagesGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile
}

View File

@@ -17,7 +17,7 @@ export class RegionsGenerator implements Generator {
logFile: File
constructor({ streams, regions, logFile }: RegionsGeneratorProps) {
this.streams = streams
this.streams = streams.clone()
this.regions = regions
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile

View File

@@ -0,0 +1,44 @@
import { Collection, Storage, File, type Dictionary } from '@freearhey/core'
import { Stream, Playlist } from '../models'
import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type SourcesGeneratorProps = {
streams: Collection
logFile: File
}
export class SourcesGenerator implements Generator {
streams: Collection
storage: Storage
logFile: File
constructor({ streams, logFile }: SourcesGeneratorProps) {
this.streams = streams.clone()
this.storage = new Storage(PUBLIC_DIR)
this.logFile = logFile
}
async generate() {
const files: Dictionary = this.streams.groupBy((stream: Stream) => stream.getFilename())
for (let filename of files.keys()) {
if (!filename) continue
let streams = new Collection(files.get(filename))
streams = streams.map((stream: Stream) => {
const groupTitle = stream.getCategoryNames().join(';')
if (groupTitle) stream.groupTitle = groupTitle
return stream
})
const playlist = new Playlist(streams, { public: true })
const filepath = `sources/${filename}`
await this.storage.save(filepath, playlist.toString())
this.logFile.append(
JSON.stringify({ type: 'source', filepath, count: playlist.streams.count() }) + EOL
)
}
}
}