1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-04 08:25:03 -05:00

* run full series matching on all files only if folders can't be matched

This commit is contained in:
Reinhard Pointner 2012-02-23 19:53:04 +00:00
parent 806ffdc91d
commit 327f71ce5b

View File

@ -134,12 +134,11 @@ public class MediaDetection {
public static List<String> detectSeriesNames(Collection<File> files, Locale locale) throws Exception { public static List<String> detectSeriesNames(Collection<File> files, Locale locale) throws Exception {
// don't allow duplicates List<String> names = new ArrayList<String>();
Map<String, String> names = new LinkedHashMap<String, String>();
try { try {
for (SearchResult it : lookupSeriesNameByInfoFile(files, locale)) { for (SearchResult it : lookupSeriesNameByInfoFile(files, locale)) {
names.put(it.getName().toLowerCase(), it.getName()); names.add(it.getName());
} }
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to lookup info by id: " + e.getMessage(), 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 // cross-reference known series names against file structure
try { try {
Set<String> folders = new LinkedHashSet<String>();
Set<String> filenames = new LinkedHashSet<String>(); Set<String> filenames = new LinkedHashSet<String>();
for (File f : files) { for (File f : files) {
for (int i = 0; i < 3 && f != null; i++, f = f.getParentFile()) { 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 // check foldernames first
for (String match : matchSeriesByName(filenames.toArray(new String[0]))) { List<String> matches = matchSeriesByName(folders);
names.put(match.toLowerCase(), match);
// check all filenames if necessary
if (matches.isEmpty()) {
matches = matchSeriesByName(filenames);
} }
names.addAll(matches);
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to match folder structure: " + e.getMessage(), 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) { } catch (Exception e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to clean matches: " + e.getMessage(), e); Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to clean matches: " + e.getMessage(), e);
} }
for (String it : matches) { names.addAll(matches);
names.put(it.toLowerCase(), it);
}
return new ArrayList<String>(names.values()); // don't allow duplicates
Map<String, String> unique = new LinkedHashMap<String, String>();
for (String it : matches) {
unique.put(it.toLowerCase(), it);
}
return new ArrayList<String>(unique.values());
} }
public static List<String> matchSeriesByName(String... names) throws Exception { public static List<String> matchSeriesByName(Collection<String> names) throws Exception {
HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(0); HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(0);
List<String> matches = new ArrayList<String>(); List<String> matches = new ArrayList<String>();