From 11c899fddd00598562d33337b5b242af31b9de10 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 15 Jan 2019 23:37:26 +0700 Subject: [PATCH] Use more platform-independent code for our video quality comparator (e.g. based on libmediainfo or ffprobe depending on configuration) to make sure --conflict auto works as expected on platforms where libmediainfo doesn't work --- source/net/filebot/media/VideoQuality.java | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/source/net/filebot/media/VideoQuality.java b/source/net/filebot/media/VideoQuality.java index 547733dd..7912108c 100644 --- a/source/net/filebot/media/VideoQuality.java +++ b/source/net/filebot/media/VideoQuality.java @@ -4,6 +4,8 @@ import static java.util.Comparator.*; import static net.filebot.Logging.*; import static net.filebot.MediaTypes.*; import static net.filebot.media.MediaDetection.*; +import static net.filebot.media.XattrMetaInfo.*; +import static net.filebot.util.FileUtilities.*; import static net.filebot.util.StringUtilities.*; import java.io.File; @@ -20,7 +22,7 @@ public class VideoQuality implements Comparator { return DESCENDING_ORDER.compare(f1, f2) < 0; } - private final Comparator chain = comparing(f -> new MediaBindingBean(f, f), comparingInt(this::getRepack).thenComparingInt(this::getResolution).thenComparingLong(MediaBindingBean::getFileSize)); + private final Comparator chain = comparingInt(this::getRepack).thenComparingInt(this::getResolution).thenComparingLong(File::length); @Override public int compare(File f1, File f2) { @@ -29,19 +31,19 @@ public class VideoQuality implements Comparator { private final Pattern repack = releaseInfo.getRepackPattern(); - private int getRepack(MediaBindingBean m) { - return find(m.getFileName(), repack) || find(m.getOriginalFileName(), repack) ? 1 : 0; + private int getRepack(File f) { + return find(f.getName(), repack) || find(xattr.getOriginalName(f), repack) ? 1 : 0; } - private int getResolution(MediaBindingBean m) { - // use video file for video/subtitle pairs when comparing the subtitle file - File mediaFile = m.getInferredMediaFile(); + private int getResolution(File f) { + // use primary video file when checking video resolution of subtitle files or disk folders + f = new MediaBindingBean(f, f).getInferredMediaFile(); - if (VIDEO_FILES.accept(mediaFile)) { - try { - return m.getDimension().stream().mapToInt(Number::intValue).reduce((a, b) -> a * b).orElse(0); + if (VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) { + try (MediaCharacteristics mi = MediaCharacteristicsParser.open(f)) { + return mi.getWidth() * mi.getHeight(); } catch (Exception e) { - debug.warning("Failed to read media info: " + e); + debug.warning("Failed to read video resolution: " + e.getMessage()); } }