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

@ -14,7 +14,8 @@
"ptachoire/process-builder-chain": "~1.2.0", "ptachoire/process-builder-chain": "~1.2.0",
"ffmpeg/ffmpeg": "dev-release", "ffmpeg/ffmpeg": "dev-release",
"rudloff/smarty-plugin-noscheme": "~0.1.0", "rudloff/smarty-plugin-noscheme": "~0.1.0",
"rudloff/rtmpdump-bin": "~2.3" "rudloff/rtmpdump-bin": "~2.3",
"rudloff/psr7-process-stream": "~0.1.0"
}, },
"require-dev": { "require-dev": {
"symfony/var-dumper": "~3.0.0" "symfony/var-dumper": "~3.0.0"

95
composer.lock generated
View file

@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "a0c23015c2a2bbb700ae566a04ca8679", "hash": "0fef6027910cac993af5690ffd131b1c",
"content-hash": "42d3272dbfe226c0ef3da4e135e2dae3", "content-hash": "ae728e70b08dd126d55576800f334529",
"packages": [ "packages": [
{ {
"name": "container-interop/container-interop", "name": "container-interop/container-interop",
@ -48,6 +48,64 @@
], ],
"type": "library" "type": "library"
}, },
{
"name": "guzzlehttp/psr7",
"version": "1.3.0",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "31382fef2889136415751badebbd1cb022a4ed72"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/31382fef2889136415751badebbd1cb022a4ed72",
"reference": "31382fef2889136415751badebbd1cb022a4ed72",
"shasum": ""
},
"require": {
"php": ">=5.4.0",
"psr/http-message": "~1.0"
},
"provide": {
"psr/http-message-implementation": "1.0"
},
"require-dev": {
"phpunit/phpunit": "~4.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
}
},
"autoload": {
"psr-4": {
"GuzzleHttp\\Psr7\\": "src/"
},
"files": [
"src/functions_include.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
}
],
"description": "PSR-7 message implementation",
"keywords": [
"http",
"message",
"stream",
"uri"
],
"time": "2016-04-13 19:56:01"
},
{ {
"name": "jeremykendall/php-domain-parser", "name": "jeremykendall/php-domain-parser",
"version": "3.0.0", "version": "3.0.0",
@ -408,6 +466,39 @@
}, },
"type": "library" "type": "library"
}, },
{
"name": "rudloff/psr7-process-stream",
"version": "0.1.0",
"source": {
"type": "git",
"url": "https://github.com/Rudloff/psr7-process-stream.git",
"reference": "055ecbdadee9b43904aed75d5a548c277cac10a8"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Rudloff/psr7-process-stream/zipball/055ecbdadee9b43904aed75d5a548c277cac10a8",
"reference": "055ecbdadee9b43904aed75d5a548c277cac10a8",
"shasum": ""
},
"require": {
"guzzlehttp/psr7": "~1.3.0"
},
"require-dev": {
"symfony/var-dumper": "~3.0.0"
},
"type": "library",
"autoload": {
"psr-4": {
"ProcessStream\\": "classes/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"GPL-3.0"
],
"description": "PSR-7 stream implementation that can be used to manage processes",
"time": "2016-04-14 10:36:10"
},
{ {
"name": "rudloff/rtmpdump-bin", "name": "rudloff/rtmpdump-bin",
"version": "2.3", "version": "2.3",

View file

@ -16,6 +16,7 @@ use Alltube\VideoDownload;
use Alltube\Config; use Alltube\Config;
use Symfony\Component\Process\ProcessBuilder; use Symfony\Component\Process\ProcessBuilder;
use Chain\Chain; use Chain\Chain;
use ProcessStream\PopenStream;
/** /**
* Main controller * Main controller
@ -136,6 +137,21 @@ class FrontController
'user_agent', 'user_agent',
$video->http_headers->{'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') { if (parse_url($video->url, PHP_URL_SCHEME) == 'rtmp') {
$builder = new ProcessBuilder( $builder = new ProcessBuilder(
array( array(
@ -164,21 +180,6 @@ class FrontController
} }
$chain = new Chain($builder->getProcess()); $chain = new Chain($builder->getProcess());
$chain->add('|', $avconvProc); $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 { } else {
$chain = new Chain( $chain = new Chain(
ProcessBuilder::create( ProcessBuilder::create(
@ -193,22 +194,8 @@ class FrontController
) )
); );
$chain->add('|', $avconvProc); $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) { } catch (\Exception $e) {
$error = $e->getMessage(); $error = $e->getMessage();