replyPolitely('L\'url n\'est pas conforme'); } if (!in_array($type, ['', 'audio', 'video', 'vidéo'], true)) { $bot->replyPolitely('Je n\'ai pas compris ce que je devais faire'); } $youtubedl = self::getYoutubeDl($bot); if (in_array($type, ['', 'audio'], true)) { $type = 'l\'audio'; $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'; $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)); } $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 { return 'Youtubedl wrapper'; } private static function getYoutubeDl(Bot $bot): string { $youtubedl_bin = $bot->getConfig()['youtube-dl']['bin']; if (empty($youtubedl_bin)) { exec('which youtube-dl', $output); $youtubedl_bin = current($output); } return $youtubedl_bin; } private static function getDownloadFolder(Bot $bot): string { return $bot->getConfig()['youtube-dl']['download_folder'] ?? __DIR__.'/../../'; } }