1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-05 00:45:06 -05:00

* slightly improved behavior as to when to require manual user input of series name

This commit is contained in:
Reinhard Pointner 2011-08-26 09:46:02 +00:00
parent e1261eadbc
commit ca3fb703b2
2 changed files with 32 additions and 31 deletions

View File

@ -50,28 +50,6 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
}
protected Collection<String> grabSeriesNames(Collection<File> files, boolean autodetect) {
Collection<String> 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<SearchResult> searchResults) throws Exception {
if (searchResults.size() == 1) {
return searchResults.get(0);
@ -175,10 +153,28 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
public List<Match<File, ?>> match(final List<File> files, Locale locale, boolean autodetection) throws Exception {
// focus on movie and subtitle files
List<File> mediaFiles = FileUtilities.filter(files, VIDEO_FILES, SUBTITLE_FILES);
Set<Episode> episodes = emptySet();
// detect series name and fetch episode list
Set<Episode> episodes = fetchEpisodeSet(grabSeriesNames(mediaFiles, autodetection), locale);
if (autodetection) {
Collection<String> 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<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
// group by subtitles first and then by files in general
@ -198,5 +194,4 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
return matches;
}
}

View File

@ -50,12 +50,9 @@ class MovieHashMatcher implements AutoCompleteMatcher {
public List<Match<File, ?>> match(final List<File> 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<MovieDescriptor, SortedSet<File>> filesByMovie = new HashMap<MovieDescriptor, SortedSet<File>>();
@ -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<MovieDescriptor> options = new ArrayList<MovieDescriptor>();
// 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
}
}