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

Add support for telegram document attachments. Close #2

This commit is contained in:
aNNiMON 2023-10-18 23:50:02 +03:00
parent 46f40a4617
commit 1a9b338836
3 changed files with 30 additions and 3 deletions

View File

@ -1,7 +1,9 @@
package com.annimon.ffmpegbot.parameters.resolvers;
import com.annimon.ffmpegbot.parameters.AudioStreamByLanguage;
import com.annimon.ffmpegbot.parameters.Parameter;
import com.annimon.ffmpegbot.session.FileInfo;
import com.annimon.ffmpegbot.session.FileType;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@ -9,8 +11,13 @@ public class MultiAudioStreamsResolver implements ParametersResolver {
@Override
public void resolve(@NotNull List<Parameter<?>> parameters, @NotNull FileInfo fileInfo) {
// TODO: Disabled until files support will be implemented
// Check for mkv file type
// parameters.add(new AudioStreamByLanguage());
// TODO: ffprobe check for actual codec
if (!fileInfo.fileType().equals(FileType.VIDEO)) {
return;
}
if (fileInfo.getExtension().equals("mkv")) {
parameters.add(new AudioStreamByLanguage());
}
}
}

View File

@ -1,8 +1,15 @@
package com.annimon.ffmpegbot.session;
import org.apache.commons.io.FilenameUtils;
import java.util.Locale;
public record FileInfo(FileType fileType, String fileId, String filename,
Long fileSize, Integer duration, Integer width, Integer height) {
public FileInfo(FileType fileType, String fileId, String filename, Long fileSize, Integer duration) {
this(fileType, fileId, filename, fileSize, duration, null, null);
}
public String getExtension() {
return FilenameUtils.getExtension(filename).toLowerCase(Locale.ROOT);
}
}

View File

@ -28,6 +28,19 @@ public class Resolver {
} else if (message.hasVoice()) {
final var att = message.getVoice();
return new FileInfo(FileType.VOICE, att.getFileId(), null, att.getFileSize(), att.getDuration());
} else if (message.hasDocument()) {
final var att = message.getDocument();
final var mimeType = att.getMimeType();
if (mimeType == null || att.getFileSize() == null || att.getFileSize() == 0) {
return null;
} else if (mimeType.startsWith("video/")) {
return new FileInfo(FileType.VIDEO, att.getFileId(), att.getFileName(),
att.getFileSize(), null);
} else if (mimeType.startsWith("audio/")) {
return new FileInfo(FileType.AUDIO, att.getFileId(), att.getFileName(),
att.getFileSize(), null);
}
return null;
} else {
return null;
}