| 10 | } |
| 11 | |
| 12 | export class SourcesGenerator implements Generator { |
| 13 | streams: Collection<Stream> |
| 14 | storage: Storage |
| 15 | logFile: File |
| 16 | |
| 17 | constructor({ streams, logFile }: SourcesGeneratorProps) { |
| 18 | this.streams = streams.clone() |
| 19 | this.storage = new Storage(PUBLIC_DIR) |
| 20 | this.logFile = logFile |
| 21 | } |
| 22 | |
| 23 | async generate() { |
| 24 | const files: Dictionary<Stream[]> = this.streams.groupBy((stream: Stream) => |
| 25 | stream.getFilename() |
| 26 | ) |
| 27 | |
| 28 | for (const filename of files.keys()) { |
| 29 | if (!filename) continue |
| 30 | |
| 31 | const streams = new Collection<Stream>(files.get(filename)).map((stream: Stream) => { |
| 32 | const groupTitle = stream |
| 33 | .getCategories() |
| 34 | .map(category => category.name) |
| 35 | .sort() |
| 36 | .join(';') |
| 37 | if (groupTitle) stream.groupTitle = groupTitle |
| 38 | |
| 39 | return stream |
| 40 | }) |
| 41 | const playlist = new Playlist(streams, { public: true }) |
| 42 | const filepath = `sources/${filename}` |
| 43 | await this.storage.save(filepath, playlist.toString()) |
| 44 | this.logFile.append( |
| 45 | JSON.stringify({ type: 'source', filepath, count: playlist.streams.count() }) + EOL |
| 46 | ) |
| 47 | } |
| 48 | } |
| 49 | } |
nothing calls this directly
no outgoing calls
no test coverage detected