mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-11 14:59:44 -04:00
Accept small files (useful for automated image processing)
This commit is contained in:
parent
04b3110d71
commit
404ea2714a
@ -118,7 +118,7 @@ public class AutoDetection {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) {
|
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(f)) {
|
||||||
// check for Japanese audio or characteristic subtitles
|
// check for Japanese audio or characteristic subtitles
|
||||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
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);
|
return mi.getDuration().toMinutes() < 60 || find(mi.getAudioLanguage(), JAPANESE_AUDIO_LANGUAGE_PATTERN) && find(mi.getSubtitleCodec(), JAPANESE_SUBTITLE_CODEC_PATTERN);
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package net.filebot.media;
|
package net.filebot.media;
|
||||||
|
|
||||||
|
import static net.filebot.MediaTypes.*;
|
||||||
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
import net.filebot.mediainfo.MediaInfo;
|
import net.filebot.mediainfo.MediaInfo;
|
||||||
@ -25,6 +28,10 @@ public enum MediaCharacteristicsParser {
|
|||||||
|
|
||||||
public abstract MediaCharacteristics open(File f) throws Exception;
|
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() {
|
public static MediaCharacteristicsParser getDefault() {
|
||||||
return DEFAULT;
|
return DEFAULT;
|
||||||
}
|
}
|
||||||
|
@ -1113,7 +1113,7 @@ public class MediaDetection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
filesByExtension.stream().collect(groupingBy(f -> {
|
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)) {
|
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
||||||
ChronoUnit d = mi.getDuration().toMinutes() < 10 ? ChronoUnit.MINUTES : ChronoUnit.HOURS;
|
ChronoUnit d = mi.getDuration().toMinutes() < 10 ? ChronoUnit.MINUTES : ChronoUnit.HOURS;
|
||||||
String v = mi.getVideoCodec();
|
String v = mi.getVideoCodec();
|
||||||
|
@ -2,9 +2,7 @@ package net.filebot.media;
|
|||||||
|
|
||||||
import static java.util.Comparator.*;
|
import static java.util.Comparator.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.MediaTypes.*;
|
|
||||||
import static net.filebot.media.MediaDetection.*;
|
import static net.filebot.media.MediaDetection.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
|
||||||
import static net.filebot.util.StringUtilities.*;
|
import static net.filebot.util.StringUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
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
|
// use primary video file when checking video resolution of subtitle files or disk folders
|
||||||
f = new MediaBindingBean(f, f).getInferredMediaFile();
|
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)) {
|
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
||||||
return mi.getWidth() * mi.getHeight() * mi.getBitRate();
|
return mi.getWidth() * mi.getHeight() * mi.getBitRate();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -614,7 +614,7 @@ public class EpisodeMetrics {
|
|||||||
|
|
||||||
private long getTimeStamp(File file) {
|
private long getTimeStamp(File file) {
|
||||||
return cache.computeIfAbsent(file, f -> {
|
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)) {
|
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(file)) {
|
||||||
Instant t = mi.getCreationTime();
|
Instant t = mi.getCreationTime();
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
|
@ -203,11 +203,13 @@ public class SubtitleMetrics extends EpisodeMetrics {
|
|||||||
|
|
||||||
private Map<String, Object> getVideoProperties(File file) {
|
private Map<String, Object> getVideoProperties(File file) {
|
||||||
return cache.computeIfAbsent(file, f -> {
|
return cache.computeIfAbsent(file, f -> {
|
||||||
|
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(f)) {
|
||||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
||||||
return getProperties(mi.getFrameRate(), mi.getDuration().toMillis());
|
return getProperties(mi.getFrameRate(), mi.getDuration().toMillis());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
debug.warning(cause("Failed to read video properties", e));
|
debug.warning(cause("Failed to read video properties", e));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return emptyMap();
|
return emptyMap();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -59,18 +59,21 @@ class MediaInfoTool extends Tool<TableModel> {
|
|||||||
return new MediaInfoTableModel();
|
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[]>();
|
Map<MediaInfoKey, String[]> data = new TreeMap<MediaInfoKey, String[]>();
|
||||||
|
|
||||||
try (MediaInfo mi = new MediaInfo()) {
|
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 {
|
try {
|
||||||
mi.open(files.get(f));
|
mi.open(f);
|
||||||
mi.snapshot().forEach((kind, streams) -> {
|
mi.snapshot().forEach((kind, streams) -> {
|
||||||
IntStream.range(0, streams.size()).forEach(i -> {
|
IntStream.range(0, streams.size()).forEach(streamIndex -> {
|
||||||
streams.get(i).forEach((name, value) -> {
|
streams.get(streamIndex).forEach((name, value) -> {
|
||||||
String[] values = data.computeIfAbsent(new MediaInfoKey(kind, i, name), k -> new String[files.size()]);
|
String[] values = data.computeIfAbsent(new MediaInfoKey(kind, streamIndex, name), k -> new String[files.size()]);
|
||||||
values[f] = value;
|
values[fileIndex] = value;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -79,6 +82,7 @@ class MediaInfoTool extends Tool<TableModel> {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
debug.warning(e::toString);
|
debug.warning(e::toString);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (Thread.interrupted()) {
|
if (Thread.interrupted()) {
|
||||||
throw new CancellationException();
|
throw new CancellationException();
|
||||||
|
@ -312,12 +312,14 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||||||
sub.setSubContent(readFile(subtitleFile));
|
sub.setSubContent(readFile(subtitleFile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (MediaCharacteristicsParser.DEFAULT.acceptVideoFile(videoFile)) {
|
||||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(videoFile)) {
|
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(videoFile)) {
|
||||||
sub.setMovieFPS(String.valueOf(mi.getFrameRate()));
|
sub.setMovieFPS(String.valueOf(mi.getFrameRate()));
|
||||||
sub.setMovieTimeMS(String.valueOf(mi.getDuration().toMillis()));
|
sub.setMovieTimeMS(String.valueOf(mi.getDuration().toMillis()));
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
debug.log(Level.SEVERE, "Failed to read media info", e);
|
debug.log(Level.SEVERE, "Failed to read media info", e);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return sub;
|
return sub;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user