| 11 | } |
| 12 | |
| 13 | export class IndexLanguageGenerator implements Generator { |
| 14 | streams: Collection<Stream> |
| 15 | storage: Storage |
| 16 | logFile: File |
| 17 | |
| 18 | constructor({ streams, logFile }: IndexLanguageGeneratorProps) { |
| 19 | this.streams = streams.clone() |
| 20 | this.storage = new Storage(PUBLIC_DIR) |
| 21 | this.logFile = logFile |
| 22 | } |
| 23 | |
| 24 | async generate(): Promise<void> { |
| 25 | let groupedStreams = new Collection<Stream>() |
| 26 | this.streams |
| 27 | .sortBy((stream: Stream) => stream.title) |
| 28 | .filter((stream: Stream) => stream.isSFW()) |
| 29 | .forEach((stream: Stream) => { |
| 30 | const streamLanguages = stream.getLanguages() |
| 31 | if (streamLanguages.isEmpty()) { |
| 32 | const streamClone = stream.clone() |
| 33 | streamClone.groupTitle = 'Undefined' |
| 34 | groupedStreams.add(streamClone) |
| 35 | return |
| 36 | } |
| 37 | |
| 38 | streamLanguages.forEach((language: sdk.Models.Language) => { |
| 39 | const streamClone = stream.clone() |
| 40 | streamClone.groupTitle = language.name |
| 41 | groupedStreams.add(streamClone) |
| 42 | }) |
| 43 | }) |
| 44 | |
| 45 | groupedStreams = groupedStreams.sortBy((stream: Stream) => { |
| 46 | if (stream.groupTitle === 'Undefined') return 'ZZ' |
| 47 | return stream.groupTitle |
| 48 | }) |
| 49 | |
| 50 | const playlist = new Playlist(groupedStreams, { public: true }) |
| 51 | const filepath = 'index.language.m3u' |
| 52 | await this.storage.save(filepath, playlist.toString()) |
| 53 | this.logFile.append( |
| 54 | JSON.stringify({ type: 'index', filepath, count: playlist.streams.count() }) + EOL |
| 55 | ) |
| 56 | } |
| 57 | } |
nothing calls this directly
no outgoing calls
no test coverage detected