Files
iptv/scripts/generators/indexNsfwGenerator.ts

31 lines
927 B
TypeScript
Raw Normal View History

2023-09-22 06:22:47 +03:00
import { Collection, Logger, Storage } from '@freearhey/core'
import { Stream, Playlist } from '../models'
import { Generator } from './generator'
import { PUBLIC_DIR } from '../constants'
type IndexNsfwGeneratorProps = {
streams: Collection
logger: Logger
}
export class IndexNsfwGenerator implements Generator {
streams: Collection
storage: Storage
logger: Logger
constructor({ streams, logger }: IndexNsfwGeneratorProps) {
this.streams = streams
this.storage = new Storage(PUBLIC_DIR)
this.logger = logger
}
async generate(): Promise<void> {
const allStreams = this.streams.orderBy((stream: Stream) => stream.getTitle())
const playlist = new Playlist(allStreams, { public: true })
const filepath = 'index.nsfw.m3u'
await this.storage.save(filepath, playlist.toString())
2025-03-29 11:39:46 +03:00
this.logger.info(JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }))
2023-09-22 06:22:47 +03:00
}
}