From ca3fb703b2c43c14ac95fd295f5eeeb8a9888185 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 26 Aug 2011 09:46:02 +0000 Subject: [PATCH] * slightly improved behavior as to when to require manual user input of series name --- .../ui/panel/rename/EpisodeListMatcher.java | 43 ++++++++----------- .../ui/panel/rename/MovieHashMatcher.java | 20 ++++++--- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/source/net/sourceforge/filebot/ui/panel/rename/EpisodeListMatcher.java b/source/net/sourceforge/filebot/ui/panel/rename/EpisodeListMatcher.java index 18fe242a..7ebaeeb2 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/EpisodeListMatcher.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/EpisodeListMatcher.java @@ -50,28 +50,6 @@ class EpisodeListMatcher implements AutoCompleteMatcher { } - protected Collection grabSeriesNames(Collection files, boolean autodetect) { - Collection names = null; - - // auto-detect series name(s) from files - if (autodetect) { - names = new SeriesNameMatcher().matchAll(files.toArray(new File[0])); - } - - // require user input if auto-detection fails - if (names == null || names.isEmpty()) { - String suggestion = new SeriesNameMatcher().matchBySeasonEpisodePattern(getName(files.iterator().next())); - String input = showInputDialog(null, "Enter series name:", suggestion); - - if (input != null) { - names = singleton(input); - } - } - - return names; - } - - protected SearchResult selectSearchResult(final String query, final List searchResults) throws Exception { if (searchResults.size() == 1) { return searchResults.get(0); @@ -175,10 +153,28 @@ class EpisodeListMatcher implements AutoCompleteMatcher { public List> match(final List files, Locale locale, boolean autodetection) throws Exception { // focus on movie and subtitle files List mediaFiles = FileUtilities.filter(files, VIDEO_FILES, SUBTITLE_FILES); + Set episodes = emptySet(); // detect series name and fetch episode list - Set episodes = fetchEpisodeSet(grabSeriesNames(mediaFiles, autodetection), locale); + if (autodetection) { + Collection names = new SeriesNameMatcher().matchAll(files.toArray(new File[0])); + + if (names.size() > 0) { + episodes = fetchEpisodeSet(names, locale); + } + } + // require user input if auto-detection has failed or has been disabled + if (episodes.isEmpty()) { + String suggestion = new SeriesNameMatcher().matchBySeasonEpisodePattern(getName(files.iterator().next())); + String input = showInputDialog(null, "Enter series name:", suggestion); + + if (input != null) { + episodes = fetchEpisodeSet(singleton(input), locale); + } + } + + // find file/episode matches List> matches = new ArrayList>(); // group by subtitles first and then by files in general @@ -198,5 +194,4 @@ class EpisodeListMatcher implements AutoCompleteMatcher { return matches; } - } diff --git a/source/net/sourceforge/filebot/ui/panel/rename/MovieHashMatcher.java b/source/net/sourceforge/filebot/ui/panel/rename/MovieHashMatcher.java index 970a0993..5acffc59 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/MovieHashMatcher.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/MovieHashMatcher.java @@ -50,12 +50,9 @@ class MovieHashMatcher implements AutoCompleteMatcher { public List> match(final List files, Locale locale, boolean autodetect) throws Exception { // handle movie files File[] movieFiles = filter(files, VIDEO_FILES).toArray(new File[0]); - MovieDescriptor[] movieByFileHash = new MovieDescriptor[movieFiles.length]; // match movie hashes online - if (autodetect) { - movieByFileHash = service.getMovieDescriptors(movieFiles, locale); - } + MovieDescriptor[] movieByFileHash = service.getMovieDescriptors(movieFiles, locale); // map movies to (possibly multiple) files (in natural order) Map> filesByMovie = new HashMap>(); @@ -65,8 +62,8 @@ class MovieHashMatcher implements AutoCompleteMatcher { MovieDescriptor movie = movieByFileHash[i]; // unknown hash, try via imdb id from nfo file - if (movie == null) { - movie = grabMovieName(movieFiles[i], locale, autodetect); + if (movie == null || !autodetect) { + movie = grabMovieName(movieFiles[i], locale, autodetect, movie); } // check if we managed to lookup the movie descriptor @@ -153,9 +150,16 @@ class MovieHashMatcher implements AutoCompleteMatcher { } - protected MovieDescriptor grabMovieName(File movieFile, Locale locale, boolean autodetect) throws Exception { + protected MovieDescriptor grabMovieName(File movieFile, Locale locale, boolean autodetect, MovieDescriptor... suggestions) throws Exception { List options = new ArrayList(); + // add default value if any + for (MovieDescriptor it : suggestions) { + if (it != null) { + options.add(it); + } + } + // try to grep imdb id from nfo files for (int imdbid : grepImdbId(movieFile.getParentFile().listFiles(getDefaultFilter("application/nfo")))) { MovieDescriptor movie = service.getMovieDescriptor(imdbid, locale); @@ -179,6 +183,8 @@ class MovieHashMatcher implements AutoCompleteMatcher { if (input != null) { options = service.searchMovie(input, locale); + } else { + options.clear(); // cancel search } }