* local index now contains localized titles and thus should be considered the best result if available

This commit is contained in:
Reinhard Pointner 2014-09-15 18:00:34 +00:00
parent 36feeba380
commit 1ce479e858
4 changed files with 25 additions and 21 deletions

View File

@ -643,6 +643,9 @@ public class MediaDetection {
} }
} }
// add local index matches before online search (and retain additional alias titles available in the local index)
options.addAll(movieNameMatches);
// query by file / folder name // query by file / folder name
if (queryLookupService != null) { if (queryLookupService != null) {
Collection<Movie> results = queryMovieByFileName(terms, queryLookupService, locale); Collection<Movie> results = queryMovieByFileName(terms, queryLookupService, locale);
@ -668,9 +671,6 @@ public class MediaDetection {
options.addAll(results); options.addAll(results);
} }
// add local matching after online search
options.addAll(movieNameMatches);
// sort by relevance // sort by relevance
return sortBySimilarity(options, terms, getMovieMatchMetric(), true); return sortBySimilarity(options, terms, getMovieMatchMetric(), true);
} }

View File

@ -475,8 +475,10 @@ class MovieHashMatcher implements AutoCompleteMatcher {
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>(); List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
if (input != null && input.length() > 0) { if (input != null && input.length() > 0) {
Collection<Movie> results = new LinkedHashSet<Movie>(); Collection<Movie> results = new LinkedHashSet<Movie>();
// data from local index has precedence same as in standard movie detection
results.addAll(matchMovieName(singleton(input), false, 0));
results.addAll(service.searchMovie(input, locale)); results.addAll(service.searchMovie(input, locale));
results.addAll(matchMovieName(singleton(input), false, 2));
// improve ranking // improve ranking
results = sortBySimilarity(results, singleton(input), getMovieMatchMetric(), false); results = sortBySimilarity(results, singleton(input), getMovieMatchMetric(), false);

View File

@ -702,7 +702,7 @@ public class SubtitleUploadDialog extends JDialog {
Collection<Movie> identity = MediaDetection.detectMovie(mapping.getVideo(), database, database, Locale.ENGLISH, true); Collection<Movie> identity = MediaDetection.detectMovie(mapping.getVideo(), database, database, Locale.ENGLISH, true);
for (Movie it : identity) { for (Movie it : identity) {
if (it.getImdbId() <= 0 && it.getTmdbId() > 0) { if (it.getImdbId() <= 0 && it.getTmdbId() > 0) {
it = WebServices.TheMovieDB.getMovieDescriptor(it.getTmdbId(), Locale.ENGLISH, false); it = WebServices.TheMovieDB.getMovieDescriptor(it.getTmdbId(), false, Locale.ENGLISH, false);
} }
if (it != null && it.getImdbId() > 0) { if (it != null && it.getImdbId() > 0) {
mapping.setIdentity(it); mapping.setIdentity(it);

View File

@ -69,13 +69,13 @@ public class TMDbClient implements MovieIdentificationService {
// query by name with year filter if possible // query by name with year filter if possible
Matcher nameYear = Pattern.compile("(.+)\\b(19\\d{2}|20\\d{2})$").matcher(query); Matcher nameYear = Pattern.compile("(.+)\\b(19\\d{2}|20\\d{2})$").matcher(query);
if (nameYear.matches()) { if (nameYear.matches()) {
return searchMovie(nameYear.group(1).trim(), Integer.parseInt(nameYear.group(2)), locale); return searchMovie(nameYear.group(1).trim(), Integer.parseInt(nameYear.group(2)), locale, false);
} else { } else {
return searchMovie(query, -1, locale); return searchMovie(query, -1, locale, false);
} }
} }
public List<Movie> searchMovie(String movieName, int movieYear, Locale locale) throws IOException { public List<Movie> searchMovie(String movieName, int movieYear, Locale locale, boolean extendedInfo) throws IOException {
// ignore queries that are too short to yield good results // ignore queries that are too short to yield good results
if (movieName.length() < 3 && !(movieName.length() > 1 && movieYear > 0)) { if (movieName.length() < 3 && !(movieName.length() > 1 && movieYear > 0)) {
return emptyList(); return emptyList();
@ -118,18 +118,20 @@ public class TMDbClient implements MovieIdentificationService {
alternativeTitles.add(originalTitle); alternativeTitles.add(originalTitle);
} }
try { if (extendedInfo) {
Set<String> internationalTitles = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); try {
JSONObject titles = request("movie/" + id + "/alternative_titles", null, null, REQUEST_LIMIT); Set<String> internationalTitles = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
for (JSONObject node : jsonList(titles.get("titles"))) { JSONObject titles = request("movie/" + id + "/alternative_titles", null, null, REQUEST_LIMIT);
String t = (String) node.get("title"); for (JSONObject node : jsonList(titles.get("titles"))) {
if (t != null && t.length() >= 3) { String t = (String) node.get("title");
internationalTitles.add(t); if (t != null && t.length() >= 3) {
internationalTitles.add(t);
}
} }
alternativeTitles.addAll(internationalTitles);
} catch (Exception e) {
Logger.getLogger(TMDbClient.class.getName()).log(Level.WARNING, String.format("Unable to retrieve alternative titles [%s]: %s", title, e.getMessage()));
} }
alternativeTitles.addAll(internationalTitles);
} catch (Exception e) {
Logger.getLogger(TMDbClient.class.getName()).log(Level.WARNING, String.format("Unable to retrieve alternative titles [%s]: %s", title, e.getMessage()));
} }
// make sure main title is not in the set of alternative titles // make sure main title is not in the set of alternative titles
@ -152,17 +154,17 @@ public class TMDbClient implements MovieIdentificationService {
@Override @Override
public Movie getMovieDescriptor(int imdbid, Locale locale) throws IOException { public Movie getMovieDescriptor(int imdbid, Locale locale) throws IOException {
return getMovieDescriptor(imdbid, locale, true); return getMovieDescriptor(imdbid, true, locale, true);
} }
public Movie getMovieDescriptor(int imdbtmdbid, Locale locale, boolean byIMDB) throws IOException { public Movie getMovieDescriptor(int imdbtmdbid, boolean byIMDB, Locale locale, boolean extendedInfo) throws IOException {
if (imdbtmdbid <= 0) { if (imdbtmdbid <= 0) {
throw new IllegalArgumentException("id must not be " + imdbtmdbid); throw new IllegalArgumentException("id must not be " + imdbtmdbid);
} }
String id = byIMDB ? String.format("tt%07d", imdbtmdbid) : String.valueOf(imdbtmdbid); String id = byIMDB ? String.format("tt%07d", imdbtmdbid) : String.valueOf(imdbtmdbid);
try { try {
MovieInfo info = getMovieInfo(id, locale, false); MovieInfo info = getMovieInfo(id, locale, extendedInfo);
return new Movie(info.getName(), new String[0], info.getReleased().getYear(), info.getImdbId(), info.getId(), locale); return new Movie(info.getName(), new String[0], info.getReleased().getYear(), info.getImdbId(), info.getId(), locale);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Movie not found: " + id); Logger.getLogger(getClass().getName()).log(Level.WARNING, "Movie not found: " + id);