TheMovieDB::discoverPeriod
This commit is contained in:
parent
8654b2008b
commit
0312dcaf83
@ -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);
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user