Makes the anime converter map unknown streams
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good

This commit is contained in:
Kristian Knarvik 2024-04-20 00:43:52 +02:00
parent 3c9fa55585
commit ded88eb5b5
5 changed files with 54 additions and 2 deletions

View File

@ -1,6 +1,7 @@
package net.knarcraft.ffmpegconverter.container; package net.knarcraft.ffmpegconverter.container;
import net.knarcraft.ffmpegconverter.streams.AudioStream; import net.knarcraft.ffmpegconverter.streams.AudioStream;
import net.knarcraft.ffmpegconverter.streams.OtherStream;
import net.knarcraft.ffmpegconverter.streams.StreamObject; import net.knarcraft.ffmpegconverter.streams.StreamObject;
import net.knarcraft.ffmpegconverter.streams.SubtitleStream; import net.knarcraft.ffmpegconverter.streams.SubtitleStream;
import net.knarcraft.ffmpegconverter.streams.VideoStream; import net.knarcraft.ffmpegconverter.streams.VideoStream;
@ -48,6 +49,18 @@ public record StreamProbeResult(@NotNull List<File> parsedFiles, @NotNull List<S
return filterStreamsByType(this.parsedStreams, VideoStream.class); return filterStreamsByType(this.parsedStreams, VideoStream.class);
} }
/**
* Gets all other streams
*
* <p>Other streams are streams that are not video, audio or subtitle streams</p>
*
* @return <p>All other streams</p>
*/
@NotNull
public List<OtherStream> getOtherStreams() {
return filterStreamsByType(this.parsedStreams, OtherStream.class);
}
/** /**
* Filters parsed streams into one of the stream types * Filters parsed streams into one of the stream types
* *

View File

@ -139,6 +139,9 @@ public class AnimeConverter extends AbstractConverter {
modules.add(new CopyVideoModule()); modules.add(new CopyVideoModule());
} }
// Map all attached streams, such as fonts and covers
modules.add(new MapAllModule<>(probeResult.getOtherStreams()));
modules.add(new SetOutputFileModule(outFile)); modules.add(new SetOutputFileModule(outFile));
new ModuleExecutor(command, modules).execute(); new ModuleExecutor(command, modules).execute();

View File

@ -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 <p>All info about the stream</p>
* @param inputIndex <p>The index of the input file this stream belongs to</p>
*/
public OtherStream(@NotNull Map<StreamTag, String> streamInfo, int inputIndex) {
super(streamInfo, inputIndex, 0);
}
@Override
public char streamTypeCharacter() {
return '?';
}
}

View File

@ -58,7 +58,8 @@ public class SubtitleStream extends AbstractStream implements StreamObject {
!titleLowercase.matches("signs?") && !titleLowercase.matches("signs?") &&
!titleLowercase.matches("songs?") && !titleLowercase.matches("songs?") &&
!titleLowercase.matches(".*signs only.*") && !titleLowercase.matches(".*signs only.*") &&
!titleLowercase.matches(".* signs .*"); !titleLowercase.matches(".* signs .*") &&
!titleLowercase.matches("signs@.*");
} }
@Override @Override

View File

@ -4,6 +4,7 @@ import net.knarcraft.ffmpegconverter.container.FFMpegCommand;
import net.knarcraft.ffmpegconverter.container.ProcessResult; import net.knarcraft.ffmpegconverter.container.ProcessResult;
import net.knarcraft.ffmpegconverter.container.StreamProbeResult; import net.knarcraft.ffmpegconverter.container.StreamProbeResult;
import net.knarcraft.ffmpegconverter.streams.AudioStream; import net.knarcraft.ffmpegconverter.streams.AudioStream;
import net.knarcraft.ffmpegconverter.streams.OtherStream;
import net.knarcraft.ffmpegconverter.streams.StreamObject; import net.knarcraft.ffmpegconverter.streams.StreamObject;
import net.knarcraft.ffmpegconverter.streams.StreamTag; import net.knarcraft.ffmpegconverter.streams.StreamTag;
import net.knarcraft.ffmpegconverter.streams.SubtitleStream; import net.knarcraft.ffmpegconverter.streams.SubtitleStream;
@ -300,7 +301,12 @@ public final class FFMpegHelper {
String codecType = ValueParsingHelper.parseString(streamInfo.get(StreamTag.CODEC_TYPE), ""); String codecType = ValueParsingHelper.parseString(streamInfo.get(StreamTag.CODEC_TYPE), "");
switch (codecType) { switch (codecType) {
case "video": 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; break;
case "audio": case "audio":
parsedStreams.add(new AudioStream(streamInfo, 0, relativeAudioIndex++)); parsedStreams.add(new AudioStream(streamInfo, 0, relativeAudioIndex++));
@ -308,6 +314,8 @@ public final class FFMpegHelper {
case "subtitle": case "subtitle":
parsedStreams.add(new SubtitleStream(streamInfo, 0, relativeSubtitleIndex++)); parsedStreams.add(new SubtitleStream(streamInfo, 0, relativeSubtitleIndex++));
break; break;
default:
parsedStreams.add(new OtherStream(streamInfo, 0));
} }
} }
StreamProbeResult probeResult = new StreamProbeResult(List.of(file), parsedStreams); StreamProbeResult probeResult = new StreamProbeResult(List.of(file), parsedStreams);