Changes some things
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
All checks were successful
KnarCraft/FFmpegConvert/pipeline/head This commit looks good
Removes any forced subtitles when changing the default stream Makes the title filter accept a list of filters, and allows using it for sorting rather than filtering
This commit is contained in:
parent
dae93b9f81
commit
ac25ca1986
@ -104,7 +104,8 @@ public class AnimeConverter extends AbstractConverter {
|
|||||||
modules.add(new SetDefaultStreamModule<>(sortedAudio, 0));
|
modules.add(new SetDefaultStreamModule<>(sortedAudio, 0));
|
||||||
|
|
||||||
//Get the first subtitle stream in accordance with chosen languages and signs and songs prevention
|
//Get the first subtitle stream in accordance with chosen languages and signs and songs prevention
|
||||||
StreamSorter<SubtitleStream> subtitleSorter = new SubtitleTitleSorter(this.subtitleNameFilter)
|
StreamSorter<SubtitleStream> subtitleSorter = new SubtitleTitleSorter(
|
||||||
|
List.of(this.subtitleNameFilter.split(",")))
|
||||||
.append(new SubtitleLanguageSorter(this.subtitleLanguages))
|
.append(new SubtitleLanguageSorter(this.subtitleLanguages))
|
||||||
.append(new MinimalSubtitleSorter(this.subtitlePreference))
|
.append(new MinimalSubtitleSorter(this.subtitlePreference))
|
||||||
.append(new ForcedFirstSorter<>(this.forcedSubtitleIndex));
|
.append(new ForcedFirstSorter<>(this.forcedSubtitleIndex));
|
||||||
|
@ -95,7 +95,7 @@ public class WebAnimeConverter extends AbstractConverter {
|
|||||||
VideoStream videoStream = getNthSteam(probeResult.getVideoStreams(), 0);
|
VideoStream videoStream = getNthSteam(probeResult.getVideoStreams(), 0);
|
||||||
|
|
||||||
//Get the first subtitle stream in accordance with chosen languages and signs and songs prevention
|
//Get the first subtitle stream in accordance with chosen languages and signs and songs prevention
|
||||||
StreamSorter<SubtitleStream> subtitleSorter = new SubtitleTitleSorter(this.subtitleNameFilter)
|
StreamSorter<SubtitleStream> subtitleSorter = new SubtitleTitleSorter(List.of(this.subtitleNameFilter))
|
||||||
.append(new MinimalSubtitleSorter(this.subtitlePreference))
|
.append(new MinimalSubtitleSorter(this.subtitlePreference))
|
||||||
.append(new SubtitleLanguageSorter(this.subtitleLanguages));
|
.append(new SubtitleLanguageSorter(this.subtitleLanguages));
|
||||||
SubtitleStream subtitleStream = getNthSteam(subtitleSorter.chainSort(probeResult.getSubtitleStreams()),
|
SubtitleStream subtitleStream = getNthSteam(subtitleSorter.chainSort(probeResult.getSubtitleStreams()),
|
||||||
|
@ -37,7 +37,7 @@ public class SetDefaultStreamModule<K extends StreamObject> implements Converter
|
|||||||
defaultModifier = '-';
|
defaultModifier = '-';
|
||||||
}
|
}
|
||||||
command.addOutputFileOption(String.format("-disposition:%s:%d", stream.streamTypeCharacter(), i),
|
command.addOutputFileOption(String.format("-disposition:%s:%d", stream.streamTypeCharacter(), i),
|
||||||
String.format("%sdefault", defaultModifier));
|
String.format("%sdefault-forced", defaultModifier));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.knarcraft.ffmpegconverter.converter.sorter;
|
package net.knarcraft.ffmpegconverter.converter.sorter;
|
||||||
|
|
||||||
|
import net.knarcraft.ffmpegconverter.FFMpegConvert;
|
||||||
import net.knarcraft.ffmpegconverter.streams.SubtitleStream;
|
import net.knarcraft.ffmpegconverter.streams.SubtitleStream;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@ -13,7 +14,7 @@ import java.util.regex.PatternSyntaxException;
|
|||||||
*/
|
*/
|
||||||
public class SubtitleTitleSorter extends AbstractSorter<SubtitleStream> {
|
public class SubtitleTitleSorter extends AbstractSorter<SubtitleStream> {
|
||||||
|
|
||||||
private final String titleFilter;
|
private final List<String> titleFilter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Instantiates a new subtitle title sorter
|
* Instantiates a new subtitle title sorter
|
||||||
@ -23,18 +24,40 @@ public class SubtitleTitleSorter extends AbstractSorter<SubtitleStream> {
|
|||||||
*
|
*
|
||||||
* @param titleFilter <p>The filter to use. RegEx match, or a string the title must contain.</p>
|
* @param titleFilter <p>The filter to use. RegEx match, or a string the title must contain.</p>
|
||||||
*/
|
*/
|
||||||
public SubtitleTitleSorter(@NotNull String titleFilter) {
|
public SubtitleTitleSorter(@NotNull List<String> titleFilter) {
|
||||||
this.titleFilter = titleFilter;
|
this.titleFilter = new ArrayList<>(titleFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull List<SubtitleStream> sort(@NotNull List<SubtitleStream> input) {
|
public @NotNull List<SubtitleStream> sort(@NotNull List<SubtitleStream> input) {
|
||||||
List<SubtitleStream> output = new ArrayList<>(input);
|
// Don't change anything if no filter is given
|
||||||
if (!this.titleFilter.trim().isEmpty()) {
|
this.titleFilter.removeIf(String::isBlank);
|
||||||
if (isValidRegularExpression(this.titleFilter) && hasSpecialRegexCharacters(this.titleFilter)) {
|
if (this.titleFilter.isEmpty()) {
|
||||||
output.removeIf((stream) -> !stream.getTitle().matches(this.titleFilter));
|
return input;
|
||||||
} else {
|
}
|
||||||
output.removeIf((stream) -> !stream.getTitle().contains(this.titleFilter));
|
|
||||||
|
List<SubtitleStream> output = new ArrayList<>();
|
||||||
|
|
||||||
|
for (String filter : this.titleFilter) {
|
||||||
|
if (filter.trim().isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isRegEx = isValidRegularExpression(filter) && hasSpecialRegexCharacters(filter);
|
||||||
|
|
||||||
|
if (FFMpegConvert.isDebugEnabled()) {
|
||||||
|
System.out.println("Filtering subtitles by filter " + filter + ". RegEx is " + isRegEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (SubtitleStream subtitleStream : input) {
|
||||||
|
String title = subtitleStream.getTitle().trim().toLowerCase();
|
||||||
|
// Add the subtitle if the filter matches, and it hasn't been added already
|
||||||
|
boolean matches = filter.trim().equals("*") || (isRegEx && title.matches(filter)) ||
|
||||||
|
(!isRegEx && title.contains(filter));
|
||||||
|
if (matches && !output.contains(subtitleStream)) {
|
||||||
|
System.out.println("Subtitle stream with title " + title + " matches");
|
||||||
|
output.add(subtitleStream);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
|
Loading…
Reference in New Issue
Block a user