mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-10 19:35:15 -05:00
Refactor MediaCharacteristics so we can switch between implementations easily
This commit is contained in:
parent
e4abc0afb4
commit
51072a2c40
@ -118,7 +118,7 @@ public class AutoDetection {
|
||||
|
||||
if (VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) {
|
||||
// check for Japanese audio or characteristic subtitles
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.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);
|
||||
} catch (Exception e) {
|
||||
debug.warning("Failed to read audio language: " + e.getMessage());
|
||||
|
@ -7,21 +7,24 @@ import net.filebot.util.SystemProperty;
|
||||
|
||||
public enum MediaCharacteristicsParser {
|
||||
|
||||
libmediainfo, ffprobe;
|
||||
libmediainfo {
|
||||
|
||||
public static MediaCharacteristicsParser getDefault() {
|
||||
return SystemProperty.of("net.filebot.media.parser", MediaCharacteristicsParser::valueOf, libmediainfo).get();
|
||||
}
|
||||
|
||||
public static MediaCharacteristics open(File f) throws Exception {
|
||||
switch (getDefault()) {
|
||||
case libmediainfo:
|
||||
@Override
|
||||
public MediaCharacteristics open(File f) throws Exception {
|
||||
return new MediaInfo().open(f);
|
||||
case ffprobe:
|
||||
}
|
||||
},
|
||||
|
||||
ffprobe {
|
||||
|
||||
@Override
|
||||
public MediaCharacteristics open(File f) throws Exception {
|
||||
return new FFProbe().open(f);
|
||||
}
|
||||
};
|
||||
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
public abstract MediaCharacteristics open(File f) throws Exception;
|
||||
|
||||
public static final MediaCharacteristicsParser DEFAULT = SystemProperty.of("net.filebot.media.parser", MediaCharacteristicsParser::valueOf, libmediainfo).get();
|
||||
|
||||
}
|
@ -1114,7 +1114,7 @@ public class MediaDetection {
|
||||
|
||||
filesByExtension.stream().collect(groupingBy(f -> {
|
||||
if (VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.open(f)) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
||||
ChronoUnit d = mi.getDuration().toMinutes() < 10 ? ChronoUnit.MINUTES : ChronoUnit.HOURS;
|
||||
String v = mi.getVideoCodec();
|
||||
String a = mi.getAudioCodec();
|
||||
|
@ -22,7 +22,7 @@ public class MediaDurationFilter implements FileFilter {
|
||||
}
|
||||
|
||||
public long getDuration(File f) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.open(f)) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
||||
return mi.getDuration().toMillis();
|
||||
} catch (Exception e) {
|
||||
debug.warning(format("Failed to read video duration: %s", e.getMessage()));
|
||||
|
@ -40,7 +40,7 @@ public class VideoQuality implements Comparator<File> {
|
||||
f = new MediaBindingBean(f, f).getInferredMediaFile();
|
||||
|
||||
if (VIDEO_FILES.accept(f) && f.length() > ONE_MEGABYTE) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.open(f)) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
||||
return mi.getWidth() * mi.getHeight();
|
||||
} catch (Exception e) {
|
||||
debug.warning("Failed to read video resolution: " + e.getMessage());
|
||||
|
@ -538,7 +538,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
|
||||
|
||||
private long getTimeStamp(File file) {
|
||||
if (VIDEO_FILES.accept(file) && file.length() > ONE_MEGABYTE) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.open(file)) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(file)) {
|
||||
Instant t = mi.getCreationTime();
|
||||
if (t != null) {
|
||||
return t.toEpochMilli();
|
||||
|
@ -185,7 +185,7 @@ public enum SubtitleMetrics implements SimilarityMetric {
|
||||
|
||||
private Map<String, Object> getVideoProperties(File file) {
|
||||
return mediaInfoCache.computeIfAbsent(file, f -> {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.open(f)) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(f)) {
|
||||
return getProperties(mi.getFrameRate(), mi.getDuration().toMillis());
|
||||
} catch (Exception e) {
|
||||
debug.warning("Failed to read video properties: " + e.getMessage());
|
||||
|
@ -312,7 +312,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
||||
sub.setSubContent(readFile(subtitleFile));
|
||||
}
|
||||
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.open(videoFile)) {
|
||||
try (MediaCharacteristics mi = MediaCharacteristicsParser.DEFAULT.open(videoFile)) {
|
||||
sub.setMovieFPS(String.valueOf(mi.getFrameRate()));
|
||||
sub.setMovieTimeMS(String.valueOf(mi.getDuration().toMillis()));
|
||||
} catch (Throwable e) {
|
||||
|
Loading…
Reference in New Issue
Block a user