From 327f71ce5bf9ffecdc56abb561a7db305f320f1e Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 23 Feb 2012 19:53:04 +0000 Subject: [PATCH] * run full series matching on all files only if folders can't be matched --- .../filebot/media/MediaDetection.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/source/net/sourceforge/filebot/media/MediaDetection.java b/source/net/sourceforge/filebot/media/MediaDetection.java index 3dfd8b06..12fac104 100644 --- a/source/net/sourceforge/filebot/media/MediaDetection.java +++ b/source/net/sourceforge/filebot/media/MediaDetection.java @@ -134,12 +134,11 @@ public class MediaDetection { public static List detectSeriesNames(Collection files, Locale locale) throws Exception { - // don't allow duplicates - Map names = new LinkedHashMap(); + List names = new ArrayList(); try { for (SearchResult it : lookupSeriesNameByInfoFile(files, locale)) { - names.put(it.getName().toLowerCase(), it.getName()); + names.add(it.getName()); } } catch (Exception e) { Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to lookup info by id: " + e.getMessage(), e); @@ -147,17 +146,23 @@ public class MediaDetection { // cross-reference known series names against file structure try { + Set folders = new LinkedHashSet(); Set filenames = new LinkedHashSet(); for (File f : files) { for (int i = 0; i < 3 && f != null; i++, f = f.getParentFile()) { - filenames.add(f.getName()); + (i == 0 ? filenames : folders).add(f.getName()); } } - // match folder names against known series names - for (String match : matchSeriesByName(filenames.toArray(new String[0]))) { - names.put(match.toLowerCase(), match); + // check foldernames first + List matches = matchSeriesByName(folders); + + // check all filenames if necessary + if (matches.isEmpty()) { + matches = matchSeriesByName(filenames); } + + names.addAll(matches); } catch (Exception e) { Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to match folder structure: " + e.getMessage(), e); } @@ -169,15 +174,18 @@ public class MediaDetection { } catch (Exception e) { Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to clean matches: " + e.getMessage(), e); } - for (String it : matches) { - names.put(it.toLowerCase(), it); - } + names.addAll(matches); - return new ArrayList(names.values()); + // don't allow duplicates + Map unique = new LinkedHashMap(); + for (String it : matches) { + unique.put(it.toLowerCase(), it); + } + return new ArrayList(unique.values()); } - public static List matchSeriesByName(String... names) throws Exception { + public static List matchSeriesByName(Collection names) throws Exception { HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(0); List matches = new ArrayList();