🐛 Trying to debug with Process

This commit is contained in:
Clement Desmidt 2024-08-06 17:23:06 +02:00
parent 808b786f5e
commit a4a678d32f
3 changed files with 85 additions and 10 deletions

View File

@ -3,6 +3,8 @@
namespace Shikiryu\Bot\Commands;
use Shikiryu\Bot\Bot;
use Symfony\Component\Process\Exception\ProcessFailedException;
use Symfony\Component\Process\Process;
class Youtubedl implements Icommands
{
@ -24,16 +26,27 @@ class Youtubedl implements Icommands
if (in_array($type, ['', 'audio'], true)) {
$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);
exec($cmd, $output);
$bot->sendChatMessage('', sprintf('Je lance %s', $cmd));
$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]);
// $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);
// exec($cmd, $output);
// $bot->sendChatMessage('', sprintf('Je lance %s', $cmd));
} else {
$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);
exec($cmd, $output);
$bot->sendChatMessage('', sprintf('Je lance %s', $cmd));
$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]);
// $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);
// 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
@ -54,7 +67,7 @@ class Youtubedl implements Icommands
private static function getDownloadFolder(Bot $bot): string
{
return $bot->getConfig()['youtube-dl']['folder'] ?? __DIR__.'/../../';
return $bot->getConfig()['youtube-dl']['download_folder'] ?? __DIR__.'/../../';
}
}

View File

@ -1,7 +1,8 @@
{
"require": {
"fguillot/json-rpc": "@stable",
"ext-curl": "*"
"ext-curl": "*",
"symfony/process": "^7.1"
}
,
"require-dev": {

63
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "bed911648f06c7f5eec53ba6bd058579",
"content-hash": "e45594209664f711602fce8f3ec35699",
"packages": [
{
"name": "fguillot/json-rpc",
@ -50,6 +50,67 @@
"source": "https://github.com/matasarei/json-rpc/tree/v1.3.0"
},
"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": [