Alfred/bot/Commands/Youtubedl.php

39 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2020-03-26 00:11:37 +01:00
<?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';
}
}