mirror of
https://github.com/koel/koel
synced 2024-12-24 19:43:06 +00:00
39 lines
1,002 B
PHP
39 lines
1,002 B
PHP
|
<?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);
|
||
|
}
|
||
|
|
||
|
$playable = EpisodePlayable::retrieveForEpisode($song);
|
||
|
|
||
|
if (!$playable?->valid()) {
|
||
|
$playable = EpisodePlayable::createForEpisode($song);
|
||
|
}
|
||
|
|
||
|
$this->streamLocalPath($playable->path);
|
||
|
}
|
||
|
}
|