From 0438e4756f20424029e3fed16dea25af90550f57 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 11 May 2014 07:37:02 +0000 Subject: [PATCH] * 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 --- source/net/filebot/cli/ScriptShellMethods.java | 4 ++++ source/net/filebot/media/MediaDetection.java | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/source/net/filebot/cli/ScriptShellMethods.java b/source/net/filebot/cli/ScriptShellMethods.java index 32394812..8d32416e 100644 --- a/source/net/filebot/cli/ScriptShellMethods.java +++ b/source/net/filebot/cli/ScriptShellMethods.java @@ -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) { diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index a3d2d620..2c830603 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -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 relativePath = new LinkedList(); + + // 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> mapByMediaFolder(Collection files) { Map> mediaFolders = new HashMap>(); for (File f : files) {