1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 08:48:51 -05:00

Make sure that movie object localization doesn't break anything

This commit is contained in:
Reinhard Pointner 2016-08-08 17:05:23 +08:00
parent 9c3e60f34e
commit 1f6f184e8d
3 changed files with 32 additions and 15 deletions

View File

@ -279,7 +279,7 @@ public class CmdlineOperations implements CmdlineInterface {
return validMatches; return validMatches;
} }
private List<Episode> fetchEpisodeSet(final EpisodeListProvider db, final Collection<String> names, final SortOrder sortOrder, final Locale locale, final boolean strict) throws Exception { private List<Episode> fetchEpisodeSet(EpisodeListProvider db, Collection<String> names, SortOrder sortOrder, Locale locale, boolean strict) throws Exception {
Set<SearchResult> shows = new LinkedHashSet<SearchResult>(); Set<SearchResult> shows = new LinkedHashSet<SearchResult>();
Set<Episode> episodes = new LinkedHashSet<Episode>(); Set<Episode> episodes = new LinkedHashSet<Episode>();
@ -341,7 +341,7 @@ public class CmdlineOperations implements CmdlineInterface {
} }
// match movie hashes online // match movie hashes online
final Map<File, Movie> movieByFile = new TreeMap<File, Movie>(); Map<File, Movie> movieByFile = new TreeMap<File, Movie>();
if (query == null) { if (query == null) {
// collect useful nfo files even if they are not part of the selected fileset // collect useful nfo files even if they are not part of the selected fileset
Set<File> effectiveNfoFileSet = new TreeSet<File>(nfoFiles); Set<File> effectiveNfoFileSet = new TreeSet<File>(nfoFiles);
@ -418,7 +418,7 @@ public class CmdlineOperations implements CmdlineInterface {
Map<Movie, SortedSet<File>> filesByMovie = new HashMap<Movie, SortedSet<File>>(); Map<Movie, SortedSet<File>> filesByMovie = new HashMap<Movie, SortedSet<File>>();
// map all files by movie // map all files by movie
for (final File file : movieMatchFiles) { for (File file : movieMatchFiles) {
Movie movie = movieByFile.get(file); Movie movie = movieByFile.get(file);
// unknown hash, try via imdb id from nfo file // unknown hash, try via imdb id from nfo file
@ -438,8 +438,10 @@ public class CmdlineOperations implements CmdlineInterface {
try { try {
// select first element if matches are reliable // select first element if matches are reliable
if (options.size() > 0) { if (options.size() > 0) {
movie = (Movie) selectSearchResult(null, options, false, strict).get(0);
// make sure to get the language-specific movie object for the selected option // make sure to get the language-specific movie object for the selected option
movie = service.getMovieDescriptor((Movie) selectSearchResult(null, options, false, strict).get(0), locale); movie = getLocalizedMovie(service, movie, locale);
} }
} catch (Exception e) { } catch (Exception e) {
log.log(Level.WARNING, format("%s: [%s] %s", e.getClass().getSimpleName(), getStructurePathTail(file), e.getMessage())); log.log(Level.WARNING, format("%s: [%s] %s", e.getClass().getSimpleName(), getStructurePathTail(file), e.getMessage()));
@ -1108,15 +1110,15 @@ public class CmdlineOperations implements CmdlineInterface {
outputFolder = outputFolder.getCanonicalFile(); // normalize weird paths outputFolder = outputFolder.getCanonicalFile(); // normalize weird paths
log.info(format("Read archive [%s] and extract to [%s]", file.getName(), outputFolder)); log.info(format("Read archive [%s] and extract to [%s]", file.getName(), outputFolder));
final FileMapper outputMapper = new FileMapper(outputFolder); FileMapper outputMapper = new FileMapper(outputFolder);
final List<FileInfo> outputMapping = new ArrayList<FileInfo>(); List<FileInfo> outputMapping = new ArrayList<FileInfo>();
for (FileInfo it : archive.listFiles()) { for (FileInfo it : archive.listFiles()) {
File outputPath = outputMapper.getOutputFile(it.toFile()); File outputPath = outputMapper.getOutputFile(it.toFile());
outputMapping.add(new SimpleFileInfo(outputPath.getPath(), it.getLength())); outputMapping.add(new SimpleFileInfo(outputPath.getPath(), it.getLength()));
} }
final Set<FileInfo> selection = new TreeSet<FileInfo>(); Set<FileInfo> selection = new TreeSet<FileInfo>();
for (FileInfo future : outputMapping) { for (FileInfo future : outputMapping) {
if (filter == null || filter.accept(future.toFile())) { if (filter == null || filter.accept(future.toFile())) {
selection.add(future); selection.add(future);

View File

@ -698,6 +698,19 @@ public class MediaDetection {
}); });
} }
public static Movie getLocalizedMovie(MovieIdentificationService service, Movie movie, Locale locale) throws Exception {
// retrieve language-specific movie object if possible
try {
Movie localized = service.getMovieDescriptor(movie, locale);
if (localized != null) {
return localized;
}
} catch (Exception e) {
debug.log(Level.WARNING, "Failed to retrieve localized movie data", e);
}
return movie;
}
public static SimilarityMetric getSeriesMatchMetric() { public static SimilarityMetric getSeriesMatchMetric() {
return new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric(), new SequenceMatchSimilarity(0, true)); return new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric(), new SequenceMatchSimilarity(0, true));
} }

View File

@ -176,12 +176,15 @@ class MovieMatcher implements AutoCompleteMatcher {
for (Future<Map<File, List<Movie>>> future : tasks) { for (Future<Map<File, List<Movie>>> future : tasks) {
for (Entry<File, List<Movie>> it : future.get().entrySet()) { for (Entry<File, List<Movie>> it : future.get().entrySet()) {
// auto-select movie or ask user File file = it.getKey();
Movie movie = grabMovieName(it.getKey(), it.getValue(), strict, locale, autodetect, parent); List<Movie> options = it.getValue();
// make sure to use language-specific movie object // auto-select movie or ask user
Movie movie = grabMovieName(file, options, strict, locale, autodetect, parent);
// make sure to use language-specific movie object if possible
if (movie != null) { if (movie != null) {
movieByFile.put(it.getKey(), service.getMovieDescriptor(movie, locale)); movieByFile.put(file, getLocalizedMovie(service, movie, locale));
} }
} }
} }
@ -410,10 +413,9 @@ class MovieMatcher implements AutoCompleteMatcher {
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>(); List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
if (input != null && input.length() > 0) { if (input != null && input.length() > 0) {
List<Movie> results = detectMovie(new File(input), service, locale, false); for (Movie movie : detectMovie(new File(input), service, locale, false)) {
for (Movie it : results) { // make sure to use language-specific movie object if possible
// make sure to retrieve language-specific movie descriptor matches.add(new Match<File, Movie>(null, getLocalizedMovie(service, movie, locale)));
matches.add(new Match<File, Movie>(null, service.getMovieDescriptor(it, locale)));
} }
} }
return matches; return matches;