Use symfony/process (fixes #50)

This commit is contained in:
Pierre Rudloff 2016-04-01 00:42:28 +02:00
parent 55a250d60f
commit 1d83c5c0b3
3 changed files with 73 additions and 33 deletions

View file

@ -12,6 +12,8 @@
* */
namespace Alltube;
use Symfony\Component\Process\Process;
/**
* Main class
*
@ -37,11 +39,9 @@ class VideoDownload
$config->python.' '.escapeshellarg($config->youtubedl).
' '.$config->params
);
exec(
$cmd.' --dump-user-agent',
$version
);
return $version[0];
$process = new Process($cmd.' --dump-user-agent');
$process->run();
return trim($process->getOutput());
}
/**
@ -56,11 +56,9 @@ class VideoDownload
$config->python.' '.escapeshellarg($config->youtubedl).
' '.$config->params
);
exec(
$cmd.' --list-extractors',
$extractors
);
return $extractors;
$process = new Process($cmd.' --list-extractors');
$process->run();
return explode(PHP_EOL, $process->getOutput());
}
/**
@ -82,11 +80,9 @@ class VideoDownload
$cmd .= ' -f '.escapeshellarg($format);
}
$cmd .=' --get-filename '.escapeshellarg($url)." 2>&1";
exec(
$cmd,
$filename
);
return end($filename);
$process = new Process($cmd);
$process->run();
return trim($process->getOutput());
}
/**
@ -108,15 +104,12 @@ class VideoDownload
$cmd .= ' -f '.escapeshellarg($format);
}
$cmd .=' --dump-json '.escapeshellarg($url)." 2>&1";
exec(
$cmd,
$result,
$code
);
if ($code>0) {
throw new \Exception(implode(PHP_EOL, $result));
$process = new Process($cmd);
$process->run();
if (!$process->isSuccessful()) {
throw new \Exception($process->getOutput());
} else {
return json_decode($result[0]);
return json_decode($process->getOutput());
}
}
@ -139,15 +132,12 @@ class VideoDownload
$cmd .= ' -f '.escapeshellarg($format);
}
$cmd .=' -g '.escapeshellarg($url)." 2>&1";
exec(
$cmd,
$result,
$code
);
if ($code>0) {
throw new \Exception(implode(PHP_EOL, $result));
$process = new Process($cmd);
$process->run();
if (!$process->isSuccessful()) {
throw new \Exception($process->getOutput());
} else {
return array('success'=>true, 'url'=>end($result));
return array('success'=>true, 'url'=>$process->getOutput());
}
}

View file

@ -10,6 +10,7 @@
"slim/slim": "~3.3.0",
"mathmarques/smarty-view": "~1.0.0",
"symfony/yaml": "~3.0.0",
"symfony/process": "~3.0.0",
"ffmpeg/ffmpeg": "~2.8.2"
},
"require-dev": {

53
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",
"This file is @generated automatically"
],
"hash": "22d65db5d1fd37d20bc4b2ad6736ab4a",
"content-hash": "bbf51588b3930e62a675a947d23aa6b0",
"hash": "5ba1de7cdc94a679d3cbea5aa73db0d5",
"content-hash": "f2b2cf7d6170452e2cfc4dfde5fd6b5f",
"packages": [
{
"name": "container-interop/container-interop",
@ -367,6 +367,55 @@
],
"time": "2015-12-21 01:57:06"
},
{
"name": "symfony/process",
"version": "v3.0.4",
"source": {
"type": "git",
"url": "https://github.com/symfony/process.git",
"reference": "e6f1f98bbd355d209a992bfff45e7edfbd4a0776"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/process/zipball/e6f1f98bbd355d209a992bfff45e7edfbd4a0776",
"reference": "e6f1f98bbd355d209a992bfff45e7edfbd4a0776",
"shasum": ""
},
"require": {
"php": ">=5.5.9"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.0-dev"
}
},
"autoload": {
"psr-4": {
"Symfony\\Component\\Process\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Symfony Process Component",
"homepage": "https://symfony.com",
"time": "2016-03-30 10:41:14"
},
{
"name": "symfony/yaml",
"version": "v3.0.4",