2014-04-19 02:30:29 -04:00
|
|
|
package net.filebot.web;
|
2009-11-02 18:25:04 -05:00
|
|
|
|
2016-03-11 16:26:36 -05:00
|
|
|
import static net.filebot.CachedResource.*;
|
2009-11-02 18:25:04 -05:00
|
|
|
import static org.junit.Assert.*;
|
|
|
|
|
2016-03-11 16:26:36 -05:00
|
|
|
import java.net.URL;
|
|
|
|
import java.time.Duration;
|
2013-11-18 09:41:19 -05:00
|
|
|
import java.util.Arrays;
|
2009-11-02 18:25:04 -05:00
|
|
|
import java.util.List;
|
2011-08-10 01:05:11 -04:00
|
|
|
import java.util.Locale;
|
2009-11-02 18:25:04 -05:00
|
|
|
|
2014-05-02 04:00:43 -04:00
|
|
|
import org.junit.Ignore;
|
2012-07-24 13:44:54 -04:00
|
|
|
import org.junit.Test;
|
|
|
|
|
2016-03-11 16:26:36 -05:00
|
|
|
import net.filebot.Cache;
|
|
|
|
import net.filebot.CacheType;
|
|
|
|
import net.filebot.CachedResource;
|
|
|
|
import net.filebot.web.TMDbClient.MovieInfo;
|
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
public class TMDbClientTest {
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2016-05-09 10:59:21 -04:00
|
|
|
static TMDbClient db = new TMDbClient("66308fb6e3fd850dde4c7d21df2e8306");
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
@Test
|
|
|
|
public void searchByName() throws Exception {
|
2016-05-09 10:59:21 -04:00
|
|
|
List<Movie> result = db.searchMovie("Serenity", Locale.CHINESE);
|
2011-09-22 08:55:04 -04:00
|
|
|
Movie movie = result.get(0);
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2012-02-09 08:42:14 -05:00
|
|
|
assertEquals("冲出宁静号", movie.getName());
|
2011-01-07 06:02:11 -05:00
|
|
|
assertEquals(2005, movie.getYear());
|
2012-07-24 13:44:54 -04:00
|
|
|
assertEquals(-1, movie.getImdbId());
|
|
|
|
assertEquals(16320, movie.getTmdbId());
|
2009-11-02 18:25:04 -05:00
|
|
|
}
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2014-05-02 04:00:43 -04:00
|
|
|
@Test
|
2015-09-27 04:41:02 -04:00
|
|
|
public void searchByNameWithYearShortName() throws Exception {
|
2016-05-09 10:59:21 -04:00
|
|
|
List<Movie> result = db.searchMovie("Up 2009", Locale.ENGLISH);
|
2014-05-02 04:00:43 -04:00
|
|
|
Movie movie = result.get(0);
|
|
|
|
|
|
|
|
assertEquals("Up", movie.getName());
|
|
|
|
assertEquals(2009, movie.getYear());
|
|
|
|
assertEquals(-1, movie.getImdbId());
|
|
|
|
assertEquals(14160, movie.getTmdbId());
|
|
|
|
}
|
|
|
|
|
2015-09-27 04:41:02 -04:00
|
|
|
@Test
|
|
|
|
public void searchByNameWithYearNumberName() throws Exception {
|
2016-05-09 10:59:21 -04:00
|
|
|
List<Movie> result = db.searchMovie("9 (2009)", Locale.ENGLISH);
|
2015-09-27 04:41:02 -04:00
|
|
|
Movie movie = result.get(0);
|
|
|
|
|
|
|
|
assertEquals("9", movie.getName());
|
|
|
|
assertEquals(2009, movie.getYear());
|
|
|
|
assertEquals(-1, movie.getImdbId());
|
|
|
|
assertEquals(12244, movie.getTmdbId());
|
|
|
|
}
|
|
|
|
|
2013-11-18 09:41:19 -05:00
|
|
|
@Test
|
|
|
|
public void searchByNameGermanResults() throws Exception {
|
2016-05-09 10:59:21 -04:00
|
|
|
List<Movie> result = db.searchMovie("East of Eden", Locale.GERMAN);
|
2013-11-18 09:41:19 -05:00
|
|
|
Movie movie = result.get(0);
|
|
|
|
|
|
|
|
assertEquals("Jenseits von Eden", movie.getName());
|
|
|
|
assertEquals(1955, movie.getYear());
|
|
|
|
assertEquals(Arrays.asList("Jenseits von Eden (1955)", "East of Eden (1955)"), movie.getEffectiveNames());
|
|
|
|
}
|
|
|
|
|
2009-11-21 20:27:05 -05:00
|
|
|
@Test
|
|
|
|
public void searchByIMDB() throws Exception {
|
2016-05-09 10:59:21 -04:00
|
|
|
Movie movie = db.getMovieDescriptor(new Movie(418279), Locale.ENGLISH);
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2009-11-21 20:27:05 -05:00
|
|
|
assertEquals("Transformers", movie.getName());
|
2011-12-25 06:18:55 -05:00
|
|
|
assertEquals(2007, movie.getYear(), 0);
|
|
|
|
assertEquals(418279, movie.getImdbId(), 0);
|
2012-07-24 13:44:54 -04:00
|
|
|
assertEquals(1858, movie.getTmdbId(), 0);
|
2009-11-21 20:27:05 -05:00
|
|
|
}
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2011-12-25 06:18:55 -05:00
|
|
|
@Test
|
|
|
|
public void getMovieInfo() throws Exception {
|
2016-05-09 10:59:21 -04:00
|
|
|
MovieInfo movie = db.getMovieInfo(new Movie(418279), Locale.ENGLISH, true);
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2011-12-25 06:18:55 -05:00
|
|
|
assertEquals("Transformers", movie.getName());
|
2016-03-07 10:36:13 -05:00
|
|
|
assertEquals("2007-06-27", movie.getReleased().toString());
|
2012-07-24 13:44:54 -04:00
|
|
|
assertEquals("PG-13", movie.getCertification());
|
2016-03-07 10:36:13 -05:00
|
|
|
assertEquals("[es, en]", movie.getSpokenLanguages().toString());
|
2012-07-24 13:44:54 -04:00
|
|
|
assertEquals("Shia LaBeouf", movie.getActors().get(0));
|
|
|
|
assertEquals("Michael Bay", movie.getDirector());
|
|
|
|
}
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2012-07-24 13:44:54 -04:00
|
|
|
@Test
|
|
|
|
public void getArtwork() throws Exception {
|
2016-05-09 10:59:21 -04:00
|
|
|
Artwork a = db.getArtwork(16320, "backdrops", Locale.ROOT).get(0);
|
2016-04-19 06:39:31 -04:00
|
|
|
assertEquals("[backdrops, 1920x1080]", a.getTags().toString());
|
2016-04-17 08:40:37 -04:00
|
|
|
assertEquals("https://image.tmdb.org/t/p/original/424MxHQe5Hfu92hTeRvZb5Giv0X.jpg", a.getUrl().toString());
|
2016-03-26 13:40:59 -04:00
|
|
|
}
|
|
|
|
|
2016-05-09 10:59:21 -04:00
|
|
|
@Test
|
|
|
|
public void getPeople() throws Exception {
|
|
|
|
Person p = db.getMovieInfo("16320", Locale.ENGLISH, true).getPeople().get(0);
|
|
|
|
assertEquals("Nathan Fillion", p.getName());
|
|
|
|
assertEquals("Mal", p.getCharacter());
|
|
|
|
assertEquals(null, p.getJob());
|
|
|
|
assertEquals(null, p.getDepartment());
|
|
|
|
assertEquals("0", p.getOrder().toString());
|
|
|
|
assertEquals("http://image.tmdb.org/t/p/original/B7VTVtnKyFk0AtYjEbqzBQlPec.jpg", p.getImage().toString());
|
|
|
|
}
|
|
|
|
|
2014-05-02 04:00:43 -04:00
|
|
|
@Ignore
|
2012-04-08 04:41:48 -04:00
|
|
|
@Test
|
|
|
|
public void floodLimit() throws Exception {
|
|
|
|
for (Locale it : Locale.getAvailableLocales()) {
|
2016-05-09 10:59:21 -04:00
|
|
|
List<Movie> results = db.searchMovie("Serenity", it);
|
2012-07-24 13:44:54 -04:00
|
|
|
assertEquals(16320, results.get(0).getTmdbId());
|
2012-04-08 04:41:48 -04:00
|
|
|
}
|
|
|
|
}
|
2013-11-18 09:41:19 -05:00
|
|
|
|
2016-03-11 16:26:36 -05:00
|
|
|
@Ignore
|
|
|
|
@Test
|
|
|
|
public void etag() throws Exception {
|
|
|
|
Cache cache = Cache.getCache("test", CacheType.Persistent);
|
|
|
|
Cache etagStorage = Cache.getCache("etag", CacheType.Persistent);
|
2016-03-12 05:01:11 -05:00
|
|
|
CachedResource<String, byte[]> resource = cache.bytes("http://devel.squid-cache.org/old_projects.html#etag", URL::new).fetch(fetchIfNoneMatch(etagStorage::get, etagStorage::put)).expire(Duration.ZERO);
|
2016-03-11 16:26:36 -05:00
|
|
|
assertArrayEquals(resource.get(), resource.get());
|
|
|
|
}
|
|
|
|
|
2009-11-02 18:25:04 -05:00
|
|
|
}
|