This commit is contained in:
Reinhard Pointner 2016-03-29 06:29:23 +00:00
parent 874c6ff4eb
commit c552bdb8ae
2 changed files with 24 additions and 27 deletions

View File

@ -252,7 +252,7 @@ public abstract class ScriptShellBaseClass extends Script {
return null; return null;
} }
public Movie matchMovie(String name) throws Exception { public Movie matchMovie(String name) {
List<Movie> matches = MediaDetection.matchMovieName(singleton(name), true, 0); List<Movie> matches = MediaDetection.matchMovieName(singleton(name), true, 0);
return matches == null || matches.isEmpty() ? null : matches.get(0); return matches == null || matches.isEmpty() ? null : matches.get(0);
} }

View File

@ -26,6 +26,7 @@ import java.util.Collection;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.LinkedList; import java.util.LinkedList;
@ -33,7 +34,6 @@ import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Objects; import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.SortedSet; import java.util.SortedSet;
@ -81,7 +81,7 @@ public class MediaDetection {
try { try {
return releaseInfo.getClutterFileFilter(); return releaseInfo.getClutterFileFilter();
} catch (Exception e) { } catch (Exception e) {
debug.log(Level.SEVERE, "Failed to access clutter file filter: " + e.getMessage(), e); debug.log(Level.SEVERE, "Failed to load clutter file filter: " + e.getMessage(), e);
} }
return f -> false; return f -> false;
} }
@ -125,14 +125,12 @@ public class MediaDetection {
public static boolean isMovie(File file, boolean strict) { public static boolean isMovie(File file, boolean strict) {
if (xattr.getMetaInfo(file) instanceof Movie) if (xattr.getMetaInfo(file) instanceof Movie)
return true; return true;
if (isEpisode(file, strict)) if (isEpisode(file, strict))
return false; return false;
try { if (matchMovieName(asList(file.getName(), file.getParent()), strict, 0).size() > 0)
return matchMovieName(asList(file.getName(), file.getParent()), strict, 0).size() > 0; return true;
} catch (Exception e) {
debug.log(Level.SEVERE, "Failed to access movie index: " + e.getMessage(), e);
}
// check for valid imdb id patterns // check for valid imdb id patterns
return grepImdbId(file.getPath()).stream().map(Movie::new).filter(m -> { return grepImdbId(file.getPath()).stream().map(Movie::new).filter(m -> {
@ -851,14 +849,14 @@ public class MediaDetection {
return null; return null;
} }
public static Movie checkMovie(File file, boolean strict) throws Exception { public static Movie checkMovie(File file, boolean strict) {
List<Movie> matches = file != null ? matchMovieName(singleton(file.getName()), strict, 4) : null; List<Movie> matches = file == null ? null : matchMovieName(singleton(file.getName()), strict, 4);
return matches != null && matches.size() > 0 ? matches.get(0) : null; return matches == null || matches.isEmpty() ? null : matches.get(0);
} }
private static final ArrayList<IndexEntry<Movie>> movieIndex = new ArrayList<IndexEntry<Movie>>(); private static final ArrayList<IndexEntry<Movie>> movieIndex = new ArrayList<IndexEntry<Movie>>();
public static List<IndexEntry<Movie>> getMovieIndex() throws IOException { public static List<IndexEntry<Movie>> getMovieIndex() {
synchronized (movieIndex) { synchronized (movieIndex) {
if (movieIndex.isEmpty()) { if (movieIndex.isEmpty()) {
movieIndex.ensureCapacity(100000); movieIndex.ensureCapacity(100000);
@ -878,7 +876,7 @@ public class MediaDetection {
} }
} }
public static List<Movie> matchMovieName(final Collection<String> files, boolean strict, int maxStartIndex) throws Exception { public static List<Movie> matchMovieName(Collection<String> files, boolean strict, int maxStartIndex) {
// cross-reference file / folder name with movie list // cross-reference file / folder name with movie list
final HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(maxStartIndex); final HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(maxStartIndex);
final Map<Movie, String> matchMap = new HashMap<Movie, String>(); final Map<Movie, String> matchMap = new HashMap<Movie, String>();
@ -907,7 +905,7 @@ public class MediaDetection {
}).collect(toList()); }).collect(toList());
} }
public static List<Movie> matchMovieFromStringWithoutSpacing(Collection<String> names, boolean strict) throws IOException { public static List<Movie> matchMovieFromStringWithoutSpacing(Collection<String> names, boolean strict) {
// clear name of punctuation, spacing, and leading 'The' or 'A' that are common causes for word-lookup to fail // clear name of punctuation, spacing, and leading 'The' or 'A' that are common causes for word-lookup to fail
Pattern spacing = Pattern.compile("(^(?i)(The|A)\\b)|[\\p{Punct}\\p{Space}]+"); Pattern spacing = Pattern.compile("(^(?i)(The|A)\\b)|[\\p{Punct}\\p{Space}]+");
@ -1023,12 +1021,14 @@ public class MediaDetection {
public static String stripReleaseInfo(String name, boolean strict) { public static String stripReleaseInfo(String name, boolean strict) {
try { try {
return releaseInfo.cleanRelease(singleton(name), strict).iterator().next(); Iterator<String> value = releaseInfo.cleanRelease(singleton(name), strict).iterator();
} catch (NoSuchElementException e) { if (value.hasNext()) {
return ""; // default value in case all tokens are stripped away return value.next();
}
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); debug.log(Level.SEVERE, "Failed to strip release info: " + e.getMessage(), e);
} }
return ""; // default value in case all tokens are stripped away
} }
public static boolean isStructureRoot(File folder) throws Exception { public static boolean isStructureRoot(File folder) throws Exception {
@ -1129,16 +1129,13 @@ public class MediaDetection {
} }
public static Movie matchMovie(File file, int depth) { public static Movie matchMovie(File file, int depth) {
try { List<String> names = new ArrayList<String>(depth);
List<String> names = new ArrayList<String>(depth); for (File it : listPathTail(file, depth, true)) {
for (File it : listPathTail(file, depth, true)) { names.add(it.getName());
names.add(it.getName());
}
List<Movie> matches = matchMovieName(names, true, 0);
return matches.size() > 0 ? matches.get(0) : null;
} catch (Exception e) {
throw new RuntimeException(e);
} }
List<Movie> matches = matchMovieName(names, true, 0);
return matches.size() > 0 ? matches.get(0) : null;
} }
public static File guessMediaFolder(File file) { public static File guessMediaFolder(File file) {