Use PSR-7 streams for conversion

This commit is contained in:
Pierre Rudloff 2016-04-14 12:42:13 +02:00
parent 3e8cbe6cc8
commit d00c1dc91c
3 changed files with 112 additions and 33 deletions

View file

@ -16,6 +16,7 @@ use Alltube\VideoDownload;
use Alltube\Config;
use Symfony\Component\Process\ProcessBuilder;
use Chain\Chain;
use ProcessStream\PopenStream;
/**
* Main controller
@ -136,6 +137,21 @@ class FrontController
'user_agent',
$video->http_headers->{'User-Agent'}
);
$response = $response->withHeader(
'Content-Disposition',
'attachment; filename="'.
html_entity_decode(
pathinfo(
$video->_filename,
PATHINFO_FILENAME
).'.mp3',
ENT_COMPAT,
'ISO-8859-1'
).'"'
);
$response = $response->withHeader('Content-Type', 'audio/mpeg');
if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
$builder = new ProcessBuilder(
array(
@ -164,21 +180,6 @@ class FrontController
}
$chain = new Chain($builder->getProcess());
$chain->add('|', $avconvProc);
ob_end_flush();
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
$video->_filename,
PATHINFO_FILENAME
).'.mp3',
ENT_COMPAT,
'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru($chain->getProcess()->getCommandLine());
exit;
} else {
$chain = new Chain(
ProcessBuilder::create(
@ -193,22 +194,8 @@ class FrontController
)
);
$chain->add('|', $avconvProc);
ob_end_flush();
header(
'Content-Disposition: attachment; filename="'.
html_entity_decode(
pathinfo(
$video->_filename,
PATHINFO_FILENAME
).'.mp3',
ENT_COMPAT,
'ISO-8859-1'
).'"'
);
header("Content-Type: audio/mpeg");
passthru($chain->getProcess()->getCommandLine());
exit;
}
return $response->withBody(new PopenStream($chain->getProcess()->getCommandLine()));
}
} catch (\Exception $e) {
$error = $e->getMessage();