🐛 Trying to debug with Process
This commit is contained in:
parent
808b786f5e
commit
a4a678d32f
@ -3,6 +3,8 @@
|
|||||||
namespace Shikiryu\Bot\Commands;
|
namespace Shikiryu\Bot\Commands;
|
||||||
|
|
||||||
use Shikiryu\Bot\Bot;
|
use Shikiryu\Bot\Bot;
|
||||||
|
use Symfony\Component\Process\Exception\ProcessFailedException;
|
||||||
|
use Symfony\Component\Process\Process;
|
||||||
|
|
||||||
class Youtubedl implements Icommands
|
class Youtubedl implements Icommands
|
||||||
{
|
{
|
||||||
@ -24,16 +26,27 @@ class Youtubedl implements Icommands
|
|||||||
|
|
||||||
if (in_array($type, ['', 'audio'], true)) {
|
if (in_array($type, ['', 'audio'], true)) {
|
||||||
$type = 'l\'audio';
|
$type = 'l\'audio';
|
||||||
$cmd = sprintf('%s --extract-audio --audio-format mp3 -o %s%s %s', $youtubedl, static::getDownloadFolder($bot), '%(upload_date)s-%(uploader)s-%(title)s.%(ext)s', $url);
|
$process = new Process([$youtubedl, '--extract-audio', '--audio-format', 'mp3', sprintf('-o %s%s', static::getDownloadFolder($bot), '%(upload_date)s-%(uploader)s-%(title)s.%(ext)s'), $url]);
|
||||||
exec($cmd, $output);
|
// $cmd = sprintf('%s --extract-audio --audio-format mp3 -o %s%s %s', $youtubedl, static::getDownloadFolder($bot), '%(upload_date)s-%(uploader)s-%(title)s.%(ext)s', $url);
|
||||||
$bot->sendChatMessage('', sprintf('Je lance %s', $cmd));
|
// exec($cmd, $output);
|
||||||
|
// $bot->sendChatMessage('', sprintf('Je lance %s', $cmd));
|
||||||
} else {
|
} else {
|
||||||
$type = 'la vidéo';
|
$type = 'la vidéo';
|
||||||
$cmd = sprintf('%s -f bestvideo+bestaudio/best -o %s%s %s', $youtubedl, static::getDownloadFolder($bot), '%(upload_date)s-%(uploader)s-%(title)s.%(ext)s', $url);
|
$process = new Process([$youtubedl, '-f bestvideo+bestaudio/best', sprintf('-o %s%s', static::getDownloadFolder($bot), '%(upload_date)s-%(uploader)s-%(title)s.%(ext)s'), $url]);
|
||||||
exec($cmd, $output);
|
// $cmd = sprintf('%s -f bestvideo+bestaudio/best -o %s%s %s', $youtubedl, static::getDownloadFolder($bot), '%(upload_date)s-%(uploader)s-%(title)s.%(ext)s', $url);
|
||||||
$bot->sendChatMessage('', sprintf('Je lance %s', $cmd));
|
// exec($cmd, $output);
|
||||||
|
// $bot->sendChatMessage('', sprintf('Je lance %s', $cmd));
|
||||||
}
|
}
|
||||||
$bot->replyPolitely(sprintf('Je %s %s', $action, $type));
|
$process->run();
|
||||||
|
|
||||||
|
// executes after the command finishes
|
||||||
|
if (!$process->isSuccessful()) {
|
||||||
|
$ex = new ProcessFailedException($process);
|
||||||
|
$bot->reply($ex->getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
$bot->reply($process->getOutput());
|
||||||
|
// $bot->replyPolitely(sprintf('Je %s %s', $action, $type));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function getDescription(): string
|
public static function getDescription(): string
|
||||||
@ -54,7 +67,7 @@ class Youtubedl implements Icommands
|
|||||||
|
|
||||||
private static function getDownloadFolder(Bot $bot): string
|
private static function getDownloadFolder(Bot $bot): string
|
||||||
{
|
{
|
||||||
return $bot->getConfig()['youtube-dl']['folder'] ?? __DIR__.'/../../';
|
return $bot->getConfig()['youtube-dl']['download_folder'] ?? __DIR__.'/../../';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
{
|
{
|
||||||
"require": {
|
"require": {
|
||||||
"fguillot/json-rpc": "@stable",
|
"fguillot/json-rpc": "@stable",
|
||||||
"ext-curl": "*"
|
"ext-curl": "*",
|
||||||
|
"symfony/process": "^7.1"
|
||||||
}
|
}
|
||||||
,
|
,
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
63
composer.lock
generated
63
composer.lock
generated
@ -4,7 +4,7 @@
|
|||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "bed911648f06c7f5eec53ba6bd058579",
|
"content-hash": "e45594209664f711602fce8f3ec35699",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "fguillot/json-rpc",
|
"name": "fguillot/json-rpc",
|
||||||
@ -50,6 +50,67 @@
|
|||||||
"source": "https://github.com/matasarei/json-rpc/tree/v1.3.0"
|
"source": "https://github.com/matasarei/json-rpc/tree/v1.3.0"
|
||||||
},
|
},
|
||||||
"time": "2024-06-08T19:21:47+00:00"
|
"time": "2024-06-08T19:21:47+00:00"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "symfony/process",
|
||||||
|
"version": "v7.1.3",
|
||||||
|
"source": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "https://github.com/symfony/process.git",
|
||||||
|
"reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca"
|
||||||
|
},
|
||||||
|
"dist": {
|
||||||
|
"type": "zip",
|
||||||
|
"url": "https://api.github.com/repos/symfony/process/zipball/7f2f542c668ad6c313dc4a5e9c3321f733197eca",
|
||||||
|
"reference": "7f2f542c668ad6c313dc4a5e9c3321f733197eca",
|
||||||
|
"shasum": ""
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"php": ">=8.2"
|
||||||
|
},
|
||||||
|
"type": "library",
|
||||||
|
"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": "Executes commands in sub-processes",
|
||||||
|
"homepage": "https://symfony.com",
|
||||||
|
"support": {
|
||||||
|
"source": "https://github.com/symfony/process/tree/v7.1.3"
|
||||||
|
},
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"url": "https://symfony.com/sponsor",
|
||||||
|
"type": "custom"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://github.com/fabpot",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
|
||||||
|
"type": "tidelift"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"time": "2024-07-26T12:44:47+00:00"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"packages-dev": [
|
"packages-dev": [
|
||||||
|
Loading…
Reference in New Issue
Block a user