From f772553b40f4a9324371230aa160f9e2c5ba3223 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Mon, 15 Sep 2014 20:35:13 +0000 Subject: [PATCH] * retrieve pristine language-specific movie object before formatting & renaming --- source/net/filebot/cli/CmdlineOperations.java | 3 ++- source/net/filebot/media/MediaDetection.java | 8 ++++--- .../filebot/ui/rename/MovieHashMatcher.java | 7 ++++--- .../ui/subtitle/SubtitleUploadDialog.java | 4 ++-- .../web/MovieIdentificationService.java | 21 +++++++------------ source/net/filebot/web/OMDbClient.java | 8 +++---- .../net/filebot/web/OpenSubtitlesClient.java | 12 +++++------ source/net/filebot/web/TMDbClient.java | 18 +++++++--------- test/net/filebot/web/OMDbClientTest.java | 10 ++++----- test/net/filebot/web/TMDbClientTest.java | 2 +- 10 files changed, 43 insertions(+), 50 deletions(-) diff --git a/source/net/filebot/cli/CmdlineOperations.java b/source/net/filebot/cli/CmdlineOperations.java index 12d35ab2..00e581cd 100644 --- a/source/net/filebot/cli/CmdlineOperations.java +++ b/source/net/filebot/cli/CmdlineOperations.java @@ -448,7 +448,8 @@ public class CmdlineOperations implements CmdlineInterface { try { // select first element if matches are reliable if (options.size() > 0) { - movie = (Movie) selectSearchResult(null, options, strict).get(0); + // make sure to get the language-specific movie object for the selected option + movie = service.getMovieDescriptor((Movie) selectSearchResult(null, options, strict).get(0), locale); } } catch (Exception e) { CLILogger.log(Level.WARNING, String.format("%s: [%s/%s] %s", e.getClass().getSimpleName(), guessMovieFolder(file) != null ? guessMovieFolder(file).getName() : null, file.getName(), e.getMessage())); diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index 96caafb9..a6a3b67d 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -578,7 +578,7 @@ public class MediaDetection { // lookup by id from nfo file if (queryLookupService != null) { for (int imdbid : grepImdbId(movieFile.getPath())) { - Movie movie = queryLookupService.getMovieDescriptor(imdbid, locale); + Movie movie = queryLookupService.getMovieDescriptor(new Movie(null, 0, imdbid, -1), locale); if (movie != null) { options.add(movie); } @@ -586,7 +586,7 @@ public class MediaDetection { // try to grep imdb id from nfo files for (int imdbid : grepImdbIdFor(movieFile)) { - Movie movie = queryLookupService.getMovieDescriptor(imdbid, locale); + Movie movie = queryLookupService.getMovieDescriptor(new Movie(null, 0, imdbid, -1), locale); if (movie != null) { options.add(movie); } @@ -1239,7 +1239,9 @@ public class MediaDetection { } public static Movie grepMovie(File nfo, MovieIdentificationService resolver, Locale locale) throws Exception { - return resolver.getMovieDescriptor(grepImdbId(new String(readFile(nfo), "UTF-8")).iterator().next(), locale); + String contents = new String(readFile(nfo), "UTF-8"); + int imdbid = grepImdbId(contents).iterator().next(); + return resolver.getMovieDescriptor(new Movie(null, 0, imdbid, -1), locale); } public static SeriesInfo grepSeries(File nfo, Locale locale) throws Exception { diff --git a/source/net/filebot/ui/rename/MovieHashMatcher.java b/source/net/filebot/ui/rename/MovieHashMatcher.java index aca39180..2c4b35ce 100644 --- a/source/net/filebot/ui/rename/MovieHashMatcher.java +++ b/source/net/filebot/ui/rename/MovieHashMatcher.java @@ -217,7 +217,8 @@ class MovieHashMatcher implements AutoCompleteMatcher { File movieFile = it.getKey(); Movie movie = grabMovieName(movieFile, it.getValue(), strict, locale, autodetect, memory, parent); if (movie != null) { - movieByFile.put(movieFile, movie); + // make sure to use language-specific movie object + movieByFile.put(movieFile, service.getMovieDescriptor(movie, locale)); } } } @@ -474,9 +475,9 @@ class MovieHashMatcher implements AutoCompleteMatcher { List> matches = new ArrayList>(); if (input != null && input.length() > 0) { List results = detectMovie(new File(input), null, service, locale, false); - for (Movie it : results) { - matches.add(new Match(null, it)); + // make sure to retrieve language-specific movie descriptor + matches.add(new Match(null, service.getMovieDescriptor(it, locale))); } } return matches; diff --git a/source/net/filebot/ui/subtitle/SubtitleUploadDialog.java b/source/net/filebot/ui/subtitle/SubtitleUploadDialog.java index 3ec39f0e..b108cb85 100644 --- a/source/net/filebot/ui/subtitle/SubtitleUploadDialog.java +++ b/source/net/filebot/ui/subtitle/SubtitleUploadDialog.java @@ -693,7 +693,7 @@ public class SubtitleUploadDialog extends JDialog { SeriesInfo seriesInfo = WebServices.TheTVDB.getSeriesInfo((TheTVDBSearchResult) entry, Locale.ENGLISH); Integer imdbid = seriesInfo.getImdbId(); if (imdbid != null && imdbid > 0) { - mapping.setIdentity(WebServices.OpenSubtitles.getMovieDescriptor(imdbid, Locale.ENGLISH)); + mapping.setIdentity(WebServices.OpenSubtitles.getMovieDescriptor(new Movie(null, 0, imdbid, -1), Locale.ENGLISH)); break; } } @@ -702,7 +702,7 @@ public class SubtitleUploadDialog extends JDialog { Collection identity = MediaDetection.detectMovie(mapping.getVideo(), database, database, Locale.ENGLISH, true); for (Movie it : identity) { if (it.getImdbId() <= 0 && it.getTmdbId() > 0) { - it = WebServices.TheMovieDB.getMovieDescriptor(it.getTmdbId(), false, Locale.ENGLISH, false); + it = WebServices.TheMovieDB.getMovieDescriptor(it, Locale.ENGLISH); } if (it != null && it.getImdbId() > 0) { mapping.setIdentity(it); diff --git a/source/net/filebot/web/MovieIdentificationService.java b/source/net/filebot/web/MovieIdentificationService.java index 71e0a6ee..b3028011 100644 --- a/source/net/filebot/web/MovieIdentificationService.java +++ b/source/net/filebot/web/MovieIdentificationService.java @@ -1,7 +1,5 @@ - package net.filebot.web; - import java.io.File; import java.util.Collection; import java.util.List; @@ -10,21 +8,16 @@ import java.util.Map; import javax.swing.Icon; - public interface MovieIdentificationService { - + public String getName(); - - + public Icon getIcon(); - - + public List searchMovie(String query, Locale locale) throws Exception; - - - public Movie getMovieDescriptor(int imdbid, Locale locale) throws Exception; - - + + public Movie getMovieDescriptor(Movie movie, Locale locale) throws Exception; + public Map getMovieDescriptors(Collection movieFiles, Locale locale) throws Exception; - + } diff --git a/source/net/filebot/web/OMDbClient.java b/source/net/filebot/web/OMDbClient.java index 1bab750c..a0147c8a 100644 --- a/source/net/filebot/web/OMDbClient.java +++ b/source/net/filebot/web/OMDbClient.java @@ -99,13 +99,13 @@ public class OMDbClient implements MovieIdentificationService { } @Override - public Movie getMovieDescriptor(int imdbid, Locale locale) throws Exception { - if (imdbid <= 0) { - throw new IllegalArgumentException("Illegal ID: " + imdbid); + public Movie getMovieDescriptor(Movie id, Locale locale) throws Exception { + if (id.getImdbId() <= 0) { + throw new IllegalArgumentException("Illegal ID: " + id.getImdbId()); } // request full movie info for given id - return getMovie(getMovieInfo(imdbid, null, null, false)); + return getMovie(getMovieInfo(id.getImdbId(), null, null, false)); } public Map getInfoMap(Object node) { diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index c30715a2..e88cebd8 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -396,12 +396,12 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS } @Override - public Movie getMovieDescriptor(int imdbid, Locale locale) throws Exception { - if (imdbid <= 0) { - throw new IllegalArgumentException("id must not be " + imdbid); + public Movie getMovieDescriptor(Movie id, Locale locale) throws Exception { + if (id.getImdbId() <= 0) { + throw new IllegalArgumentException("id must not be " + id.getImdbId()); } - Movie result = getCache().getData("getMovieDescriptor", imdbid, locale, Movie.class); + Movie result = getCache().getData("getMovieDescriptor", id.getImdbId(), locale, Movie.class); if (result != null) { return result; } @@ -409,9 +409,9 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS // require login login(); - Movie movie = xmlrpc.getIMDBMovieDetails(imdbid); + Movie movie = xmlrpc.getIMDBMovieDetails(id.getImdbId()); - getCache().putData("getMovieDescriptor", imdbid, locale, movie); + getCache().putData("getMovieDescriptor", id.getImdbId(), locale, movie); return movie; } diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 73485fa3..4fce1fe5 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -153,24 +153,20 @@ public class TMDbClient implements MovieIdentificationService { } @Override - public Movie getMovieDescriptor(int imdbid, Locale locale) throws IOException { - return getMovieDescriptor(imdbid, true, locale, true); - } - - public Movie getMovieDescriptor(int imdbtmdbid, boolean byIMDB, Locale locale, boolean extendedInfo) throws IOException { - if (imdbtmdbid <= 0) { - throw new IllegalArgumentException("id must not be " + imdbtmdbid); + public Movie getMovieDescriptor(Movie id, Locale locale) throws IOException { + if (id.getImdbId() <= 0 && id.getTmdbId() <= 0) { + throw new IllegalArgumentException("id"); } - String id = byIMDB ? String.format("tt%07d", imdbtmdbid) : String.valueOf(imdbtmdbid); + String identifier = id.getTmdbId() > 0 ? String.valueOf(id.getTmdbId()) : String.format("tt%07d", id.getImdbId()); try { - MovieInfo info = getMovieInfo(id, locale, extendedInfo); + MovieInfo info = getMovieInfo(identifier, locale, false); return new Movie(info.getName(), new String[0], info.getReleased().getYear(), info.getImdbId(), info.getId(), locale); } catch (FileNotFoundException e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, "Movie not found: " + id); + Logger.getLogger(getClass().getName()).log(Level.WARNING, "Movie not found: " + identifier); return null; } catch (NullPointerException e) { - Logger.getLogger(getClass().getName()).log(Level.WARNING, "Movie data missing: " + id); + Logger.getLogger(getClass().getName()).log(Level.WARNING, "Movie data missing: " + identifier); return null; } } diff --git a/test/net/filebot/web/OMDbClientTest.java b/test/net/filebot/web/OMDbClientTest.java index 22715a4e..dbf6bc0d 100644 --- a/test/net/filebot/web/OMDbClientTest.java +++ b/test/net/filebot/web/OMDbClientTest.java @@ -64,7 +64,7 @@ public class OMDbClientTest { @Test public void getMovieDescriptor1() throws Exception { - Movie movie = client.getMovieDescriptor(499549, null); + Movie movie = client.getMovieDescriptor(new Movie(null, 0, 499549, -1), null); assertEquals("Avatar", movie.getName()); assertEquals(2009, movie.getYear()); @@ -73,7 +73,7 @@ public class OMDbClientTest { @Test public void getMovieDescriptor2() throws Exception { - Movie movie = client.getMovieDescriptor(211915, null); + Movie movie = client.getMovieDescriptor(new Movie(null, 0, 211915, -1), null); assertEquals("Amélie", movie.getName()); assertEquals(2001, movie.getYear()); @@ -82,7 +82,7 @@ public class OMDbClientTest { @Test public void getMovieDescriptor3() throws Exception { - Movie movie = client.getMovieDescriptor(75610, null); + Movie movie = client.getMovieDescriptor(new Movie(null, 0, 75610, -1), null); assertEquals("21 Up", movie.getName()); assertEquals(1977, movie.getYear()); @@ -91,7 +91,7 @@ public class OMDbClientTest { @Test public void getMovieDescriptor4() throws Exception { - Movie movie = client.getMovieDescriptor(369702, null); + Movie movie = client.getMovieDescriptor(new Movie(null, 0, 369702, -1), null); assertEquals("The Sea Inside", movie.getName()); assertEquals(2004, movie.getYear()); @@ -100,7 +100,7 @@ public class OMDbClientTest { @Test public void getMovieDescriptor5() throws Exception { - Movie movie = client.getMovieDescriptor(1020960, null); + Movie movie = client.getMovieDescriptor(new Movie(null, 0, 1020960, -1), null); assertEquals("God, the Universe and Everything Else", movie.getName()); assertEquals(1988, movie.getYear()); diff --git a/test/net/filebot/web/TMDbClientTest.java b/test/net/filebot/web/TMDbClientTest.java index 1bfdb7b2..036f84de 100644 --- a/test/net/filebot/web/TMDbClientTest.java +++ b/test/net/filebot/web/TMDbClientTest.java @@ -50,7 +50,7 @@ public class TMDbClientTest { @Test public void searchByIMDB() throws Exception { - Movie movie = tmdb.getMovieDescriptor(418279, Locale.ENGLISH); + Movie movie = tmdb.getMovieDescriptor(new Movie(null, 0, 418279, -1), Locale.ENGLISH); assertEquals("Transformers", movie.getName()); assertEquals(2007, movie.getYear(), 0);