From 76bb88042afcd1e7b594c76d94ed94695087dfa1 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 8 Aug 2016 07:46:04 +0800 Subject: [PATCH] Implement advanced multi-part movie detection (via group by mediainfo) --- .../net/filebot/format/MediaBindingBean.java | 5 ----- source/net/filebot/media/MediaDetection.java | 22 ++++++++++--------- source/net/filebot/media/VideoQuality.java | 6 ----- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/source/net/filebot/format/MediaBindingBean.java b/source/net/filebot/format/MediaBindingBean.java index 055a44b1..7bf4b880 100644 --- a/source/net/filebot/format/MediaBindingBean.java +++ b/source/net/filebot/format/MediaBindingBean.java @@ -770,11 +770,6 @@ public class MediaBindingBean { return (int) (getDuration() / 60000); } - @Define("encodedDate") - public String getEncodedDate() { - return getMediaInfo(StreamKind.General, 0, "Encoded_Date"); // e.g. UTC 2014-07-18 13:57:37 - } - @Define("media") public AssociativeScriptObject getGeneralMediaInfo() { return createMediaInfoBindings(StreamKind.General).get(0); diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index 567459b3..5b01fca4 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -46,6 +46,8 @@ import net.filebot.ApplicationFolder; import net.filebot.Resource; import net.filebot.WebServices; import net.filebot.archive.Archive; +import net.filebot.mediainfo.MediaInfo; +import net.filebot.mediainfo.MediaInfo.StreamKind; import net.filebot.similarity.CommonSequenceMatcher; import net.filebot.similarity.DateMatcher; import net.filebot.similarity.EpisodeMetrics; @@ -1082,16 +1084,16 @@ public class MediaDetection { return; } - try { - filesByMediaFolder.stream().collect(groupingBy(new VideoQuality()::getEncodedDate)).forEach((group, videos) -> { - groups.add(videos); - }); - } catch (Exception e) { - debug.warning(format("Failed to group by media characteristics: %s", e.getMessage())); - - // if mediainfo fails and we can't further group by video bitrate then just keep the grouping we have - groups.add(filesByMediaFolder); - } + filesByMediaFolder.stream().collect(groupingBy(f -> { + if (VIDEO_FILES.accept(f)) { + try (MediaInfo mi = new MediaInfo().open(f)) { + return mi.get(StreamKind.General, 0, "Encoded_Date"); + } catch (Exception e) { + debug.warning(format("Failed to read media characteristics: %s", e.getMessage())); + } + } + return ""; + })).forEach((group, videos) -> groups.add(videos)); }); }); diff --git a/source/net/filebot/media/VideoQuality.java b/source/net/filebot/media/VideoQuality.java index 16da933c..12c1061a 100644 --- a/source/net/filebot/media/VideoQuality.java +++ b/source/net/filebot/media/VideoQuality.java @@ -64,10 +64,4 @@ public class VideoQuality implements Comparator { }).orElseGet(f::length); } - public String getEncodedDate(File f) { - return media(f).map(it -> { - return it.getEncodedDate(); - }).orElse(null); - } - }