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

Class IndexCategoryGenerator

scripts/generators/indexCategoryGenerator.ts:13–56  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11}
12
13export class IndexCategoryGenerator implements Generator {
14 streams: Collection<Stream>
15 storage: Storage
16 logFile: File
17
18 constructor({ streams, logFile }: IndexCategoryGeneratorProps) {
19 this.streams = streams.clone()
20 this.storage = new Storage(PUBLIC_DIR)
21 this.logFile = logFile
22 }
23
24 async generate(): Promise<void> {
25 const streams = this.streams.sortBy(stream => stream.title).filter(stream => stream.isSFW())
26
27 let groupedStreams = new Collection<Stream>()
28 streams.forEach((stream: Stream) => {
29 const streamCategories = stream.getCategories()
30 if (streamCategories.isEmpty()) {
31 const streamClone = stream.clone()
32 streamClone.groupTitle = 'Undefined'
33 groupedStreams.add(streamClone)
34 return
35 }
36
37 streamCategories.forEach((category: sdk.Models.Category) => {
38 const streamClone = stream.clone()
39 streamClone.groupTitle = category.name
40 groupedStreams.add(streamClone)
41 })
42 })
43
44 groupedStreams = groupedStreams.sortBy(stream => {
45 if (stream.groupTitle === 'Undefined') return 'ZZ'
46 return stream.groupTitle
47 })
48
49 const playlist = new Playlist(groupedStreams, { public: true })
50 const filepath = 'index.category.m3u'
51 await this.storage.save(filepath, playlist.toString())
52 this.logFile.append(
53 JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
54 )
55 }
56}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected