From ded88eb5b54152a4f27386789a69ab60a98d8768 Mon Sep 17 00:00:00 2001
From: EpicKnarvik97
Date: Sat, 20 Apr 2024 00:43:52 +0200
Subject: [PATCH] Makes the anime converter map unknown streams
---
.../container/StreamProbeResult.java | 13 +++++++++
.../converter/AnimeConverter.java | 3 +++
.../ffmpegconverter/streams/OtherStream.java | 27 +++++++++++++++++++
.../streams/SubtitleStream.java | 3 ++-
.../ffmpegconverter/utility/FFMpegHelper.java | 10 ++++++-
5 files changed, 54 insertions(+), 2 deletions(-)
create mode 100644 src/main/java/net/knarcraft/ffmpegconverter/streams/OtherStream.java
diff --git a/src/main/java/net/knarcraft/ffmpegconverter/container/StreamProbeResult.java b/src/main/java/net/knarcraft/ffmpegconverter/container/StreamProbeResult.java
index 86fb0c2..fa2d671 100644
--- a/src/main/java/net/knarcraft/ffmpegconverter/container/StreamProbeResult.java
+++ b/src/main/java/net/knarcraft/ffmpegconverter/container/StreamProbeResult.java
@@ -1,6 +1,7 @@
package net.knarcraft.ffmpegconverter.container;
import net.knarcraft.ffmpegconverter.streams.AudioStream;
+import net.knarcraft.ffmpegconverter.streams.OtherStream;
import net.knarcraft.ffmpegconverter.streams.StreamObject;
import net.knarcraft.ffmpegconverter.streams.SubtitleStream;
import net.knarcraft.ffmpegconverter.streams.VideoStream;
@@ -48,6 +49,18 @@ public record StreamProbeResult(@NotNull List parsedFiles, @NotNull ListOther streams are streams that are not video, audio or subtitle streams
+ *
+ * @return All other streams
+ */
+ @NotNull
+ public List getOtherStreams() {
+ return filterStreamsByType(this.parsedStreams, OtherStream.class);
+ }
+
/**
* Filters parsed streams into one of the stream types
*
diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java
index 27a2b33..e763bb8 100644
--- a/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java
+++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java
@@ -139,6 +139,9 @@ public class AnimeConverter extends AbstractConverter {
modules.add(new CopyVideoModule());
}
+ // Map all attached streams, such as fonts and covers
+ modules.add(new MapAllModule<>(probeResult.getOtherStreams()));
+
modules.add(new SetOutputFileModule(outFile));
new ModuleExecutor(command, modules).execute();
diff --git a/src/main/java/net/knarcraft/ffmpegconverter/streams/OtherStream.java b/src/main/java/net/knarcraft/ffmpegconverter/streams/OtherStream.java
new file mode 100644
index 0000000..18e5944
--- /dev/null
+++ b/src/main/java/net/knarcraft/ffmpegconverter/streams/OtherStream.java
@@ -0,0 +1,27 @@
+package net.knarcraft.ffmpegconverter.streams;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Map;
+
+/**
+ * A stream type for attached streams that aren't audio, video or subtitles
+ */
+public class OtherStream extends AbstractStream {
+
+ /**
+ * Instantiates a new other stream
+ *
+ * @param streamInfo All info about the stream
+ * @param inputIndex The index of the input file this stream belongs to
+ */
+ public OtherStream(@NotNull Map streamInfo, int inputIndex) {
+ super(streamInfo, inputIndex, 0);
+ }
+
+ @Override
+ public char streamTypeCharacter() {
+ return '?';
+ }
+
+}
diff --git a/src/main/java/net/knarcraft/ffmpegconverter/streams/SubtitleStream.java b/src/main/java/net/knarcraft/ffmpegconverter/streams/SubtitleStream.java
index cfaeb63..7fa296e 100644
--- a/src/main/java/net/knarcraft/ffmpegconverter/streams/SubtitleStream.java
+++ b/src/main/java/net/knarcraft/ffmpegconverter/streams/SubtitleStream.java
@@ -58,7 +58,8 @@ public class SubtitleStream extends AbstractStream implements StreamObject {
!titleLowercase.matches("signs?") &&
!titleLowercase.matches("songs?") &&
!titleLowercase.matches(".*signs only.*") &&
- !titleLowercase.matches(".* signs .*");
+ !titleLowercase.matches(".* signs .*") &&
+ !titleLowercase.matches("signs@.*");
}
@Override
diff --git a/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java b/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java
index 5a62e3a..1958052 100644
--- a/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java
+++ b/src/main/java/net/knarcraft/ffmpegconverter/utility/FFMpegHelper.java
@@ -4,6 +4,7 @@ import net.knarcraft.ffmpegconverter.container.FFMpegCommand;
import net.knarcraft.ffmpegconverter.container.ProcessResult;
import net.knarcraft.ffmpegconverter.container.StreamProbeResult;
import net.knarcraft.ffmpegconverter.streams.AudioStream;
+import net.knarcraft.ffmpegconverter.streams.OtherStream;
import net.knarcraft.ffmpegconverter.streams.StreamObject;
import net.knarcraft.ffmpegconverter.streams.StreamTag;
import net.knarcraft.ffmpegconverter.streams.SubtitleStream;
@@ -300,7 +301,12 @@ public final class FFMpegHelper {
String codecType = ValueParsingHelper.parseString(streamInfo.get(StreamTag.CODEC_TYPE), "");
switch (codecType) {
case "video":
- parsedStreams.add(new VideoStream(streamInfo, 0, relativeVideoIndex++));
+ // Some attached covers are marked as video streams
+ if (ValueParsingHelper.parseInt(streamInfo.get(StreamTag.DISPOSITION_ATTACHED_PIC), 0) != 1) {
+ parsedStreams.add(new VideoStream(streamInfo, 0, relativeVideoIndex++));
+ } else {
+ parsedStreams.add(new OtherStream(streamInfo, 0));
+ }
break;
case "audio":
parsedStreams.add(new AudioStream(streamInfo, 0, relativeAudioIndex++));
@@ -308,6 +314,8 @@ public final class FFMpegHelper {
case "subtitle":
parsedStreams.add(new SubtitleStream(streamInfo, 0, relativeSubtitleIndex++));
break;
+ default:
+ parsedStreams.add(new OtherStream(streamInfo, 0));
}
}
StreamProbeResult probeResult = new StreamProbeResult(List.of(file), parsedStreams);