Use symfony/process (fixes #50)
This commit is contained in:
parent
55a250d60f
commit
1d83c5c0b3
3 changed files with 73 additions and 33 deletions
|
@ -12,6 +12,8 @@
|
||||||
* */
|
* */
|
||||||
namespace Alltube;
|
namespace Alltube;
|
||||||
|
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class
|
* Main class
|
||||||
*
|
*
|
||||||
|
@ -37,11 +39,9 @@ class VideoDownload
|
||||||
$config->python.' '.escapeshellarg($config->youtubedl).
|
$config->python.' '.escapeshellarg($config->youtubedl).
|
||||||
' '.$config->params
|
' '.$config->params
|
||||||
);
|
);
|
||||||
exec(
|
$process = new Process($cmd.' --dump-user-agent');
|
||||||
$cmd.' --dump-user-agent',
|
$process->run();
|
||||||
$version
|
return trim($process->getOutput());
|
||||||
);
|
|
||||||
return $version[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,11 +56,9 @@ class VideoDownload
|
||||||
$config->python.' '.escapeshellarg($config->youtubedl).
|
$config->python.' '.escapeshellarg($config->youtubedl).
|
||||||
' '.$config->params
|
' '.$config->params
|
||||||
);
|
);
|
||||||
exec(
|
$process = new Process($cmd.' --list-extractors');
|
||||||
$cmd.' --list-extractors',
|
$process->run();
|
||||||
$extractors
|
return explode(PHP_EOL, $process->getOutput());
|
||||||
);
|
|
||||||
return $extractors;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -82,11 +80,9 @@ class VideoDownload
|
||||||
$cmd .= ' -f '.escapeshellarg($format);
|
$cmd .= ' -f '.escapeshellarg($format);
|
||||||
}
|
}
|
||||||
$cmd .=' --get-filename '.escapeshellarg($url)." 2>&1";
|
$cmd .=' --get-filename '.escapeshellarg($url)." 2>&1";
|
||||||
exec(
|
$process = new Process($cmd);
|
||||||
$cmd,
|
$process->run();
|
||||||
$filename
|
return trim($process->getOutput());
|
||||||
);
|
|
||||||
return end($filename);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -108,15 +104,12 @@ class VideoDownload
|
||||||
$cmd .= ' -f '.escapeshellarg($format);
|
$cmd .= ' -f '.escapeshellarg($format);
|
||||||
}
|
}
|
||||||
$cmd .=' --dump-json '.escapeshellarg($url)." 2>&1";
|
$cmd .=' --dump-json '.escapeshellarg($url)." 2>&1";
|
||||||
exec(
|
$process = new Process($cmd);
|
||||||
$cmd,
|
$process->run();
|
||||||
$result,
|
if (!$process->isSuccessful()) {
|
||||||
$code
|
throw new \Exception($process->getOutput());
|
||||||
);
|
|
||||||
if ($code>0) {
|
|
||||||
throw new \Exception(implode(PHP_EOL, $result));
|
|
||||||
} else {
|
} else {
|
||||||
return json_decode($result[0]);
|
return json_decode($process->getOutput());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,15 +132,12 @@ class VideoDownload
|
||||||
$cmd .= ' -f '.escapeshellarg($format);
|
$cmd .= ' -f '.escapeshellarg($format);
|
||||||
}
|
}
|
||||||
$cmd .=' -g '.escapeshellarg($url)." 2>&1";
|
$cmd .=' -g '.escapeshellarg($url)." 2>&1";
|
||||||
exec(
|
$process = new Process($cmd);
|
||||||
$cmd,
|
$process->run();
|
||||||
$result,
|
if (!$process->isSuccessful()) {
|
||||||
$code
|
throw new \Exception($process->getOutput());
|
||||||
);
|
|
||||||
if ($code>0) {
|
|
||||||
throw new \Exception(implode(PHP_EOL, $result));
|
|
||||||
} else {
|
} else {
|
||||||
return array('success'=>true, 'url'=>end($result));
|
return array('success'=>true, 'url'=>$process->getOutput());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
"slim/slim": "~3.3.0",
|
"slim/slim": "~3.3.0",
|
||||||
"mathmarques/smarty-view": "~1.0.0",
|
"mathmarques/smarty-view": "~1.0.0",
|
||||||
"symfony/yaml": "~3.0.0",
|
"symfony/yaml": "~3.0.0",
|
||||||
|
"symfony/process": "~3.0.0",
|
||||||
"ffmpeg/ffmpeg": "~2.8.2"
|
"ffmpeg/ffmpeg": "~2.8.2"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|
53
composer.lock
generated
53
composer.lock
generated
|
@ -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": "22d65db5d1fd37d20bc4b2ad6736ab4a",
|
"hash": "5ba1de7cdc94a679d3cbea5aa73db0d5",
|
||||||
"content-hash": "bbf51588b3930e62a675a947d23aa6b0",
|
"content-hash": "f2b2cf7d6170452e2cfc4dfde5fd6b5f",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "container-interop/container-interop",
|
"name": "container-interop/container-interop",
|
||||||
|
@ -367,6 +367,55 @@
|
||||||
],
|
],
|
||||||
"time": "2015-12-21 01:57:06"
|
"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",
|
"name": "symfony/yaml",
|
||||||
"version": "v3.0.4",
|
"version": "v3.0.4",
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue