* use y:2014 year filter when querying TheMovieDB if possible

This commit is contained in:
Reinhard Pointner 2014-05-02 08:00:43 +00:00
parent c275b0e53d
commit 53e5e48d5f
2 changed files with 28 additions and 0 deletions

View File

@ -26,6 +26,8 @@ import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.Icon;
@ -63,6 +65,19 @@ public class TMDbClient implements MovieIdentificationService {
@Override
public List<Movie> 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);
if (nameYear.matches()) {
return searchMovie(nameYear.group(1).trim(), Integer.parseInt(nameYear.group(2)), locale);
} else {
return searchMovie(query, -1, locale);
}
}
public List<Movie> searchMovie(String movieName, int movieYear, Locale locale) throws IOException {
// use y:2014 year filter if possible
String query = (movieYear > 0) ? String.format("%s y:%d", movieName, movieYear) : movieName.toString();
JSONObject response = request("search/movie", singletonMap("query", query), locale, SEARCH_LIMIT);
List<Movie> result = new ArrayList<Movie>();

View File

@ -10,6 +10,7 @@ import java.util.Locale;
import net.filebot.web.TMDbClient.Artwork;
import net.filebot.web.TMDbClient.MovieInfo;
import org.junit.Ignore;
import org.junit.Test;
public class TMDbClientTest {
@ -27,6 +28,17 @@ public class TMDbClientTest {
assertEquals(16320, movie.getTmdbId());
}
@Test
public void searchByNameWithYear() throws Exception {
List<Movie> result = tmdb.searchMovie("Up 2009", Locale.ENGLISH);
Movie movie = result.get(0);
assertEquals("Up", movie.getName());
assertEquals(2009, movie.getYear());
assertEquals(-1, movie.getImdbId());
assertEquals(14160, movie.getTmdbId());
}
@Test
public void searchByNameGermanResults() throws Exception {
List<Movie> result = tmdb.searchMovie("East of Eden", Locale.GERMAN);
@ -66,6 +78,7 @@ public class TMDbClientTest {
assertEquals("http://image.tmdb.org/t/p/original/dXTeZELpoVMDOTTLnNoCpsCngwW.jpg", artwork.get(0).getUrl().toString());
}
@Ignore
@Test
public void floodLimit() throws Exception {
for (Locale it : Locale.getAvailableLocales()) {