1
0
mirror of https://github.com/aNNiMON/ffmpegbot synced 2024-09-19 22:54:20 +03:00

Fix optional argument of /dl command

This commit is contained in:
aNNiMON 2023-01-10 23:05:48 +02:00
parent 5e29f677c7
commit 5d480be29e

View File

@ -9,7 +9,9 @@ import com.annimon.tgbotsmodule.commands.context.RegexMessageContext;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import java.io.File; import java.io.File;
import java.util.Optional;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.function.Predicate;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class YtDlpCommandBundle implements CommandBundle<For> { public class YtDlpCommandBundle implements CommandBundle<For> {
@ -23,7 +25,9 @@ public class YtDlpCommandBundle implements CommandBundle<For> {
private void download(@NotNull RegexMessageContext ctx) { private void download(@NotNull RegexMessageContext ctx) {
final String url = ctx.group(1); final String url = ctx.group(1);
final String downloadOption = ctx.group(2).isEmpty() ? "720": ctx.group(2); final String downloadOption = Optional.ofNullable(ctx.group(2))
.filter(Predicate.not(String::isBlank))
.orElse("720");
final var fileType = downloadOption.equals("audio") ? FileType.AUDIO : FileType.VIDEO; final var fileType = downloadOption.equals("audio") ? FileType.AUDIO : FileType.VIDEO;
final var ytDlpSession = new YtDlpSession(url, downloadOption, fileType); final var ytDlpSession = new YtDlpSession(url, downloadOption, fileType);
final var filename = FilePath.generateFilename(url, Resolver.resolveDefaultFilename(fileType)); final var filename = FilePath.generateFilename(url, Resolver.resolveDefaultFilename(fileType));