From 1ce479e858b0bb504fa43415de59dbe99fe8cfb8 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 15 Sep 2014 18:00:34 +0000 Subject: [PATCH] * local index now contains localized titles and thus should be considered the best result if available --- source/net/filebot/media/MediaDetection.java | 6 ++-- .../filebot/ui/rename/MovieHashMatcher.java | 4 ++- .../ui/subtitle/SubtitleUploadDialog.java | 2 +- source/net/filebot/web/TMDbClient.java | 34 ++++++++++--------- 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index 78eda193..0d98910b 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -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 if (queryLookupService != null) { Collection results = queryMovieByFileName(terms, queryLookupService, locale); @@ -668,9 +671,6 @@ public class MediaDetection { options.addAll(results); } - // add local matching after online search - options.addAll(movieNameMatches); - // sort by relevance return sortBySimilarity(options, terms, getMovieMatchMetric(), true); } diff --git a/source/net/filebot/ui/rename/MovieHashMatcher.java b/source/net/filebot/ui/rename/MovieHashMatcher.java index 5989f0d2..338d66ea 100644 --- a/source/net/filebot/ui/rename/MovieHashMatcher.java +++ b/source/net/filebot/ui/rename/MovieHashMatcher.java @@ -475,8 +475,10 @@ class MovieHashMatcher implements AutoCompleteMatcher { List> matches = new ArrayList>(); if (input != null && input.length() > 0) { Collection results = new LinkedHashSet(); + + // 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(matchMovieName(singleton(input), false, 2)); // improve ranking results = sortBySimilarity(results, singleton(input), getMovieMatchMetric(), false); diff --git a/source/net/filebot/ui/subtitle/SubtitleUploadDialog.java b/source/net/filebot/ui/subtitle/SubtitleUploadDialog.java index e3ab9054..3ec39f0e 100644 --- a/source/net/filebot/ui/subtitle/SubtitleUploadDialog.java +++ b/source/net/filebot/ui/subtitle/SubtitleUploadDialog.java @@ -702,7 +702,7 @@ public class SubtitleUploadDialog extends JDialog { Collection identity = MediaDetection.detectMovie(mapping.getVideo(), database, database, Locale.ENGLISH, true); for (Movie it : identity) { 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) { mapping.setIdentity(it); diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 128a0b56..73485fa3 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -69,13 +69,13 @@ public class TMDbClient implements MovieIdentificationService { // query by name with year filter if possible Matcher nameYear = Pattern.compile("(.+)\\b(19\\d{2}|20\\d{2})$").matcher(query); 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 { - return searchMovie(query, -1, locale); + return searchMovie(query, -1, locale, false); } } - public List searchMovie(String movieName, int movieYear, Locale locale) throws IOException { + public List searchMovie(String movieName, int movieYear, Locale locale, boolean extendedInfo) throws IOException { // ignore queries that are too short to yield good results if (movieName.length() < 3 && !(movieName.length() > 1 && movieYear > 0)) { return emptyList(); @@ -118,18 +118,20 @@ public class TMDbClient implements MovieIdentificationService { alternativeTitles.add(originalTitle); } - try { - Set internationalTitles = new TreeSet(String.CASE_INSENSITIVE_ORDER); - JSONObject titles = request("movie/" + id + "/alternative_titles", null, null, REQUEST_LIMIT); - for (JSONObject node : jsonList(titles.get("titles"))) { - String t = (String) node.get("title"); - if (t != null && t.length() >= 3) { - internationalTitles.add(t); + if (extendedInfo) { + try { + Set internationalTitles = new TreeSet(String.CASE_INSENSITIVE_ORDER); + JSONObject titles = request("movie/" + id + "/alternative_titles", null, null, REQUEST_LIMIT); + for (JSONObject node : jsonList(titles.get("titles"))) { + String t = (String) node.get("title"); + 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 @@ -152,17 +154,17 @@ public class TMDbClient implements MovieIdentificationService { @Override 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) { throw new IllegalArgumentException("id must not be " + imdbtmdbid); } String id = byIMDB ? String.format("tt%07d", imdbtmdbid) : String.valueOf(imdbtmdbid); 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); } catch (FileNotFoundException e) { Logger.getLogger(getClass().getName()).log(Level.WARNING, "Movie not found: " + id);