1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

Refactor SubtitleMetrics

This commit is contained in:
Reinhard Pointner 2016-08-10 03:42:32 +08:00
parent 53226d0809
commit 9dd4a82e04

View File

@ -161,18 +161,20 @@ public enum SubtitleMetrics implements SimilarityMetric {
return emptyMap(); return emptyMap();
}; };
private Map<String, Object> getProperties(float fps, long millis) {
Map<String, Object> props = new HashMap<String, Object>(2);
if (fps > 0) {
props.put(FPS, Math.round(fps)); // round because most FPS values in the database are bad anyway
}
if (millis > 0) {
props.put(SECONDS, Math.round(Math.floor(millis / 1000d)));
}
return props;
}
private Map<String, Object> getSubtitleProperties(OpenSubtitlesSubtitleDescriptor subtitle) { private Map<String, Object> getSubtitleProperties(OpenSubtitlesSubtitleDescriptor subtitle) {
try { try {
Map<String, Object> props = new HashMap<String, Object>(2); return getProperties(subtitle.getMovieFPS(), subtitle.getMovieTimeMS());
float fps = Math.round(subtitle.getMovieFPS()); // round because most FPS values in the database are bad anyway
if (fps > 0) {
props.put(FPS, fps);
}
long seconds = (long) Math.floor(subtitle.getMovieTimeMS() / (double) 1000);
if (seconds > 0) {
props.put(SECONDS, seconds);
}
return props;
} catch (Exception e) { } catch (Exception e) {
debug.warning("Failed to read subtitle properties: " + e); debug.warning("Failed to read subtitle properties: " + e);
} }
@ -183,17 +185,10 @@ public enum SubtitleMetrics implements SimilarityMetric {
private Map<String, Object> getVideoProperties(File file) { private Map<String, Object> getVideoProperties(File file) {
return mediaInfoCache.computeIfAbsent(file, key -> { return mediaInfoCache.computeIfAbsent(file, key -> {
try (MediaInfo mediaInfo = new MediaInfo().open(file)) { try (MediaInfo mi = new MediaInfo().open(file)) {
Map<String, Object> props = new HashMap<String, Object>(2); float fps = Float.parseFloat(mi.get(StreamKind.Video, 0, "FrameRate"));
float fps = Math.round(Float.parseFloat(mediaInfo.get(StreamKind.Video, 0, "FrameRate"))); long millis = Long.parseLong(mi.get(StreamKind.Video, 0, "Duration"));
if (fps > 0) { return getProperties(fps, millis);
props.put(FPS, fps);
}
long seconds = (long) Math.floor(Long.parseLong(mediaInfo.get(StreamKind.Video, 0, "Duration")) / (double) 1000);
if (seconds > 0) {
props.put(SECONDS, seconds);
}
return props;
} catch (Exception e) { } catch (Exception e) {
debug.warning("Failed to read video properties: " + e.getMessage()); debug.warning("Failed to read video properties: " + e.getMessage());
} }