mirror of
https://github.com/mitb-archive/filebot
synced 2024-12-25 09:18:51 -05:00
* add structure root logic for the different filesystem layouts of different OSes
This commit is contained in:
parent
27f272077d
commit
1c89f8c3ef
@ -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();
|
||||
}
|
||||
|
||||
|
@ -167,8 +167,37 @@ public class ReleaseInfo {
|
||||
}
|
||||
|
||||
// cached patterns
|
||||
private Set<File> volumeRoots;
|
||||
private Pattern structureRootFolderPattern;
|
||||
|
||||
public Set<File> getVolumeRoots() {
|
||||
if (volumeRoots == null) {
|
||||
Set<File> volumes = new HashSet<File>();
|
||||
|
||||
// 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<String> folders = new ArrayList<String>();
|
||||
|
Loading…
Reference in New Issue
Block a user