diff --git a/classes/ConvertedPlaylistArchiveStream.php b/classes/ConvertedPlaylistArchiveStream.php new file mode 100644 index 0000000..ae16fe9 --- /dev/null +++ b/classes/ConvertedPlaylistArchiveStream.php @@ -0,0 +1,29 @@ +curVideoStream = new Stream($video->getAudioStream()); + + $this->init_file_stream_transfer( + $video->getFileNameWithExtension('mp3'), + // The ZIP format does not care about the file size. + 0 + ); + } +} diff --git a/classes/PlaylistArchiveStream.php b/classes/PlaylistArchiveStream.php index 78f716d..48d8b74 100644 --- a/classes/PlaylistArchiveStream.php +++ b/classes/PlaylistArchiveStream.php @@ -6,7 +6,6 @@ namespace Alltube; use Barracuda\ArchiveStream\ZipArchive; -use GuzzleHttp\Psr7\Stream; use Psr\Http\Message\StreamInterface; /** @@ -33,9 +32,9 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface /** * Current video being streamed to the archive. * - * @var Stream + * @var StreamInterface */ - private $curVideoStream; + protected $curVideoStream; /** * True if the archive is complete. @@ -234,7 +233,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface * * @return void */ - private function startVideoStream(Video $video) + protected function startVideoStream(Video $video) { $response = $video->getHttpResponse(); diff --git a/controllers/FrontController.php b/controllers/FrontController.php index 1585f4f..7fc98ae 100644 --- a/controllers/FrontController.php +++ b/controllers/FrontController.php @@ -6,6 +6,7 @@ namespace Alltube\Controller; use Alltube\Config; +use Alltube\ConvertedPlaylistArchiveStream; use Alltube\EmptyUrlException; use Alltube\Locale; use Alltube\LocaleManager; @@ -378,7 +379,11 @@ class FrontController private function getStream(Request $request, Response $response) { if (isset($this->video->entries)) { - $stream = new PlaylistArchiveStream($this->video); + if ($request->getQueryParam('audio')) { + $stream = new ConvertedPlaylistArchiveStream($this->video); + } else { + $stream = new PlaylistArchiveStream($this->video); + } $response = $response->withHeader('Content-Type', 'application/zip'); $response = $response->withHeader( 'Content-Disposition',