From f85d706dce6b8d662103840abf1c94a0d7a19f54 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 18 Nov 2013 14:41:19 +0000 Subject: [PATCH] * fix tricky internal DB override TMDb response issue when using non-English language preferences @see http://www.filebot.net/forums/viewtopic.php?f=6&t=1106&p=6797#p6797 --- source/net/sourceforge/filebot/web/Movie.java | 13 +++++-- .../filebot/web/TMDbClientTest.java | 39 ++++++++++--------- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/source/net/sourceforge/filebot/web/Movie.java b/source/net/sourceforge/filebot/web/Movie.java index f34c51f5..c624c8a5 100644 --- a/source/net/sourceforge/filebot/web/Movie.java +++ b/source/net/sourceforge/filebot/web/Movie.java @@ -1,9 +1,10 @@ package net.sourceforge.filebot.web; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; +import java.util.HashSet; import java.util.List; +import java.util.Set; public class Movie extends SearchResult { @@ -66,7 +67,13 @@ public class Movie extends SearchResult { return tmdbId == other.tmdbId; } - return year == other.year && name.equals(other.name); + if (year != other.year) { + return false; + } + + Set intersection = new HashSet(this.getEffectiveNames()); + intersection.retainAll(other.getEffectiveNames()); + return intersection.size() > 0; } return false; @@ -79,7 +86,7 @@ public class Movie extends SearchResult { @Override public int hashCode() { - return Arrays.hashCode(new Object[] { name.toLowerCase(), year }); + return year; } @Override diff --git a/test/net/sourceforge/filebot/web/TMDbClientTest.java b/test/net/sourceforge/filebot/web/TMDbClientTest.java index d0f26768..8e163656 100644 --- a/test/net/sourceforge/filebot/web/TMDbClientTest.java +++ b/test/net/sourceforge/filebot/web/TMDbClientTest.java @@ -1,10 +1,9 @@ - package net.sourceforge.filebot.web; - import static net.sourceforge.filebot.Settings.*; import static org.junit.Assert.*; +import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -13,39 +12,45 @@ import net.sourceforge.filebot.web.TMDbClient.MovieInfo; import org.junit.Test; - public class TMDbClientTest { - + private final TMDbClient tmdb = new TMDbClient(getApplicationProperty("themoviedb.apikey")); - - + @Test public void searchByName() throws Exception { List result = tmdb.searchMovie("Serenity", Locale.CHINESE); Movie movie = result.get(0); - + assertEquals("冲出宁静号", movie.getName()); assertEquals(2005, movie.getYear()); assertEquals(-1, movie.getImdbId()); assertEquals(16320, movie.getTmdbId()); } - - + + @Test + public void searchByNameGermanResults() throws Exception { + List result = tmdb.searchMovie("East of Eden", Locale.GERMAN); + 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()); + } + @Test public void searchByIMDB() throws Exception { Movie movie = tmdb.getMovieDescriptor(418279, Locale.ENGLISH); - + assertEquals("Transformers", movie.getName()); assertEquals(2007, movie.getYear(), 0); assertEquals(418279, movie.getImdbId(), 0); assertEquals(1858, movie.getTmdbId(), 0); } - - + @Test public void getMovieInfo() throws Exception { MovieInfo movie = tmdb.getMovieInfo(new Movie(null, 0, 418279, -1), Locale.ENGLISH); - + assertEquals("Transformers", movie.getName()); assertEquals("2007-07-02", movie.getReleased().toString()); assertEquals("PG-13", movie.getCertification()); @@ -54,16 +59,14 @@ public class TMDbClientTest { assertEquals("Michael Bay", movie.getDirector()); assertEquals("Editor", movie.getCast().get(30).getJob()); } - - + @Test public void getArtwork() throws Exception { List artwork = tmdb.getArtwork("tt0418279"); assertEquals("backdrops", artwork.get(0).getCategory()); assertEquals("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/original/jC4bQLEEcpM8N7BjpkMtP0zPakJ.jpg", artwork.get(0).getUrl().toString()); } - - + @Test public void floodLimit() throws Exception { for (Locale it : Locale.getAvailableLocales()) { @@ -71,5 +74,5 @@ public class TMDbClientTest { assertEquals(16320, results.get(0).getTmdbId()); } } - + }