Update scripts

This commit is contained in:
freearhey
2025-04-23 20:56:19 +03:00
parent 7f78b5770e
commit e6354bdd23
15 changed files with 144 additions and 118 deletions

View File

@@ -1,22 +1,23 @@
import { Generator } from './generator'
import { Collection, Storage, Logger } from '@freearhey/core'
import { Collection, Storage, File } from '@freearhey/core'
import { Stream, Playlist, Category } from '../models'
import { PUBLIC_DIR } from '../constants'
import { Generator } from './generator'
import { EOL } from 'node:os'
type IndexCategoryGeneratorProps = {
streams: Collection
logger: Logger
logFile: File
}
export class IndexCategoryGenerator implements Generator {
streams: Collection
storage: Storage
logger: Logger
logFile: File
constructor({ streams, logger }: IndexCategoryGeneratorProps) {
constructor({ streams, logFile }: IndexCategoryGeneratorProps) {
this.streams = streams
this.storage = new Storage(PUBLIC_DIR)
this.logger = logger
this.logFile = logFile
}
async generate(): Promise<void> {
@@ -48,6 +49,8 @@ export class IndexCategoryGenerator implements Generator {
const playlist = new Playlist(groupedStreams, { public: true })
const filepath = 'index.category.m3u'
await this.storage.save(filepath, playlist.toString())
this.logger.info(JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }))
this.logFile.append(
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
)
}
}