* optimize subtitle lookup

This commit is contained in:
Reinhard Pointner 2014-11-11 07:51:56 +00:00
parent 3ddbc28500
commit 3a06c4f7ef
4 changed files with 19 additions and 7 deletions

View File

@ -233,18 +233,17 @@ public abstract class ScriptShellBaseClass extends Script {
// 2. perfect filename match // 2. perfect filename match
try { try {
List<String> names = new ArrayList<String>(); Movie match = MediaDetection.matchMovie(file, 4);
for (File it : FileUtilities.listPathTail(file, 4, true)) { if (match != null) {
names.add(it.getName()); return match;
} }
return MediaDetection.matchMovieName(names, true, 0).get(0);
} catch (Exception e) { } catch (Exception e) {
// ignore and move on // ignore and move on
} }
// 3. run full-fledged movie detection // 3. run full-fledged movie detection
try { try {
return MediaDetection.detectMovie(file, WebServices.OpenSubtitles, WebServices.TheMovieDB, Locale.ENGLISH, strict).get(0); return MediaDetection.detectMovie(file, WebServices.OpenSubtitles.isAnonymous() ? null : WebServices.OpenSubtitles, WebServices.TheMovieDB, Locale.ENGLISH, strict).get(0);
} catch (Exception e) { } catch (Exception e) {
// ignore and fail // ignore and fail
} }

View File

@ -1113,6 +1113,19 @@ public class MediaDetection {
return result; return result;
} }
public static Movie matchMovie(File file, int depth) {
try {
List<String> names = new ArrayList<String>(depth);
for (File it : listPathTail(file, depth, true)) {
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);
}
}
public static File guessMediaFolder(File file) { public static File guessMediaFolder(File file) {
List<File> tail = listPathTail(file, 3, true); List<File> tail = listPathTail(file, 3, true);

View File

@ -69,7 +69,7 @@ public final class SubtitleUtilities {
List<File> files = bySeries.getValue(); List<File> files = bySeries.getValue();
// try to guess what type of search might be required (minimize false negatives) // try to guess what type of search might be required (minimize false negatives)
boolean searchBySeries = files.stream().anyMatch(f -> isEpisode(getName(f), false)); boolean searchBySeries = files.stream().anyMatch(f -> isEpisode(getName(f), true) || (isEpisode(getName(f), false) && matchMovie(f, 2) == null));
boolean searchByMovie = files.stream().anyMatch(f -> !isEpisode(getName(f), true)); boolean searchByMovie = files.stream().anyMatch(f -> !isEpisode(getName(f), true));
if (forceQuery != null && forceQuery.length() > 0) { if (forceQuery != null && forceQuery.length() > 0) {

View File

@ -67,7 +67,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
} }
public boolean isAnonymous() { public boolean isAnonymous() {
return username.isEmpty(); return username == null || username.isEmpty();
} }
@Override @Override