2024-02-24 07:28:49 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Streamer\Adapters;
|
|
|
|
|
|
|
|
use App\Models\Song;
|
2024-09-03 10:52:07 +00:00
|
|
|
use App\Services\Streamer\Adapters\Concerns\StreamsLocalPath;
|
|
|
|
use App\Values\TranscodeResult;
|
2024-02-24 07:28:49 +00:00
|
|
|
use Illuminate\Support\Arr;
|
|
|
|
|
|
|
|
class TranscodingStreamerAdapter implements StreamerAdapter
|
|
|
|
{
|
2024-09-03 10:52:07 +00:00
|
|
|
use StreamsLocalPath;
|
|
|
|
|
2024-02-24 07:28:49 +00:00
|
|
|
public function stream(Song $song, array $config = []): void
|
|
|
|
{
|
2024-09-03 10:52:07 +00:00
|
|
|
abort_unless(is_executable(config('koel.streaming.ffmpeg_path')), 500, 'ffmpeg not found or not executable.');
|
2024-02-24 07:28:49 +00:00
|
|
|
|
|
|
|
$bitRate = filter_var(Arr::get($config, 'bit_rate'), FILTER_SANITIZE_NUMBER_INT)
|
|
|
|
?: config('koel.streaming.bitrate');
|
|
|
|
|
2024-09-03 10:52:07 +00:00
|
|
|
$this->streamLocalPath(TranscodeResult::getForSong($song, $bitRate)->path);
|
2024-02-24 07:28:49 +00:00
|
|
|
}
|
|
|
|
}
|