* allow filename matches in -get-subtitles strict mode

This commit is contained in:
Reinhard Pointner 2012-07-08 12:35:38 +00:00
parent e3930b1e52
commit 9cd320431a
1 changed files with 12 additions and 12 deletions

View File

@ -559,24 +559,24 @@ public class CmdlineOperations implements CmdlineInterface {
} }
// lookup subtitles via text search, only perform hash lookup in strict mode // lookup subtitles via text search, only perform hash lookup in strict mode
if ((query != null || !strict) && !remainingVideos.isEmpty()) { if (!remainingVideos.isEmpty()) {
// auto-detect search query // auto-detect search query
Set<String> querySet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); Set<String> querySet = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
if (query == null) { if (query == null) {
try {
List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES); List<File> mediaFiles = filter(files, VIDEO_FILES, SUBTITLE_FILES);
querySet.addAll(detectSeriesNames(mediaFiles, language.toLocale())); querySet.addAll(detectSeriesNames(mediaFiles, language.toLocale()));
if (querySet.isEmpty() && mediaFiles.size() == 1) { for (File file : mediaFiles) {
try { Collection<Movie> results = MediaDetection.detectMovie(file, null, null, language.toLocale(), strict);
Collection<Movie> results = MediaDetection.detectMovie(mediaFiles.get(0), OpenSubtitles, TMDb, language.toLocale(), false);
for (Movie movie : results) { for (Movie movie : results) {
querySet.add(movie.getName()); querySet.add(movie.getName());
} }
}
} catch (Exception e) { } catch (Exception e) {
CLILogger.warning("Movie detection failed: " + e.getMessage()); CLILogger.warning("Movie detection failed: " + e.getMessage());
} }
}
if (querySet.isEmpty()) { if (querySet.isEmpty()) {
throw new Exception("Failed to auto-detect query"); throw new Exception("Failed to auto-detect query");
@ -592,7 +592,7 @@ public class CmdlineOperations implements CmdlineInterface {
try { try {
CLILogger.fine(format("Searching for %s at [%s]", querySet.toString(), service.getName())); CLILogger.fine(format("Searching for %s at [%s]", querySet.toString(), service.getName()));
Map<File, SubtitleDescriptor> subtitles = lookupSubtitleByFileName(service, querySet, language, remainingVideos); Map<File, SubtitleDescriptor> subtitles = lookupSubtitleByFileName(service, querySet, language, remainingVideos, strict);
Map<File, File> downloads = downloadSubtitleBatch(service.getName(), subtitles, outputFormat, outputEncoding); Map<File, File> downloads = downloadSubtitleBatch(service.getName(), subtitles, outputFormat, outputEncoding);
remainingVideos.removeAll(downloads.keySet()); remainingVideos.removeAll(downloads.keySet());
subtitleFiles.addAll(downloads.values()); subtitleFiles.addAll(downloads.values());
@ -708,7 +708,7 @@ public class CmdlineOperations implements CmdlineInterface {
} }
private Map<File, SubtitleDescriptor> lookupSubtitleByFileName(SubtitleProvider service, Collection<String> querySet, Language language, Collection<File> videoFiles) throws Exception { private Map<File, SubtitleDescriptor> lookupSubtitleByFileName(SubtitleProvider service, Collection<String> querySet, Language language, Collection<File> videoFiles, boolean strict) throws Exception {
Map<File, SubtitleDescriptor> subtitleByVideo = new HashMap<File, SubtitleDescriptor>(); Map<File, SubtitleDescriptor> subtitleByVideo = new HashMap<File, SubtitleDescriptor>();
// search for subtitles // search for subtitles
@ -721,7 +721,7 @@ public class CmdlineOperations implements CmdlineInterface {
SimilarityMetric sanity = EpisodeMetrics.verificationMetric(); SimilarityMetric sanity = EpisodeMetrics.verificationMetric();
for (Match<File, SubtitleDescriptor> it : matcher.match()) { for (Match<File, SubtitleDescriptor> it : matcher.match()) {
if (sanity.getSimilarity(it.getValue(), it.getCandidate()) >= 0.9) { if (sanity.getSimilarity(it.getValue(), it.getCandidate()) >= (strict ? 0.9f : 0.5f)) {
CLILogger.finest(format("Matched [%s] to [%s] via filename", it.getValue().getName(), it.getCandidate().getName())); CLILogger.finest(format("Matched [%s] to [%s] via filename", it.getValue().getName(), it.getCandidate().getName()));
subtitleByVideo.put(it.getValue(), it.getCandidate()); subtitleByVideo.put(it.getValue(), it.getCandidate());
} }