* 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
try {
List<String> names = new ArrayList<String>();
for (File it : FileUtilities.listPathTail(file, 4, true)) {
names.add(it.getName());
Movie match = MediaDetection.matchMovie(file, 4);
if (match != null) {
return match;
}
return MediaDetection.matchMovieName(names, true, 0).get(0);
} catch (Exception e) {
// ignore and move on
}
// 3. run full-fledged movie detection
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) {
// ignore and fail
}

View File

@ -1113,6 +1113,19 @@ public class MediaDetection {
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) {
List<File> tail = listPathTail(file, 3, true);

View File

@ -69,7 +69,7 @@ public final class SubtitleUtilities {
List<File> files = bySeries.getValue();
// 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));
if (forceQuery != null && forceQuery.length() > 0) {

View File

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