From 9ad9a3e1a99433a59449ca440a3b26c57c45b7db Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 27 Sep 2015 08:41:02 +0000 Subject: [PATCH] * fix auto-detection issues for movie query "9 (2009)" --- source/net/filebot/web/TMDbClient.java | 4 ++-- test/net/filebot/web/TMDbClientTest.java | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 60759914..c37053f4 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -69,7 +69,7 @@ public class TMDbClient implements MovieIdentificationService { @Override public List searchMovie(String query, Locale locale) throws IOException { // 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.trim()); if (nameYear.matches()) { return searchMovie(nameYear.group(1).trim(), Integer.parseInt(nameYear.group(2)), locale, false); } else { @@ -79,7 +79,7 @@ public class TMDbClient implements MovieIdentificationService { 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)) { + if (movieName.length() < 3 && !(movieName.length() >= 1 && movieYear > 0)) { return emptyList(); } diff --git a/test/net/filebot/web/TMDbClientTest.java b/test/net/filebot/web/TMDbClientTest.java index 036f84de..59216895 100644 --- a/test/net/filebot/web/TMDbClientTest.java +++ b/test/net/filebot/web/TMDbClientTest.java @@ -28,7 +28,7 @@ public class TMDbClientTest { } @Test - public void searchByNameWithYear() throws Exception { + public void searchByNameWithYearShortName() throws Exception { List result = tmdb.searchMovie("Up 2009", Locale.ENGLISH); Movie movie = result.get(0); @@ -38,6 +38,17 @@ public class TMDbClientTest { assertEquals(14160, movie.getTmdbId()); } + @Test + public void searchByNameWithYearNumberName() throws Exception { + List result = tmdb.searchMovie("9 (2009)", Locale.ENGLISH); + Movie movie = result.get(0); + + assertEquals("9", movie.getName()); + assertEquals(2009, movie.getYear()); + assertEquals(-1, movie.getImdbId()); + assertEquals(12244, movie.getTmdbId()); + } + @Test public void searchByNameGermanResults() throws Exception { List result = tmdb.searchMovie("East of Eden", Locale.GERMAN);