()
| 25 | } |
| 26 | |
| 27 | async generate(): Promise<void> { |
| 28 | const streams = this.streams |
| 29 | .sortBy((stream: Stream) => stream.title) |
| 30 | .filter((stream: Stream) => stream.isSFW()) |
| 31 | |
| 32 | const streamsGroupedByCountryCode = {} |
| 33 | streams.forEach((stream: Stream) => { |
| 34 | stream.getBroadcastCountries().forEach((country: sdk.Models.Country) => { |
| 35 | if (streamsGroupedByCountryCode[country.code]) { |
| 36 | streamsGroupedByCountryCode[country.code].add(stream) |
| 37 | } else { |
| 38 | streamsGroupedByCountryCode[country.code] = new Collection<Stream>([stream]) |
| 39 | } |
| 40 | }) |
| 41 | }) |
| 42 | |
| 43 | for (const countryCode in streamsGroupedByCountryCode) { |
| 44 | const countryStreams = streamsGroupedByCountryCode[countryCode] |
| 45 | |
| 46 | const playlist = new Playlist(countryStreams, { public: true }) |
| 47 | const filepath = `countries/${countryCode.toLowerCase()}.m3u` |
| 48 | await this.storage.save(filepath, playlist.toString()) |
| 49 | this.logFile.append( |
| 50 | JSON.stringify({ type: 'country', filepath, count: playlist.streams.count() }) + EOL |
| 51 | ) |
| 52 | } |
| 53 | |
| 54 | const internationalStreams = streams.filter((stream: Stream) => stream.isInternational()) |
| 55 | const internationalPlaylist = new Playlist(internationalStreams, { public: true }) |
| 56 | const internationalFilepath = 'countries/int.m3u' |
| 57 | await this.storage.save(internationalFilepath, internationalPlaylist.toString()) |
| 58 | this.logFile.append( |
| 59 | JSON.stringify({ |
| 60 | type: 'country', |
| 61 | filepath: internationalFilepath, |
| 62 | count: internationalPlaylist.streams.count() |
| 63 | }) + EOL |
| 64 | ) |
| 65 | |
| 66 | const undefinedStreams = streams.filter((stream: Stream) => |
| 67 | stream.getBroadcastAreaCodes().isEmpty() |
| 68 | ) |
| 69 | const undefinedPlaylist = new Playlist(undefinedStreams, { public: true }) |
| 70 | const undefinedFilepath = 'countries/undefined.m3u' |
| 71 | await this.storage.save(undefinedFilepath, undefinedPlaylist.toString()) |
| 72 | this.logFile.append( |
| 73 | JSON.stringify({ |
| 74 | type: 'country', |
| 75 | filepath: undefinedFilepath, |
| 76 | count: undefinedPlaylist.streams.count() |
| 77 | }) + EOL |
| 78 | ) |
| 79 | } |
| 80 | } |
nothing calls this directly
no test coverage detected