From 8b0c1ea81539bb21ed6cf4b4fda6b00169a09160 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 25 Jan 2021 22:08:52 +0100 Subject: [PATCH] Changes newExtension to outputExtension and requires streams to be filtered by type before calling getFirstTypeStream --- .../converter/AbstractConverter.java | 23 ++++++++----------- .../converter/AdvancedConverter.java | 2 +- .../converter/AnimeConverter.java | 4 ++-- .../converter/AudioConverter.java | 2 +- .../converter/WebVideoConverter.java | 6 ++--- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/AbstractConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/AbstractConverter.java index cbc40cd..4c2a4f8 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/AbstractConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/AbstractConverter.java @@ -18,7 +18,7 @@ import java.util.List; */ public abstract class AbstractConverter implements Converter { final boolean debug = false; - private final String newExtension; + private final String outputExtension; String ffprobePath; String ffmpegPath; String[] audioFormats; @@ -27,8 +27,8 @@ public abstract class AbstractConverter implements Converter { /** * Initializes variables used by the abstract converter */ - AbstractConverter(String newExtension) { - this.newExtension = newExtension; + AbstractConverter(String outputExtension) { + this.outputExtension = outputExtension; OutputUtil.setDebug(this.debug); try { audioFormats = FileUtil.readFileLines("audio_formats.txt"); @@ -127,7 +127,7 @@ public abstract class AbstractConverter implements Converter { throw new IllegalArgumentException("The file has no valid streams. Please make sure the file exists and" + " is not corrupt."); } - String newPath = FileUtil.getNonCollidingPath(folder, file, newExtension); + String newPath = FileUtil.getNonCollidingPath(folder, file, outputExtension); OutputUtil.println(); OutputUtil.println("Preparing to start process..."); OutputUtil.println("Converting " + file); @@ -138,11 +138,10 @@ public abstract class AbstractConverter implements Converter { /** * Gets the first audio stream from a list of streams * - * @param streams

A list of all streams.

+ * @param audioStreams

A list of all streams.

* @return

The first audio stream found or null if no audio streams were found.

*/ - AudioStream getFirstAudioSteam(List streams) { - List audioStreams = filterStreamsByType(streams, AudioStream.class); + AudioStream getFirstAudioStream(List audioStreams) { AudioStream audioStream = null; if (audioStreams.size() > 0) { audioStream = audioStreams.get(0); @@ -153,11 +152,10 @@ public abstract class AbstractConverter implements Converter { /** * Gets the first subtitle stream from a list of streams * - * @param streams

A list of all streams.

+ * @param subtitleStreams

A list of all subtitle streams.

* @return

The first subtitle stream found or null if no subtitle streams were found.

*/ - SubtitleStream getFirstSubtitleStream(List streams) { - List subtitleStreams = filterStreamsByType(streams, SubtitleStream.class); + SubtitleStream getFirstSubtitleStream(List subtitleStreams) { SubtitleStream subtitleStream = null; if (subtitleStreams.size() > 0) { subtitleStream = subtitleStreams.get(0); @@ -168,11 +166,10 @@ public abstract class AbstractConverter implements Converter { /** * Gets the first video stream from a list of streams * - * @param streams

A list of all streams.

+ * @param videoStreams

A list of all streams.

* @return

The first video stream found or null if no video streams were found.

*/ - VideoStream getFirstVideoStream(List streams) { - List videoStreams = filterStreamsByType(streams, VideoStream.class); + VideoStream getFirstVideoStream(List videoStreams) { VideoStream videoStream = null; if (videoStreams.size() > 0) { videoStream = videoStreams.get(0); diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/AdvancedConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/AdvancedConverter.java index 519edff..64a6742 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/AdvancedConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/AdvancedConverter.java @@ -80,7 +80,7 @@ public class AdvancedConverter extends AbstractConverter { //Get the first audio stream in accordance with chosen languages List audioStreams = filterAudioStreams(filterStreamsByType(streams, AudioStream.class), audioLanguages); - AudioStream audioStream = getFirstAudioSteam(new ArrayList<>(audioStreams)); + AudioStream audioStream = getFirstAudioStream(new ArrayList<>(audioStreams)); //Get the first subtitle stream in accordance with chosen languages and signs and songs prevention List subtitleStreams = filterSubtitleStreams(filterStreamsByType(streams, diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java index ff14aa9..9c114a1 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/AnimeConverter.java @@ -49,7 +49,7 @@ public class AnimeConverter extends AbstractConverter { //Get the first audio stream in accordance with chosen languages List audioStreams = filterAudioStreams(filterStreamsByType(streams, AudioStream.class), audioLanguages); - AudioStream audioStream = getFirstAudioSteam(new ArrayList<>(audioStreams)); + AudioStream audioStream = getFirstAudioStream(new ArrayList<>(audioStreams)); //Get the first subtitle stream in accordance with chosen languages and signs and songs prevention List subtitleStreams = filterSubtitleStreams(filterStreamsByType(streams, @@ -57,7 +57,7 @@ public class AnimeConverter extends AbstractConverter { SubtitleStream subtitleStream = getFirstSubtitleStream(new ArrayList<>(subtitleStreams)); //Get the first video stream - VideoStream videoStream = getFirstVideoStream(streams); + VideoStream videoStream = getFirstVideoStream(filterStreamsByType(streams, VideoStream.class)); //Add streams to output file FFMpegHelper.addAudioStream(command, audioStream, toStereo); diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/AudioConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/AudioConverter.java index fa63110..b9536c7 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/AudioConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/AudioConverter.java @@ -33,7 +33,7 @@ public class AudioConverter extends AbstractConverter { } //Gets the first audio stream from the file and adds it to the output file - AudioStream audioStream = getFirstAudioSteam(streams); + AudioStream audioStream = getFirstAudioStream(filterStreamsByType(streams, AudioStream.class)); FFMpegHelper.addAudioStream(command, audioStream, false); command.add(outFile); diff --git a/src/main/java/net/knarcraft/ffmpegconverter/converter/WebVideoConverter.java b/src/main/java/net/knarcraft/ffmpegconverter/converter/WebVideoConverter.java index 74363e9..6551350 100644 --- a/src/main/java/net/knarcraft/ffmpegconverter/converter/WebVideoConverter.java +++ b/src/main/java/net/knarcraft/ffmpegconverter/converter/WebVideoConverter.java @@ -37,9 +37,9 @@ public class WebVideoConverter extends AbstractConverter { } //Get first streams from the file - SubtitleStream subtitleStream = getFirstSubtitleStream(streams); - VideoStream videoStream = getFirstVideoStream(streams); - AudioStream audioStream = getFirstAudioSteam(streams); + SubtitleStream subtitleStream = getFirstSubtitleStream(filterStreamsByType(streams, SubtitleStream.class)); + VideoStream videoStream = getFirstVideoStream(filterStreamsByType(streams, VideoStream.class)); + AudioStream audioStream = getFirstAudioStream(filterStreamsByType(streams, AudioStream.class)); //Add streams to output FFMpegHelper.addSubtitleAndVideoStream(command, subtitleStream, videoStream, file);