Refactor SubtitleMetrics
This commit is contained in:
parent
53226d0809
commit
9dd4a82e04
|
@ -161,18 +161,20 @@ public enum SubtitleMetrics implements SimilarityMetric {
|
||||||
return emptyMap();
|
return emptyMap();
|
||||||
};
|
};
|
||||||
|
|
||||||
private Map<String, Object> getSubtitleProperties(OpenSubtitlesSubtitleDescriptor subtitle) {
|
private Map<String, Object> getProperties(float fps, long millis) {
|
||||||
try {
|
|
||||||
Map<String, Object> props = new HashMap<String, Object>(2);
|
Map<String, Object> props = new HashMap<String, Object>(2);
|
||||||
float fps = Math.round(subtitle.getMovieFPS()); // round because most FPS values in the database are bad anyway
|
|
||||||
if (fps > 0) {
|
if (fps > 0) {
|
||||||
props.put(FPS, fps);
|
props.put(FPS, Math.round(fps)); // round because most FPS values in the database are bad anyway
|
||||||
}
|
}
|
||||||
long seconds = (long) Math.floor(subtitle.getMovieTimeMS() / (double) 1000);
|
if (millis > 0) {
|
||||||
if (seconds > 0) {
|
props.put(SECONDS, Math.round(Math.floor(millis / 1000d)));
|
||||||
props.put(SECONDS, seconds);
|
|
||||||
}
|
}
|
||||||
return props;
|
return props;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> getSubtitleProperties(OpenSubtitlesSubtitleDescriptor subtitle) {
|
||||||
|
try {
|
||||||
|
return getProperties(subtitle.getMovieFPS(), subtitle.getMovieTimeMS());
|
||||||
} 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());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue