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

Method generate

scripts/generators/indexCountryGenerator.ts:24–66  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

22 }
23
24 async generate(): Promise<void> {
25 let groupedStreams = new Collection<Stream>()
26
27 this.streams
28 .sortBy((stream: Stream) => stream.title)
29 .filter((stream: Stream) => stream.isSFW())
30 .forEach((stream: Stream) => {
31 const broadcastAreaCountries = stream.getBroadcastCountries()
32
33 if (stream.getBroadcastAreaCodes().isEmpty()) {
34 const streamClone = stream.clone()
35 streamClone.groupTitle = 'Undefined'
36 groupedStreams.add(streamClone)
37 return
38 }
39
40 broadcastAreaCountries.forEach((country: sdk.Models.Country) => {
41 const streamClone = stream.clone()
42 streamClone.groupTitle = country.name
43 groupedStreams.add(streamClone)
44 })
45
46 if (stream.isInternational()) {
47 const streamClone = stream.clone()
48 streamClone.groupTitle = 'International'
49 groupedStreams.add(streamClone)
50 }
51 })
52
53 groupedStreams = groupedStreams.sortBy((stream: Stream) => {
54 if (stream.groupTitle === 'International') return 'ZZ'
55 if (stream.groupTitle === 'Undefined') return 'ZZZ'
56
57 return stream.groupTitle
58 })
59
60 const playlist = new Playlist(groupedStreams, { public: true })
61 const filepath = 'index.country.m3u'
62 await this.storage.save(filepath, playlist.toString())
63 this.logFile.append(
64 JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL
65 )
66 }
67}

Callers

nothing calls this directly

Calls 6

toStringMethod · 0.95
isSFWMethod · 0.80
getBroadcastCountriesMethod · 0.80
cloneMethod · 0.80
isInternationalMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected