TheMovieDB::discoverPeriod

This commit is contained in:
Reinhard Pointner 2016-07-19 03:29:31 +08:00
parent 8654b2008b
commit 0312dcaf83
2 changed files with 22 additions and 0 deletions

View File

@ -14,6 +14,7 @@ import java.io.FileNotFoundException;
import java.io.Serializable;
import java.net.URI;
import java.net.URL;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.EnumMap;
import java.util.LinkedHashMap;
@ -321,6 +322,17 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider {
}, toList())));
}
public List<Movie> discover(LocalDate startDate, LocalDate endDate, Locale locale) throws Exception {
Object json = request("discover/movie?primary_release_date.gte=" + startDate + "&primary_release_date.lte=" + endDate + "&sort_by=popularity.desc", emptyMap(), locale, REQUEST_LIMIT);
return streamJsonObjects(json, "results").map(it -> {
String title = getString(it, "title");
int year = getStringValue(it, "release_date", SimpleDate::parse).getYear();
int id = getInteger(it, "id");
return new Movie(title, year, 0, id);
}).collect(toList());
}
protected Object request(String resource, Map<String, Object> parameters, Locale locale, FloodLimit limit) throws Exception {
// default parameters
String key = parameters.isEmpty() ? resource : resource + '?' + encodeParameters(parameters, true);

View File

@ -5,6 +5,7 @@ import static org.junit.Assert.*;
import java.net.URL;
import java.time.Duration;
import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
@ -113,6 +114,15 @@ public class TMDbClientTest {
assertEquals("http://image.tmdb.org/t/p/original/B7VTVtnKyFk0AtYjEbqzBQlPec.jpg", p.getImage().toString());
}
@Test
public void discoverPeriod() throws Exception {
Movie m = db.discover(LocalDate.parse("2014-09-15"), LocalDate.parse("2014-10-22"), Locale.ENGLISH).get(0);
assertEquals("Big Hero 6", m.getName());
assertEquals(2014, m.getYear());
assertEquals(177572, m.getTmdbId());
}
@Ignore
@Test
public void floodLimit() throws Exception {