| Conditions | 2 |
| Paths | 2 |
| Total Lines | 24 |
| Code Lines | 15 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 6 |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | public function stream(): void |
||
| 25 | { |
||
| 26 | $ffmpeg = config('koel.streaming.ffmpeg_path'); |
||
| 27 | abort_unless(is_executable($ffmpeg), 500, 'Transcoding requires valid ffmpeg settings.'); |
||
| 28 | |||
| 29 | $bitRate = filter_var($this->bitRate, FILTER_SANITIZE_NUMBER_INT); |
||
| 30 | |||
| 31 | header('Content-Type: audio/mpeg'); |
||
| 32 | header('Content-Disposition: attachment; filename="'.basename($this->song->path).'"'); |
||
| 33 | |||
| 34 | $args = [ |
||
| 35 | '-i '.escapeshellarg($this->song->path), |
||
| 36 | '-map 0:0', |
||
| 37 | '-v 0', |
||
| 38 | "-ab {$bitRate}k", |
||
| 39 | '-f mp3', |
||
| 40 | '-', |
||
| 41 | ]; |
||
| 42 | |||
| 43 | if ($this->startTime) { |
||
| 44 | array_unshift($args, "-ss {$this->startTime}"); |
||
| 45 | } |
||
| 46 | |||
| 47 | passthru("$ffmpeg ".implode(' ', $args)); |
||
| 48 | } |
||
| 60 |