Files
iptv/scripts/generators/indexNsfwGenerator.ts

34 lines
985 B
TypeScript
Raw Normal View History

2025-04-23 20:56:19 +03:00
import { Collection, File, Storage } from '@freearhey/core'
2023-09-22 06:22:47 +03:00
import { Stream, Playlist } from '../models'
import { PUBLIC_DIR } from '../constants'
2025-04-23 20:56:19 +03:00
import { Generator } from './generator'
import { EOL } from 'node:os'
2023-09-22 06:22:47 +03:00
type IndexNsfwGeneratorProps = {
streams: Collection
2025-04-23 20:56:19 +03:00
logFile: File
2023-09-22 06:22:47 +03:00
}
export class IndexNsfwGenerator implements Generator {
streams: Collection
storage: Storage
2025-04-23 20:56:19 +03:00
logFile: File
2023-09-22 06:22:47 +03:00
2025-04-23 20:56:19 +03:00
constructor({ streams, logFile }: IndexNsfwGeneratorProps) {
2025-07-10 21:13:43 +03:00
this.streams = streams.clone()
2023-09-22 06:22:47 +03:00
this.storage = new Storage(PUBLIC_DIR)
2025-04-23 20:56:19 +03:00
this.logFile = logFile
2023-09-22 06:22:47 +03:00
}
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-04-23 20:56:19 +03:00
this.logFile.append(
JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
)
2023-09-22 06:22:47 +03:00
}
}