1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-21 23:38:50 -05:00

Accept small files (useful for automated image processing)

This commit is contained in:
Reinhard Pointner 2019-06-15 15:14:22 +07:00
parent 04b3110d71
commit 404ea2714a
8 changed files with 42 additions and 29 deletions

View File

@ -118,7 +118,7 @@ public class AutoDetection {
return true;
}
if (VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) {
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(f)) {
// check for Japanese audio or characteristic subtitles
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
return mi.getDuration().toMinutes() < 60 || find(mi.getAudioLanguage(), JAPANESE_AUDIO_LANGUAGE_PATTERN) && find(mi.getSubtitleCodec(), JAPANESE_SUBTITLE_CODEC_PATTERN);

View File

@ -1,5 +1,8 @@
package net.filebot.media;
import static net.filebot.MediaTypes.*;
import static net.filebot.util.FileUtilities.*;
import java.io.File;
import net.filebot.mediainfo.MediaInfo;
@ -25,6 +28,10 @@ public enum MediaCharacteristicsParser {
public abstract MediaCharacteristics open(File f) throws Exception;
public boolean acceptVideoFile(File f) {
return VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE;
}
public static MediaCharacteristicsParser getDefault() {
return DEFAULT;
}

View File

@ -1113,7 +1113,7 @@ public class MediaDetection {
}
filesByExtension.stream().collect(groupingBy(f -> {
if (VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) {
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(f)) {
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
ChronoUnit d = mi.getDuration().toMinutes() < 10 ? ChronoUnit.MINUTES : ChronoUnit.HOURS;
String v = mi.getVideoCodec();

View File

@ -2,9 +2,7 @@ package net.filebot.media;
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.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
import java.io.File;
@ -38,7 +36,7 @@ public class VideoQuality implements Comparator<File> {
// use primary video file when checking video resolution of subtitle files or disk folders
f = new MediaBindingBean(f, f).getInferredMediaFile();
if (VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) {
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(f)) {
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
return mi.getWidth() * mi.getHeight() * mi.getBitRate();
} catch (Exception e) {

View File

@ -614,7 +614,7 @@ public class EpisodeMetrics {
private long getTimeStamp(File file) {
return cache.computeIfAbsent(file, f -> {
if (VIDEO_FILES.accept(file) && file.length() > ONE_MEGABYTE) {
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(f)) {
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(file)) {
Instant t = mi.getCreationTime();
if (t != null) {

View File

@ -203,11 +203,13 @@ public class SubtitleMetrics extends EpisodeMetrics {
private Map<String, Object> getVideoProperties(File file) {
return cache.computeIfAbsent(file, f -> {
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(f)) {
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
return getProperties(mi.getFrameRate(), mi.getDuration().toMillis());
} catch (Exception e) {
debug.warning(cause("Failed to read video properties", e));
}
}
return emptyMap();
});
}

View File

@ -59,18 +59,21 @@ class MediaInfoTool extends Tool<TableModel> {
return new MediaInfoTableModel();
}
List<File> files = listFiles(root, filter(VIDEO_FILES, AUDIO_FILES), HUMAN_NAME_ORDER);
List<File> files = listFiles(root, filter(VIDEO_FILES, AUDIO_FILES, IMAGE_FILES), HUMAN_NAME_ORDER);
Map<MediaInfoKey, String[]> data = new TreeMap<MediaInfoKey, String[]>();
try (MediaInfo mi = new MediaInfo()) {
IntStream.range(0, files.size()).forEach(f -> {
IntStream.range(0, files.size()).forEach(fileIndex -> {
File f = files.get(fileIndex);
if ((VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) || (AUDIO_FILES.accept(f) && f.length() > ONE_KILOBYTE) || (IMAGE_FILES.accept(f) && f.length() > 0)) {
try {
mi.open(files.get(f));
mi.open(f);
mi.snapshot().forEach((kind, streams) -> {
IntStream.range(0, streams.size()).forEach(i -> {
streams.get(i).forEach((name, value) -> {
String[] values = data.computeIfAbsent(new MediaInfoKey(kind, i, name), k -> new String[files.size()]);
values[f] = value;
IntStream.range(0, streams.size()).forEach(streamIndex -> {
streams.get(streamIndex).forEach((name, value) -> {
String[] values = data.computeIfAbsent(new MediaInfoKey(kind, streamIndex, name), k -> new String[files.size()]);
values[fileIndex] = value;
});
});
});
@ -79,6 +82,7 @@ class MediaInfoTool extends Tool<TableModel> {
} catch (Exception e) {
debug.warning(e::toString);
}
}
if (Thread.interrupted()) {
throw new CancellationException();

View File

@ -312,12 +312,14 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
sub.setSubContent(readFile(subtitleFile));
}
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(videoFile)) {
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(videoFile)) {
sub.setMovieFPS(String.valueOf(mi.getFrameRate()));
sub.setMovieTimeMS(String.valueOf(mi.getDuration().toMillis()));
} catch (Throwable e) {
debug.log(Level.SEVERE, "Failed to read media info", e);
}
}
return sub;
}