* guarantee that movies are processed if already well-named also in strict mode
This commit is contained in:
parent
53e5e48d5f
commit
2f4d43b547
|
@ -417,11 +417,21 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
// unknown hash, try via imdb id from nfo file
|
||||
if (movie == null) {
|
||||
CLILogger.fine(format("Auto-detect movie from context: [%s]", file));
|
||||
Collection<Movie> results = detectMovie(file, null, service, locale, strict);
|
||||
List<Movie> validResults = applyExpressionFilter(results, filter);
|
||||
Collection<Movie> options = detectMovie(file, null, service, locale, strict);
|
||||
|
||||
// apply filter if defined
|
||||
options = applyExpressionFilter(options, filter);
|
||||
|
||||
// reduce options to perfect matches if possible
|
||||
List<Movie> perfectMatches = matchMovieByWordSequence(getName(file), options, 0);
|
||||
if (perfectMatches.size() > 0) {
|
||||
options = perfectMatches;
|
||||
}
|
||||
|
||||
try {
|
||||
if (validResults.size() > 0) {
|
||||
movie = (Movie) selectSearchResult(query, validResults, strict).get(0);
|
||||
// select first element if matches are reliable
|
||||
if (options.size() > 0) {
|
||||
movie = (Movie) selectSearchResult(null, options, strict).get(0);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
CLILogger.log(Level.WARNING, String.format("%s: [%s/%s] %s", e.getClass().getSimpleName(), guessMovieFolder(file) != null ? guessMovieFolder(file).getName() : null, file.getName(), e.getMessage()));
|
||||
|
@ -854,15 +864,19 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
}
|
||||
|
||||
public List<SearchResult> findProbableMatches(final String query, Collection<? extends SearchResult> searchResults, boolean strict) {
|
||||
if (query == null) {
|
||||
return new ArrayList<SearchResult>(searchResults);
|
||||
}
|
||||
|
||||
// auto-select most probable search result
|
||||
List<SearchResult> probableMatches = new ArrayList<SearchResult>();
|
||||
|
||||
// use name similarity metric
|
||||
final SimilarityMetric metric = new NameSimilarityMetric();
|
||||
SimilarityMetric metric = new NameSimilarityMetric();
|
||||
|
||||
// find probable matches using name similarity > 0.8 (or > 0.6 in non-strict mode)
|
||||
for (SearchResult result : searchResults) {
|
||||
float f = (query == null) ? 1 : metric.getSimilarity(query, result.getName());
|
||||
float f = metric.getSimilarity(query, result.getName());
|
||||
if (f >= (strict && searchResults.size() > 1 ? 0.8 : 0.6) || ((f >= 0.5 || !strict) && (result.getName().toLowerCase().startsWith(query.toLowerCase())))) {
|
||||
if (!probableMatches.contains(result)) {
|
||||
probableMatches.add(result);
|
||||
|
@ -871,9 +885,8 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
}
|
||||
|
||||
// sort results by similarity to query
|
||||
if (query != null) {
|
||||
sort(probableMatches, new SimilarityComparator(query));
|
||||
}
|
||||
sort(probableMatches, new SimilarityComparator(query));
|
||||
|
||||
return probableMatches;
|
||||
}
|
||||
|
||||
|
@ -892,7 +905,9 @@ public class CmdlineOperations implements CmdlineInterface {
|
|||
}
|
||||
|
||||
// just pick the best 5 matches
|
||||
probableMatches = (List<SearchResult>) sortBySimilarity(searchResults, singleton(query), getSeriesMatchMetric(), false);
|
||||
if (query != null) {
|
||||
probableMatches = (List<SearchResult>) sortBySimilarity(searchResults, singleton(query), getSeriesMatchMetric(), false);
|
||||
}
|
||||
}
|
||||
|
||||
// return first and only value
|
||||
|
|
|
@ -58,11 +58,11 @@ import net.filebot.similarity.SimilarityComparator;
|
|||
import net.filebot.similarity.SimilarityMetric;
|
||||
import net.filebot.similarity.StringEqualsMetric;
|
||||
import net.filebot.vfs.FileInfo;
|
||||
import net.filebot.web.SimpleDate;
|
||||
import net.filebot.web.Episode;
|
||||
import net.filebot.web.Movie;
|
||||
import net.filebot.web.MovieIdentificationService;
|
||||
import net.filebot.web.SearchResult;
|
||||
import net.filebot.web.SimpleDate;
|
||||
import net.filebot.web.TheTVDBClient.SeriesInfo;
|
||||
import net.filebot.web.TheTVDBSearchResult;
|
||||
|
||||
|
@ -961,6 +961,27 @@ public class MediaDetection {
|
|||
return stripReleaseInfo(name, true);
|
||||
}
|
||||
|
||||
public static List<Movie> matchMovieByWordSequence(String name, Collection<Movie> options, int maxStartIndex) {
|
||||
List<Movie> movies = new ArrayList<Movie>();
|
||||
|
||||
HighPerformanceMatcher nameMatcher = new HighPerformanceMatcher(maxStartIndex);
|
||||
CollationKey[] nameSeq = HighPerformanceMatcher.prepare(normalizePunctuation(name));
|
||||
|
||||
for (Movie movie : options) {
|
||||
for (String alias : movie.getEffectiveNames()) {
|
||||
CollationKey[] movieSeq = HighPerformanceMatcher.prepare(normalizePunctuation(alias));
|
||||
CollationKey[] commonSeq = nameMatcher.matchFirstCommonSequence(nameSeq, movieSeq);
|
||||
|
||||
if (commonSeq != null && commonSeq.length >= movieSeq.length) {
|
||||
movies.add(movie);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return movies;
|
||||
}
|
||||
|
||||
public static String stripReleaseInfo(String name, boolean strict) {
|
||||
try {
|
||||
return releaseInfo.cleanRelease(singleton(name), strict).iterator().next();
|
||||
|
|
Loading…
Reference in New Issue