1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00

* easy access to the structure relative path, might be useful for scripting latter to exclude home folders and the likes from any kind of checking

This commit is contained in:
Reinhard Pointner 2014-05-11 07:37:02 +00:00
parent 06a47a3375
commit 0438e4756f
2 changed files with 19 additions and 0 deletions

View File

@ -330,6 +330,10 @@ public class ScriptShellMethods {
return JsonReader.jsonToJava(self);
}
public static File getStructurePathTail(File self) throws IOException {
return MediaDetection.getStructurePathTail(self);
}
public static FolderWatchService watch(File self, final Closure<?> callback) throws IOException {
FolderWatchService watchService = new FolderWatchService(true) {

View File

@ -57,6 +57,7 @@ import net.filebot.similarity.SeriesNameMatcher;
import net.filebot.similarity.SimilarityComparator;
import net.filebot.similarity.SimilarityMetric;
import net.filebot.similarity.StringEqualsMetric;
import net.filebot.util.StringUtilities;
import net.filebot.vfs.FileInfo;
import net.filebot.web.Episode;
import net.filebot.web.Movie;
@ -999,6 +1000,20 @@ public class MediaDetection {
return releaseInfo.getStructureRootPattern().matcher(folder.getName()).matches();
}
public static File getStructurePathTail(File file) throws IOException {
LinkedList<String> relativePath = new LinkedList<String>();
// iterate path in reverse
for (File it : listPathTail(file, Integer.MAX_VALUE, true)) {
if (isStructureRoot(it))
break;
relativePath.addFirst(it.getName());
}
return relativePath.isEmpty() ? null : new File(StringUtilities.join(relativePath, File.separator));
}
public static Map<File, List<File>> mapByMediaFolder(Collection<File> files) {
Map<File, List<File>> mediaFolders = new HashMap<File, List<File>>();
for (File f : files) {