🎉 Hello world
This commit is contained in:
38
bot/Commands/Youtubedl.php
Normal file
38
bot/Commands/Youtubedl.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Shikiryu\Bot\Commands;
|
||||
|
||||
use Shikiryu\Bot\Bot;
|
||||
|
||||
class Youtubedl implements Icommands
|
||||
{
|
||||
|
||||
public static function getMessage(Bot $bot, array $data)
|
||||
{
|
||||
$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
|
||||
$type = $data[3]; // ex: audio
|
||||
|
||||
if (empty($url)) {
|
||||
$bot->replyPolitely('L\'url n\'est pas conforme');
|
||||
}
|
||||
|
||||
if (!in_array($type, ['', 'audio', 'video'], true)) {
|
||||
$bot->replyPolitely('Je n\'ai pas compris ce que je devais faire');
|
||||
}
|
||||
|
||||
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 &");
|
||||
} 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 &");
|
||||
}
|
||||
$bot->replyPolitely(sprintf('Je %s %s', $action, $type));
|
||||
}
|
||||
|
||||
public static function getDescription()
|
||||
{
|
||||
return 'Youtubedl wrapper';
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user