* fall back to year field if exact release date in unavailable

This commit is contained in:
Reinhard Pointner 2013-09-03 12:24:43 +00:00
parent d1b80b825c
commit 7305b0f939
2 changed files with 47 additions and 49 deletions

View File

@ -231,6 +231,11 @@ public class IMDbClient implements MovieIdentificationService {
Date released = Date.parse(data.get("released"), "dd MMM yyyy"); Date released = Date.parse(data.get("released"), "dd MMM yyyy");
if (released != null) { if (released != null) {
fields.put(MovieProperty.release_date, released.format("yyyy-MM-dd")); fields.put(MovieProperty.release_date, released.format("yyyy-MM-dd"));
} else {
Date year = Date.parse(data.get("year"), "yyyy");
if (year != null) {
fields.put(MovieProperty.release_date, year.format("yyyy-MM-dd"));
}
} }
List<String> genres = new ArrayList<String>(); List<String> genres = new ArrayList<String>();

View File

@ -1,20 +1,18 @@
package net.sourceforge.filebot.web; package net.sourceforge.filebot.web;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import org.junit.Test; import net.sourceforge.filebot.web.TMDbClient.MovieInfo;
import org.junit.Test;
public class IMDbClientTest { public class IMDbClientTest {
private final IMDbClient imdb = new IMDbClient(); private final IMDbClient imdb = new IMDbClient();
@Test @Test
public void searchMovie1() throws Exception { public void searchMovie1() throws Exception {
List<Movie> results = imdb.searchMovie("Avatar", null); List<Movie> results = imdb.searchMovie("Avatar", null);
@ -25,7 +23,6 @@ public class IMDbClientTest {
assertEquals(499549, movie.getImdbId(), 0); assertEquals(499549, movie.getImdbId(), 0);
} }
@Test @Test
public void searchMovie2() throws Exception { public void searchMovie2() throws Exception {
List<Movie> results = imdb.searchMovie("The Illusionist", null); List<Movie> results = imdb.searchMovie("The Illusionist", null);
@ -36,7 +33,6 @@ public class IMDbClientTest {
assertEquals(443543, movie.getImdbId(), 0); assertEquals(443543, movie.getImdbId(), 0);
} }
@Test @Test
public void searchMovie3() throws Exception { public void searchMovie3() throws Exception {
List<Movie> results = imdb.searchMovie("Amélie", null); List<Movie> results = imdb.searchMovie("Amélie", null);
@ -47,7 +43,6 @@ public class IMDbClientTest {
assertEquals(211915, movie.getImdbId(), 0); assertEquals(211915, movie.getImdbId(), 0);
} }
@Test @Test
public void searchMovie4() throws Exception { public void searchMovie4() throws Exception {
List<Movie> results = imdb.searchMovie("Heat", null); List<Movie> results = imdb.searchMovie("Heat", null);
@ -58,7 +53,6 @@ public class IMDbClientTest {
assertEquals(113277, movie.getImdbId(), 0); assertEquals(113277, movie.getImdbId(), 0);
} }
@Test @Test
public void searchMovie5() throws Exception { public void searchMovie5() throws Exception {
List<Movie> results = imdb.searchMovie("Det sjunde inseglet", null); List<Movie> results = imdb.searchMovie("Det sjunde inseglet", null);
@ -69,7 +63,6 @@ public class IMDbClientTest {
assertEquals(50976, movie.getImdbId(), 0); assertEquals(50976, movie.getImdbId(), 0);
} }
@Test @Test
public void searchMovie6() throws Exception { public void searchMovie6() throws Exception {
List<Movie> results = imdb.searchMovie("Drive 2011", null); List<Movie> results = imdb.searchMovie("Drive 2011", null);
@ -80,7 +73,6 @@ public class IMDbClientTest {
assertEquals(780504, movie.getImdbId(), 0); assertEquals(780504, movie.getImdbId(), 0);
} }
@Test @Test
public void searchMovieRedirect() throws Exception { public void searchMovieRedirect() throws Exception {
List<Movie> results = imdb.searchMovie("(500) Days of Summer (2009)", null); List<Movie> results = imdb.searchMovie("(500) Days of Summer (2009)", null);
@ -92,7 +84,6 @@ public class IMDbClientTest {
assertEquals(1022603, movie.getImdbId(), 0); assertEquals(1022603, movie.getImdbId(), 0);
} }
@Test @Test
public void getMovieDescriptor1() throws Exception { public void getMovieDescriptor1() throws Exception {
Movie movie = imdb.getMovieDescriptor(499549, null); Movie movie = imdb.getMovieDescriptor(499549, null);
@ -102,7 +93,6 @@ public class IMDbClientTest {
assertEquals(499549, movie.getImdbId(), 0); assertEquals(499549, movie.getImdbId(), 0);
} }
@Test @Test
public void getMovieDescriptor2() throws Exception { public void getMovieDescriptor2() throws Exception {
Movie movie = imdb.getMovieDescriptor(211915, null); Movie movie = imdb.getMovieDescriptor(211915, null);
@ -112,7 +102,6 @@ public class IMDbClientTest {
assertEquals(211915, movie.getImdbId(), 0); assertEquals(211915, movie.getImdbId(), 0);
} }
@Test @Test
public void getMovieDescriptor3() throws Exception { public void getMovieDescriptor3() throws Exception {
Movie movie = imdb.getMovieDescriptor(75610, null); Movie movie = imdb.getMovieDescriptor(75610, null);
@ -122,7 +111,6 @@ public class IMDbClientTest {
assertEquals(75610, movie.getImdbId(), 0); assertEquals(75610, movie.getImdbId(), 0);
} }
@Test @Test
public void getMovieDescriptor4() throws Exception { public void getMovieDescriptor4() throws Exception {
Movie movie = imdb.getMovieDescriptor(369702, null); Movie movie = imdb.getMovieDescriptor(369702, null);
@ -132,7 +120,6 @@ public class IMDbClientTest {
assertEquals(369702, movie.getImdbId(), 0); assertEquals(369702, movie.getImdbId(), 0);
} }
@Test @Test
public void getMovieDescriptor5() throws Exception { public void getMovieDescriptor5() throws Exception {
Movie movie = imdb.getMovieDescriptor(1020960, null); Movie movie = imdb.getMovieDescriptor(1020960, null);
@ -142,7 +129,6 @@ public class IMDbClientTest {
assertEquals(1020960, movie.getImdbId(), 0); assertEquals(1020960, movie.getImdbId(), 0);
} }
@Test @Test
public void getAkaMovieDescriptor() throws Exception { public void getAkaMovieDescriptor() throws Exception {
Movie movie = imdb.getMovieDescriptor(106559, Locale.ENGLISH); Movie movie = imdb.getMovieDescriptor(106559, Locale.ENGLISH);
@ -152,7 +138,6 @@ public class IMDbClientTest {
assertEquals(106559, movie.getImdbId(), 0); assertEquals(106559, movie.getImdbId(), 0);
} }
@Test @Test
public void getAkaMovieDescriptorExtra() throws Exception { public void getAkaMovieDescriptorExtra() throws Exception {
Movie movie = imdb.getMovieDescriptor(470761, Locale.ENGLISH); Movie movie = imdb.getMovieDescriptor(470761, Locale.ENGLISH);
@ -162,4 +147,12 @@ public class IMDbClientTest {
assertEquals(470761, movie.getImdbId(), 0); assertEquals(470761, movie.getImdbId(), 0);
} }
@Test
public void getImdbApiMovieInfoReleasedNA() throws Exception {
MovieInfo movie = imdb.getImdbApiMovieInfo(new Movie(null, -1, 1287357, -1));
assertEquals("Sommersonntag", movie.getName());
assertEquals(2008, movie.getReleased().getYear());
assertEquals("2008-01-01", movie.getReleased().toString());
}
} }