diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index b97d1f80..070494ae 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -685,17 +685,6 @@ public class MediaDetection { } public static File guessMovieFolder(File movieFile) throws Exception { - File folder = guessMovieFolderWithoutSanity(movieFile); - - // perform sanity checks - if (folder == null || folder.getName().isEmpty() || folder.equals(new File(System.getProperty("user.home")))) { - return null; - } - - return folder; - } - - private static File guessMovieFolderWithoutSanity(File movieFile) throws Exception { // special case for folder mode if (movieFile.isDirectory()) { File f = movieFile; @@ -704,7 +693,7 @@ public class MediaDetection { if (!isStructureRoot(f.getParentFile()) && checkMovie(f.getParentFile(), false) != null && checkMovie(f, false) == null) { return f.getParentFile(); } else { - return f; + return isStructureRoot(f) ? null : f; } } @@ -887,6 +876,10 @@ public class MediaDetection { } public static boolean isStructureRoot(File folder) throws IOException { + if (folder.getName().isEmpty() || releaseInfo.getVolumeRoots().contains(folder)) { + return true; + } + return releaseInfo.getStructureRootPattern().matcher(folder.getName()).matches(); } diff --git a/source/net/sourceforge/filebot/media/ReleaseInfo.java b/source/net/sourceforge/filebot/media/ReleaseInfo.java index e5a3ec9f..f4c8d33b 100644 --- a/source/net/sourceforge/filebot/media/ReleaseInfo.java +++ b/source/net/sourceforge/filebot/media/ReleaseInfo.java @@ -167,8 +167,37 @@ public class ReleaseInfo { } // cached patterns + private Set volumeRoots; private Pattern structureRootFolderPattern; + public Set getVolumeRoots() { + if (volumeRoots == null) { + Set volumes = new HashSet(); + + // user root folder + volumes.add(new File(System.getProperty("user.home"))); + + // Windows / Linux / Mac system roots + addAll(volumes, File.listRoots()); + + // media root folders + if (File.separator.equals("/")) { + // Linux and Mac + for (File root : File.listRoots()) { + addAll(volumes, root.listFiles(FOLDERS)); + } + for (String path : asList("/Volumes", "/home", "/media", "/mnt")) { + File root = new File(path); + if (root.isDirectory()) { + addAll(volumes, root.listFiles(FOLDERS)); + } + } + } + volumeRoots = volumes; + } + return volumeRoots; + } + public Pattern getStructureRootPattern() throws IOException { if (structureRootFolderPattern == null) { List folders = new ArrayList();