Files
iptv/scripts/generators/sourcesGenerator.ts
L4XB 215ee48311 fix: leave NSFW channels out of the categories and sources playlists
The other public generators drop NSFW streams with isSFW(), as PLAYLISTS.md promises (no NSFW channels since January 30th, 2024), but categories/ and sources/ took every stream, so NSFW channels with a feed were published there. The test fixture's NSFW channel now carries its feed id, so it reaches the generators instead of being dropped as a stream without a feed.
2026-10-25 04:09:46 +01:00

50 lines
1.5 KiB
TypeScript

import { Collection, Dictionary } from '@freearhey/core'
import { Storage, File } from '@freearhey/storage-js'
import { PUBLIC_DIR, EOL } from '../constants'
import { Stream, Playlist } from '../models'
import { Generator } from './generator'
type SourcesGeneratorProps = {
streams: Collection<Stream>
logFile: File
}
export class SourcesGenerator implements Generator {
streams: Collection<Stream>
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<Stream[]> = this.streams
.filter((stream: Stream) => stream.isSFW())
.groupBy((stream: Stream) => stream.getFilename())
for (const filename of files.keys()) {
if (!filename) continue
const streams = new Collection<Stream>(files.get(filename)).map((stream: Stream) => {
const groupTitle = stream
.getCategories()
.map(category => category.name)
.sort()
.join(';')
if (groupTitle) stream.groupTitle = groupTitle
return stream
})
const playlist = new Playlist(streams, { public: true, raw: false })
const filepath = `sources/${filename}`
await this.storage.save(filepath, playlist.toString())
this.logFile.append(
JSON.stringify({ type: 'source', filepath, count: playlist.streams.count() }) + EOL
)
}
}
}