MCPcopy
hub / github.com/iptv-org/iptv / IndexGenerator

Class IndexGenerator

scripts/generators/indexGenerator.ts:12–45  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

10}
11
12export class IndexGenerator implements Generator {
13 streams: Collection<Stream>
14 storage: Storage
15 logFile: File
16
17 constructor({ streams, logFile }: IndexGeneratorProps) {
18 this.streams = streams.clone()
19 this.storage = new Storage(PUBLIC_DIR)
20 this.logFile = logFile
21 }
22
23 async generate(): Promise<void> {
24 const sfwStreams = this.streams
25 .sortBy(stream => stream.title)
26 .filter((stream: Stream) => stream.isSFW())
27 .map((stream: Stream) => {
28 const groupTitle = stream
29 .getCategories()
30 .map(category => category.name)
31 .sort()
32 .join(';')
33 if (groupTitle) stream.groupTitle = groupTitle
34
35 return stream
36 })
37
38 const playlist = new Playlist(sfwStreams, { public: true })
39 const filepath = 'index.m3u'
40 await this.storage.save(filepath, playlist.toString())
41 this.logFile.append(
42 JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
43 )
44 }
45}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected