mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-24 00:38:52 -05:00
Refactor
This commit is contained in:
parent
429641a6fc
commit
61780da8a9
@ -10,6 +10,7 @@ import static net.filebot.Settings.*;
|
||||
import static net.filebot.WebServices.*;
|
||||
import static net.filebot.hash.VerificationUtilities.*;
|
||||
import static net.filebot.media.MediaDetection.*;
|
||||
import static net.filebot.media.MediaSize.*;
|
||||
import static net.filebot.media.XattrMetaInfo.*;
|
||||
import static net.filebot.subtitle.SubtitleUtilities.*;
|
||||
import static net.filebot.util.FileUtilities.*;
|
||||
|
@ -21,9 +21,7 @@ import java.net.URL;
|
||||
import java.text.CollationKey;
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -47,7 +45,6 @@ import java.util.regex.Pattern;
|
||||
import net.filebot.Resource;
|
||||
import net.filebot.WebServices;
|
||||
import net.filebot.archive.Archive;
|
||||
import net.filebot.format.MediaBindingBean;
|
||||
import net.filebot.similarity.CommonSequenceMatcher;
|
||||
import net.filebot.similarity.DateMatcher;
|
||||
import net.filebot.similarity.EpisodeMetrics;
|
||||
@ -1408,55 +1405,6 @@ public class MediaDetection {
|
||||
}
|
||||
}
|
||||
|
||||
public static Comparator<File> VIDEO_SIZE_ORDER = new Comparator<File>() {
|
||||
|
||||
@Override
|
||||
public int compare(File f1, File f2) {
|
||||
long[] v1 = getSizeValues(f1);
|
||||
long[] v2 = getSizeValues(f2);
|
||||
|
||||
for (int i = 0; i < v1.length; i++) {
|
||||
// best to worst
|
||||
int d = new Long(v1[i]).compareTo(new Long(v2[i]));
|
||||
if (d != 0) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long[] getSizeValues(File f) {
|
||||
long[] v = new long[] { 0, 0 };
|
||||
|
||||
try {
|
||||
if (VIDEO_FILES.accept(f) || SUBTITLE_FILES.accept(f)) {
|
||||
MediaBindingBean media = new MediaBindingBean(null, f, null);
|
||||
|
||||
// 1. Video Resolution
|
||||
List<Integer> dim = media.getDimension();
|
||||
v[0] = dim.get(0).longValue() * dim.get(1).longValue();
|
||||
|
||||
// 2. File Size
|
||||
v[1] = media.getInferredMediaFile().length();
|
||||
} else if (AUDIO_FILES.accept(f)) {
|
||||
// 1. Audio BitRate
|
||||
v[0] = 0;
|
||||
|
||||
// 2. File Size
|
||||
v[1] = f.length();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// negative values for invalid files
|
||||
debug.warning(format("Unable to read media info: %s [%s]", e.getMessage(), f.getName()));
|
||||
|
||||
Arrays.fill(v, -1);
|
||||
return v;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
};
|
||||
|
||||
public static List<File> getMediaUnits(File folder) {
|
||||
if (folder.isHidden()) {
|
||||
return emptyList();
|
||||
|
49
source/net/filebot/media/MediaSize.java
Normal file
49
source/net/filebot/media/MediaSize.java
Normal file
@ -0,0 +1,49 @@
|
||||
package net.filebot.media;
|
||||
|
||||
import static net.filebot.Logging.*;
|
||||
import static net.filebot.MediaTypes.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Comparator;
|
||||
|
||||
import net.filebot.format.MediaBindingBean;
|
||||
|
||||
public class MediaSize implements Comparator<File> {
|
||||
|
||||
public static final Comparator<File> VIDEO_SIZE_ORDER = new MediaSize();
|
||||
|
||||
@Override
|
||||
public int compare(File f1, File f2) {
|
||||
long[] v1 = getSizeValues(f1);
|
||||
long[] v2 = getSizeValues(f2);
|
||||
|
||||
// best to worst
|
||||
for (int i = 0; i < v1.length; i++) {
|
||||
int d = Long.compare(v1[i], v2[i]);
|
||||
if (d != 0) {
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long[] getSizeValues(File f) {
|
||||
long[] v = { -1, -1 };
|
||||
|
||||
if (VIDEO_FILES.accept(f) || SUBTITLE_FILES.accept(f)) {
|
||||
try {
|
||||
MediaBindingBean media = new MediaBindingBean(null, f, null);
|
||||
v[1] = media.getInferredMediaFile().length(); // File Size
|
||||
v[0] = media.getDimension().stream().mapToLong(Number::longValue).reduce((a, b) -> a * b).orElse(-1); // Video Resolution
|
||||
} catch (Throwable e) {
|
||||
debug.warning(format("Failed to read media info: %s [%s]", e.getMessage(), f.getName()));
|
||||
}
|
||||
} else {
|
||||
v[1] = f.length(); // File Size
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user