From 8ae4bed832ad3d46b78d706b8fc2897c5683b41e Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 14 Apr 2016 09:31:57 +0000 Subject: [PATCH] Improved auto-detection --- source/net/filebot/media/AutoDetection.java | 20 +++++++++++-- source/net/filebot/media/MediaDetection.java | 31 +++++++++++++------- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/source/net/filebot/media/AutoDetection.java b/source/net/filebot/media/AutoDetection.java index 3cc7e661..310b1d67 100644 --- a/source/net/filebot/media/AutoDetection.java +++ b/source/net/filebot/media/AutoDetection.java @@ -10,6 +10,7 @@ import static net.filebot.Settings.*; import static net.filebot.WebServices.*; import static net.filebot.format.ExpressionFormatMethods.*; import static net.filebot.media.MediaDetection.*; +import static net.filebot.media.XattrMetaInfo.*; import static net.filebot.similarity.Normalization.*; import static net.filebot.util.FileUtilities.*; import static net.filebot.util.StringUtilities.*; @@ -38,6 +39,7 @@ import net.filebot.mediainfo.MediaInfo; import net.filebot.mediainfo.MediaInfo.StreamKind; import net.filebot.similarity.NameSimilarityMetric; import net.filebot.util.FastFile; +import net.filebot.web.Episode; import net.filebot.web.Movie; public class AutoDetection { @@ -85,19 +87,29 @@ public class AutoDetection { } public boolean isEpisode(File f) { - return MediaDetection.isEpisode(f.getName(), false) && (anyMatch(f.getParentFile(), SERIES_PATTERN) || find(f.getName(), SERIES_EPISODE_PATTERN) || MediaDetection.isEpisode(f, true)); + if (MediaDetection.isEpisode(f.getName(), false) && (anyMatch(f.getParentFile(), SERIES_PATTERN) || find(f.getName(), SERIES_EPISODE_PATTERN))) { + return true; + } + + if (MediaDetection.isEpisode(f.getPath(), true)) { + return true; + } + + Object metaInfo = xattr.getMetaInfo(f); + return metaInfo instanceof Episode && !AniDB.getIdentifier().equals(((Episode) metaInfo).getSeriesInfo().getDatabase()); } public boolean isAnime(File f) { if (MediaDetection.parseEpisodeNumber(f.getName(), false) == null) { return false; } + if (anyMatch(f.getParentFile(), ANIME_PATTERN) || find(f.getName(), ANIME_EPISODE_PATTERN) || find(f.getName(), EMBEDDED_CHECKSUM)) { return true; } - // check for Japanese audio or characteristic subtitles if (VIDEO_FILES.accept(f)) { + // check for Japanese audio or characteristic subtitles try (MediaInfo mi = new MediaInfo().open(f)) { long minutes = Duration.ofMillis(Long.parseLong(mi.get(StreamKind.General, 0, "Duration"))).toMinutes(); return minutes < 60 || mi.get(StreamKind.General, 0, "AudioLanguageList").contains("Japanese") && mi.get(StreamKind.General, 0, "TextCodecList").contains("ASS"); @@ -105,7 +117,9 @@ public class AutoDetection { debug.warning("Failed to read audio language: " + e.getMessage()); } } - return false; + + Object metaInfo = xattr.getMetaInfo(f); + return metaInfo instanceof Episode && AniDB.getIdentifier().equals(((Episode) metaInfo).getSeriesInfo().getDatabase()); } public boolean anyMatch(File file, Pattern pattern) { diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index 0133fc53..352bef4f 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -120,21 +120,27 @@ public class MediaDetection { } public static boolean isEpisode(File file, boolean strict) { - if (xattr.getMetaInfo(file) instanceof Episode) - return true; + Object metaInfo = xattr.getMetaInfo(file); + if (metaInfo != null) { + return metaInfo instanceof Episode; + } return MediaDetection.isEpisode(String.join("/", file.getParent(), file.getName()), strict); } public static boolean isMovie(File file, boolean strict) { - if (xattr.getMetaInfo(file) instanceof Movie) - return true; + Object metaInfo = xattr.getMetaInfo(file); + if (metaInfo != null) { + return metaInfo instanceof Movie; + } - if (isEpisode(file, strict)) + if (isEpisode(file, strict)) { return false; + } - if (matchMovieName(asList(file.getName(), file.getParent()), strict, 0).size() > 0) + if (matchMovieName(asList(file.getName(), file.getParent()), strict, 0).size() > 0) { return true; + } // check for valid imdb id patterns return grepImdbId(file.getPath()).stream().map(Movie::new).filter(m -> { @@ -1003,18 +1009,21 @@ public class MediaDetection { return null; } - public static File getStructurePathTail(File file) throws Exception { + public static List listStructurePathTail(File file) throws Exception { LinkedList relativePath = new LinkedList(); - - // iterate path in reverse - for (File it : listPathTail(file, Integer.MAX_VALUE, true)) { + for (File it : listPathTail(file, FILE_WALK_MAX_DEPTH, true)) { if (isStructureRoot(it)) break; + // iterate path in reverse relativePath.addFirst(it.getName()); } + return relativePath; + } - return relativePath.isEmpty() ? null : new File(join(relativePath, File.separator)); + public static File getStructurePathTail(File file) throws Exception { + List relativePath = listStructurePathTail(file); + return relativePath.isEmpty() ? null : new File(String.join(File.separator, relativePath)); } public static Map> mapByMediaFolder(Collection files) {