* use y:2014 year filter when querying TheMovieDB if possible
This commit is contained in:
parent
c275b0e53d
commit
53e5e48d5f
@ -26,6 +26,8 @@ import java.util.Set;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
|
||||||
@ -63,6 +65,19 @@ public class TMDbClient implements MovieIdentificationService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Movie> searchMovie(String query, Locale locale) throws IOException {
|
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);
|
JSONObject response = request("search/movie", singletonMap("query", query), locale, SEARCH_LIMIT);
|
||||||
List<Movie> result = new ArrayList<Movie>();
|
List<Movie> result = new ArrayList<Movie>();
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@ import java.util.Locale;
|
|||||||
import net.filebot.web.TMDbClient.Artwork;
|
import net.filebot.web.TMDbClient.Artwork;
|
||||||
import net.filebot.web.TMDbClient.MovieInfo;
|
import net.filebot.web.TMDbClient.MovieInfo;
|
||||||
|
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class TMDbClientTest {
|
public class TMDbClientTest {
|
||||||
@ -27,6 +28,17 @@ public class TMDbClientTest {
|
|||||||
assertEquals(16320, movie.getTmdbId());
|
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
|
@Test
|
||||||
public void searchByNameGermanResults() throws Exception {
|
public void searchByNameGermanResults() throws Exception {
|
||||||
List<Movie> result = tmdb.searchMovie("East of Eden", Locale.GERMAN);
|
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());
|
assertEquals("http://image.tmdb.org/t/p/original/dXTeZELpoVMDOTTLnNoCpsCngwW.jpg", artwork.get(0).getUrl().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void floodLimit() throws Exception {
|
public void floodLimit() throws Exception {
|
||||||
for (Locale it : Locale.getAvailableLocales()) {
|
for (Locale it : Locale.getAvailableLocales()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user