From f737e7c5fb071d9e4026668a15e558eae494de5a Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 1 Aug 2009 18:02:09 +0000 Subject: [PATCH] * look for sfv files up to 3 levels up the directory tree --- .../filebot/format/EpisodeBindingBean.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/source/net/sourceforge/filebot/format/EpisodeBindingBean.java b/source/net/sourceforge/filebot/format/EpisodeBindingBean.java index bdc8863e..b74a0a11 100644 --- a/source/net/sourceforge/filebot/format/EpisodeBindingBean.java +++ b/source/net/sourceforge/filebot/format/EpisodeBindingBean.java @@ -132,7 +132,7 @@ public class EpisodeBindingBean { return checksum; // try to get checksum from sfv file - checksum = getChecksumFromSfvFile(inferredMediaFile); + checksum = getChecksumFromSfvFile(inferredMediaFile.getParentFile(), inferredMediaFile, 0, 3); if (checksum != null) return checksum; @@ -247,9 +247,12 @@ public class EpisodeBindingBean { } - private String getChecksumFromSfvFile(File file) throws IOException { - File folder = file.getParentFile(); + private String getChecksumFromSfvFile(File folder, File target, int depth, int maxDepth) throws IOException { + // stop if we reached max depth or the file system root + if (folder == null || depth > maxDepth) + return null; + // scan all sfv files in this folder for (File sfvFile : folder.listFiles(MediaTypes.getFilter("verification/sfv"))) { VerificationFileScanner scanner = new VerificationFileScanner(sfvFile, new SfvFormat()); @@ -257,7 +260,10 @@ public class EpisodeBindingBean { while (scanner.hasNext()) { Entry entry = scanner.next(); - if (file.getName().equals(entry.getKey().getPath())) { + // resolve relative file path + File file = new File(folder, entry.getKey().getPath()); + + if (target.equals(file)) { return entry.getValue(); } } @@ -266,7 +272,7 @@ public class EpisodeBindingBean { } } - return null; + return getChecksumFromSfvFile(folder.getParentFile(), target, depth + 1, maxDepth); }