2024-05-19 05:49:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Services\Streamer\Adapters;
|
|
|
|
|
|
|
|
use App\Models\Song as Episode;
|
|
|
|
use App\Services\PodcastService;
|
|
|
|
use App\Services\Streamer\Adapters\Concerns\StreamsLocalPath;
|
|
|
|
use App\Values\Podcast\EpisodePlayable;
|
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Webmozart\Assert\Assert;
|
|
|
|
|
|
|
|
class PodcastStreamerAdapter implements StreamerAdapter
|
|
|
|
{
|
|
|
|
use StreamsLocalPath;
|
|
|
|
|
|
|
|
public function __construct(private readonly PodcastService $podcastService)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function stream(Episode $song, array $config = []): RedirectResponse
|
|
|
|
{
|
|
|
|
Assert::true($song->isEpisode());
|
|
|
|
|
|
|
|
$streamableUrl = $this->podcastService->getStreamableUrl($song);
|
|
|
|
|
|
|
|
if ($streamableUrl) {
|
|
|
|
return response()->redirectTo($streamableUrl);
|
|
|
|
}
|
|
|
|
|
2024-09-03 10:52:07 +00:00
|
|
|
$this->streamLocalPath(EpisodePlayable::getForEpisode($song)->path);
|
2024-05-19 05:49:42 +00:00
|
|
|
}
|
|
|
|
}
|