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

Class CategoriesGenerator

scripts/generators/categoriesGenerator.ts:14–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12}
13
14export class CategoriesGenerator implements Generator {
15 streams: Collection<Stream>
16 categories: Collection<sdk.Models.Category>
17 storage: Storage
18 logFile: File
19
20 constructor({ streams, categories, logFile }: CategoriesGeneratorProps) {
21 this.streams = streams.clone()
22 this.categories = categories
23 this.storage = new Storage(PUBLIC_DIR)
24 this.logFile = logFile
25 }
26
27 async generate() {
28 const streams = this.streams.sortBy([(stream: Stream) => stream.title])
29
30 this.categories.forEach(async (category: sdk.Models.Category) => {
31 const categoryStreams = streams
32 .filter((stream: Stream) => stream.hasCategory(category))
33 .map((stream: Stream) => {
34 const groupTitle = stream
35 .getCategories()
36 .map(category => category.name)
37 .sort()
38 .join(';')
39 if (groupTitle) stream.groupTitle = groupTitle
40
41 return stream
42 })
43
44 const playlist = new Playlist(categoryStreams, { public: true })
45 const filepath = `categories/${category.id}.m3u`
46 await this.storage.save(filepath, playlist.toString())
47 this.logFile.append(
48 JSON.stringify({ type: 'category', filepath, count: playlist.streams.count() }) + EOL
49 )
50 })
51
52 const undefinedStreams = streams.filter((stream: Stream) => stream.getCategories().isEmpty())
53 const playlist = new Playlist(undefinedStreams, { public: true })
54 const filepath = 'categories/undefined.m3u'
55 await this.storage.save(filepath, playlist.toString())
56 this.logFile.append(
57 JSON.stringify({ type: 'category', filepath, count: playlist.streams.count() }) + EOL
58 )
59 }
60}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected