1
0
mirror of https://github.com/mitb-archive/filebot synced 2025-03-10 06:20:27 -04:00

Prefer exact series name as query if known. Otherwise perform the usual query normalization.

This commit is contained in:
Reinhard Pointner 2016-02-22 06:24:12 +00:00
parent 290d9363aa
commit 331b271d2b

View File

@ -297,25 +297,26 @@ public class MediaDetection {
} }
public static List<String> detectSeriesNames(Collection<File> files, List<IndexEntry<SearchResult>> index, Locale locale) throws Exception { public static List<String> detectSeriesNames(Collection<File> files, List<IndexEntry<SearchResult>> index, Locale locale) throws Exception {
List<String> names = new ArrayList<String>(); // known series names
List<String> unids = new ArrayList<String>();
// try xattr metadata if enabled // try xattr metadata if enabled
for (File it : files) { for (File it : files) {
Object metaObject = readMetaInfo(it); Object metaObject = readMetaInfo(it);
if (metaObject instanceof Episode) { if (metaObject instanceof Episode) {
names.add(((Episode) metaObject).getSeriesName()); unids.add(((Episode) metaObject).getSeriesName());
} }
} }
// completely trust xattr metadata if all files are tagged // completely trust xattr metadata if all files are tagged
if (names.size() == files.size()) { if (unids.size() == files.size()) {
return getUniqueQuerySet(names); return getUniqueQuerySet(unids, emptySet());
} }
// try to detect series name via nfo files // try to detect series name via nfo files
try { try {
for (SearchResult it : lookupSeriesNameByInfoFile(files, locale)) { for (SearchResult it : lookupSeriesNameByInfoFile(files, locale)) {
names.add(it.getName()); unids.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); Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to lookup info by id: " + e);
@ -323,11 +324,14 @@ public class MediaDetection {
// try to detect series name via known patterns // try to detect series name via known patterns
try { try {
names.addAll(matchSeriesByDirectMapping(files)); unids.addAll(matchSeriesByDirectMapping(files));
} catch (Exception e) { } catch (Exception e) {
Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to match direct mappings: " + e); Logger.getLogger(MediaDetection.class.getClass().getName()).log(Level.WARNING, "Failed to match direct mappings: " + e);
} }
// guessed queries
List<String> names = new ArrayList<String>();
// strict series name matcher for recognizing 1x01 patterns // strict series name matcher for recognizing 1x01 patterns
SeriesNameMatcher strictSeriesNameMatcher = getSeriesNameMatcher(true); SeriesNameMatcher strictSeriesNameMatcher = getSeriesNameMatcher(true);
@ -438,7 +442,7 @@ public class MediaDetection {
names.addAll(matches); names.addAll(matches);
// don't allow duplicates // don't allow duplicates
return getUniqueQuerySet(names); return getUniqueQuerySet(unids, names);
} }
public static List<String> matchSeriesByDirectMapping(Collection<File> files) throws Exception { public static List<String> matchSeriesByDirectMapping(Collection<File> files) throws Exception {
@ -933,7 +937,7 @@ public class MediaDetection {
querySet.addAll(stripReleaseInfo(files, false)); querySet.addAll(stripReleaseInfo(files, false));
// remove duplicates // remove duplicates
querySet = getUniqueQuerySet(stripBlacklistedTerms(querySet)); querySet = getUniqueQuerySet(emptySet(), stripBlacklistedTerms(querySet));
// DEBUG // DEBUG
// System.out.format("Query %s: %s%n", queryLookupService.getName(), querySet); // System.out.format("Query %s: %s%n", queryLookupService.getName(), querySet);
@ -959,14 +963,24 @@ public class MediaDetection {
return results; return results;
} }
private static List<String> getUniqueQuerySet(Collection<String> terms) { private static List<String> getUniqueQuerySet(Collection<String> exactMatches, Collection<String> guessMatches) {
Map<String, String> unique = new LinkedHashMap<String, String>(); Map<String, String> uniqueMap = new LinkedHashMap<String, String>();
// unique key function (case-insensitive ignore-punctuation)
Function<String, String> normalize = (s) -> normalizePunctuation(s).toLowerCase();
addUniqueQuerySet(exactMatches, normalize, Function.identity(), uniqueMap);
addUniqueQuerySet(guessMatches, normalize, normalize, uniqueMap);
return new ArrayList<String>(uniqueMap.values());
}
private static void addUniqueQuerySet(Collection<String> terms, Function<String, String> keyFunction, Function<String, String> valueFunction, Map<String, String> uniqueMap) {
for (String it : terms) { for (String it : terms) {
if (it.length() > 0) { String key = keyFunction.apply(it);
unique.put(normalizePunctuation(it).toLowerCase(), it); if (key.length() > 0 && !uniqueMap.containsKey(key)) {
uniqueMap.put(key, valueFunction.apply(it));
} }
} }
return new ArrayList<String>(unique.values());
} }
public static String stripReleaseInfo(String name) { public static String stripReleaseInfo(String name) {