* retrieve pristine language-specific movie object before formatting & renaming

This commit is contained in:
Reinhard Pointner 2014-09-15 20:35:13 +00:00
parent e3117e0395
commit f772553b40
10 changed files with 43 additions and 50 deletions

View File

@ -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()));

View File

@ -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 {

View File

@ -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<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
if (input != null && input.length() > 0) {
List<Movie> results = detectMovie(new File(input), null, service, locale, false);
for (Movie it : results) {
matches.add(new Match<File, Movie>(null, it));
// make sure to retrieve language-specific movie descriptor
matches.add(new Match<File, Movie>(null, service.getMovieDescriptor(it, locale)));
}
}
return matches;

View File

@ -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<Movie> 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);

View File

@ -1,7 +1,5 @@
package net.filebot.web;
import java.io.File;
import java.util.Collection;
import java.util.List;
@ -10,20 +8,15 @@ import java.util.Map;
import javax.swing.Icon;
public interface MovieIdentificationService {
public String getName();
public Icon getIcon();
public List<Movie> 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<File, Movie> getMovieDescriptors(Collection<File> movieFiles, Locale locale) throws Exception;

View File

@ -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<String, String> getInfoMap(Object node) {

View File

@ -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;
}

View File

@ -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(Movie id, Locale locale) throws IOException {
if (id.getImdbId() <= 0 && id.getTmdbId() <= 0) {
throw new IllegalArgumentException("id");
}
public Movie getMovieDescriptor(int imdbtmdbid, boolean byIMDB, Locale locale, boolean extendedInfo) throws IOException {
if (imdbtmdbid <= 0) {
throw new IllegalArgumentException("id must not be " + imdbtmdbid);
}
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;
}
}

View File

@ -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());

View File

@ -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);