feat: Add a way to convert an entire playlist

Closes #194
This commit is contained in:
Pierre Rudloff 2019-04-21 22:56:07 +02:00
parent 4db519c2ef
commit 70475f83d4
3 changed files with 38 additions and 5 deletions

View file

@ -0,0 +1,29 @@
<?php
/**
* ConvertedPlaylistArchiveStream class.
*/
namespace Alltube;
use Slim\Http\Stream;
class ConvertedPlaylistArchiveStream extends PlaylistArchiveStream
{
/**
* Start streaming a new video.
*
* @param Video $video Video to stream
*
* @return void
*/
protected function startVideoStream(Video $video)
{
$this->curVideoStream = new Stream($video->getAudioStream());
$this->init_file_stream_transfer(
$video->getFileNameWithExtension('mp3'),
// The ZIP format does not care about the file size.
0
);
}
}

View file

@ -6,7 +6,6 @@
namespace Alltube; namespace Alltube;
use Barracuda\ArchiveStream\ZipArchive; use Barracuda\ArchiveStream\ZipArchive;
use GuzzleHttp\Psr7\Stream;
use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamInterface;
/** /**
@ -33,9 +32,9 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
/** /**
* Current video being streamed to the archive. * Current video being streamed to the archive.
* *
* @var Stream * @var StreamInterface
*/ */
private $curVideoStream; protected $curVideoStream;
/** /**
* True if the archive is complete. * True if the archive is complete.
@ -234,7 +233,7 @@ class PlaylistArchiveStream extends ZipArchive implements StreamInterface
* *
* @return void * @return void
*/ */
private function startVideoStream(Video $video) protected function startVideoStream(Video $video)
{ {
$response = $video->getHttpResponse(); $response = $video->getHttpResponse();

View file

@ -6,6 +6,7 @@
namespace Alltube\Controller; namespace Alltube\Controller;
use Alltube\Config; use Alltube\Config;
use Alltube\ConvertedPlaylistArchiveStream;
use Alltube\EmptyUrlException; use Alltube\EmptyUrlException;
use Alltube\Locale; use Alltube\Locale;
use Alltube\LocaleManager; use Alltube\LocaleManager;
@ -378,7 +379,11 @@ class FrontController
private function getStream(Request $request, Response $response) private function getStream(Request $request, Response $response)
{ {
if (isset($this->video->entries)) { 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-Type', 'application/zip');
$response = $response->withHeader( $response = $response->withHeader(
'Content-Disposition', 'Content-Disposition',