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:
parent
46f40a4617
commit
1a9b338836
@ -1,7 +1,9 @@
|
|||||||
package com.annimon.ffmpegbot.parameters.resolvers;
|
package com.annimon.ffmpegbot.parameters.resolvers;
|
||||||
|
|
||||||
|
import com.annimon.ffmpegbot.parameters.AudioStreamByLanguage;
|
||||||
import com.annimon.ffmpegbot.parameters.Parameter;
|
import com.annimon.ffmpegbot.parameters.Parameter;
|
||||||
import com.annimon.ffmpegbot.session.FileInfo;
|
import com.annimon.ffmpegbot.session.FileInfo;
|
||||||
|
import com.annimon.ffmpegbot.session.FileType;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -9,8 +11,13 @@ public class MultiAudioStreamsResolver implements ParametersResolver {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resolve(@NotNull List<Parameter<?>> parameters, @NotNull FileInfo fileInfo) {
|
public void resolve(@NotNull List<Parameter<?>> parameters, @NotNull FileInfo fileInfo) {
|
||||||
// TODO: Disabled until files support will be implemented
|
// TODO: ffprobe check for actual codec
|
||||||
// Check for mkv file type
|
if (!fileInfo.fileType().equals(FileType.VIDEO)) {
|
||||||
// parameters.add(new AudioStreamByLanguage());
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fileInfo.getExtension().equals("mkv")) {
|
||||||
|
parameters.add(new AudioStreamByLanguage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,15 @@
|
|||||||
package com.annimon.ffmpegbot.session;
|
package com.annimon.ffmpegbot.session;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
public record FileInfo(FileType fileType, String fileId, String filename,
|
public record FileInfo(FileType fileType, String fileId, String filename,
|
||||||
Long fileSize, Integer duration, Integer width, Integer height) {
|
Long fileSize, Integer duration, Integer width, Integer height) {
|
||||||
public FileInfo(FileType fileType, String fileId, String filename, Long fileSize, Integer duration) {
|
public FileInfo(FileType fileType, String fileId, String filename, Long fileSize, Integer duration) {
|
||||||
this(fileType, fileId, filename, fileSize, duration, null, null);
|
this(fileType, fileId, filename, fileSize, duration, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getExtension() {
|
||||||
|
return FilenameUtils.getExtension(filename).toLowerCase(Locale.ROOT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,19 @@ public class Resolver {
|
|||||||
} else if (message.hasVoice()) {
|
} else if (message.hasVoice()) {
|
||||||
final var att = message.getVoice();
|
final var att = message.getVoice();
|
||||||
return new FileInfo(FileType.VOICE, att.getFileId(), null, att.getFileSize(), att.getDuration());
|
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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user