✨ Add better ytdl
This commit is contained in:
@@ -6,8 +6,7 @@ use Shikiryu\Bot\Bot;
|
||||
|
||||
class Youtubedl implements Icommands
|
||||
{
|
||||
|
||||
public static function getMessage(Bot $bot, array $data)
|
||||
public static function getMessage(Bot $bot, array $data): void
|
||||
{
|
||||
$action = strtolower($data[1]); // ex: télécharge
|
||||
$url = filter_var($data[2], FILTER_VALIDATE_URL, FILTER_FLAG_PATH_REQUIRED); // ex: https://www.youtube.com/watch?v=3BXDsVD6O10
|
||||
@@ -21,18 +20,37 @@ class Youtubedl implements Icommands
|
||||
$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';
|
||||
exec("youtube-dl --extract-audio --audio-format mp3 -o '/volume1/music/Podcast/Youtube/%(upload_date)s-%(uploader)s-%(title)s.%(ext)s' $url &> /dev/null &");
|
||||
exec(sprintf('%s --extract-audio --audio-format mp3 -o %s%s %s &> /dev/null &', $youtubedl, static::getDownloadFolder($bot), '%(upload_date)s-%(uploader)s-%(title)s.%(ext)s', $url));
|
||||
} else {
|
||||
$type = 'la vidéo';
|
||||
exec("youtube-dl -f bestvideo+bestaudio/best -o '/volume1/music/Podcast/Youtube/%(upload_date)s-%(uploader)s-%(title)s.%(ext)s' $url &> /dev/null &");
|
||||
exec(sprintf('%s -f bestvideo+bestaudio/best -o %s%s %s &> /dev/null &', $youtubedl, static::getDownloadFolder($bot), '%(upload_date)s-%(uploader)s-%(title)s.%(ext)s', $url));
|
||||
}
|
||||
$bot->replyPolitely(sprintf('Je %s %s', $action, $type));
|
||||
}
|
||||
|
||||
public static function getDescription()
|
||||
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']['folder'] ?? __DIR__.'/../../';
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user