| 12 | } |
| 13 | |
| 14 | export class CitiesGenerator implements Generator { |
| 15 | streams: Collection<Stream> |
| 16 | cities: Collection<sdk.Models.City> |
| 17 | storage: Storage |
| 18 | logFile: File |
| 19 | |
| 20 | constructor({ streams, cities, logFile }: CitiesGeneratorProps) { |
| 21 | this.streams = streams.clone() |
| 22 | this.cities = cities |
| 23 | this.storage = new Storage(PUBLIC_DIR) |
| 24 | this.logFile = logFile |
| 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 streamsGroupedByCityCode = {} |
| 33 | streams.forEach((stream: Stream) => { |
| 34 | stream.getBroadcastCities().forEach((city: sdk.Models.City) => { |
| 35 | if (streamsGroupedByCityCode[city.code]) { |
| 36 | streamsGroupedByCityCode[city.code].add(stream) |
| 37 | } else { |
| 38 | streamsGroupedByCityCode[city.code] = new Collection<Stream>([stream]) |
| 39 | } |
| 40 | }) |
| 41 | }) |
| 42 | |
| 43 | for (const cityCode in streamsGroupedByCityCode) { |
| 44 | const cityStreams = streamsGroupedByCityCode[cityCode] |
| 45 | |
| 46 | const playlist = new Playlist(cityStreams, { public: true }) |
| 47 | const filepath = `cities/${cityCode.toLowerCase()}.m3u` |
| 48 | await this.storage.save(filepath, playlist.toString()) |
| 49 | this.logFile.append( |
| 50 | JSON.stringify({ type: 'city', filepath, count: playlist.streams.count() }) + EOL |
| 51 | ) |
| 52 | } |
| 53 | } |
| 54 | } |
nothing calls this directly
no outgoing calls
no test coverage detected