diff --git a/source/net/filebot/subtitle/SubtitleMetrics.java b/source/net/filebot/subtitle/SubtitleMetrics.java index c21a14d8..fb7e81ab 100644 --- a/source/net/filebot/subtitle/SubtitleMetrics.java +++ b/source/net/filebot/subtitle/SubtitleMetrics.java @@ -161,18 +161,20 @@ public enum SubtitleMetrics implements SimilarityMetric { return emptyMap(); }; + private Map getProperties(float fps, long millis) { + Map props = new HashMap(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 getSubtitleProperties(OpenSubtitlesSubtitleDescriptor subtitle) { try { - Map props = new HashMap(2); - 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; + return getProperties(subtitle.getMovieFPS(), subtitle.getMovieTimeMS()); } catch (Exception e) { debug.warning("Failed to read subtitle properties: " + e); } @@ -183,17 +185,10 @@ public enum SubtitleMetrics implements SimilarityMetric { private Map getVideoProperties(File file) { return mediaInfoCache.computeIfAbsent(file, key -> { - try (MediaInfo mediaInfo = new MediaInfo().open(file)) { - Map props = new HashMap(2); - float fps = Math.round(Float.parseFloat(mediaInfo.get(StreamKind.Video, 0, "FrameRate"))); - if (fps > 0) { - 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; + try (MediaInfo mi = new MediaInfo().open(file)) { + float fps = Float.parseFloat(mi.get(StreamKind.Video, 0, "FrameRate")); + long millis = Long.parseLong(mi.get(StreamKind.Video, 0, "Duration")); + return getProperties(fps, millis); } catch (Exception e) { debug.warning("Failed to read video properties: " + e.getMessage()); }