* added special handling for subtitles in movie matcher
This commit is contained in:
parent
5519c1440d
commit
6a43ab6e3f
|
@ -22,8 +22,8 @@ class MovieFormatter implements MatchFormatter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String format(Match<?, ?> match) {
|
public String format(Match<?, ?> match) {
|
||||||
MovieDescriptor movie = (MovieDescriptor) match.getValue();
|
// use default format for the time being
|
||||||
return movie.getName();
|
return match.getValue().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,14 @@ package net.sourceforge.filebot.ui.panel.rename;
|
||||||
|
|
||||||
|
|
||||||
import static net.sourceforge.filebot.MediaTypes.*;
|
import static net.sourceforge.filebot.MediaTypes.*;
|
||||||
|
import static net.sourceforge.tuned.FileUtilities.*;
|
||||||
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
import static net.sourceforge.tuned.ui.TunedUtilities.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
|
@ -23,7 +26,6 @@ import net.sourceforge.filebot.similarity.Match;
|
||||||
import net.sourceforge.filebot.ui.SelectDialog;
|
import net.sourceforge.filebot.ui.SelectDialog;
|
||||||
import net.sourceforge.filebot.web.MovieDescriptor;
|
import net.sourceforge.filebot.web.MovieDescriptor;
|
||||||
import net.sourceforge.filebot.web.MovieIdentificationService;
|
import net.sourceforge.filebot.web.MovieIdentificationService;
|
||||||
import net.sourceforge.tuned.FileUtilities;
|
|
||||||
|
|
||||||
|
|
||||||
class MovieHashMatcher implements AutoCompleteMatcher {
|
class MovieHashMatcher implements AutoCompleteMatcher {
|
||||||
|
@ -37,9 +39,9 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Match<File, ?>> match(List<File> files) throws Exception {
|
public List<Match<File, ?>> match(final List<File> files) throws Exception {
|
||||||
// focus on movie and subtitle files
|
// handle movie files
|
||||||
File[] movieFiles = FileUtilities.filter(files, VIDEO_FILES).toArray(new File[0]);
|
File[] movieFiles = filter(files, VIDEO_FILES).toArray(new File[0]);
|
||||||
MovieDescriptor[] movieDescriptors = service.getMovieDescriptors(movieFiles);
|
MovieDescriptor[] movieDescriptors = service.getMovieDescriptors(movieFiles);
|
||||||
|
|
||||||
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
|
List<Match<File, ?>> matches = new ArrayList<Match<File, ?>>();
|
||||||
|
@ -57,6 +59,30 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle subtitle files
|
||||||
|
for (File subtitle : filter(files, SUBTITLE_FILES)) {
|
||||||
|
// check if subtitle corresponds to a movie file (same name, different extension)
|
||||||
|
for (Match<File, ?> movieMatch : matches) {
|
||||||
|
String subtitleName = getName(subtitle);
|
||||||
|
String movieName = getName(movieMatch.getValue());
|
||||||
|
|
||||||
|
if (subtitleName.equalsIgnoreCase(movieName)) {
|
||||||
|
matches.add(new Match<File, Object>(subtitle, movieMatch.getCandidate()));
|
||||||
|
// movie match found, we're done
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// restore original order
|
||||||
|
Collections.sort(matches, new Comparator<Match<File, ?>>() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compare(Match<File, ?> o1, Match<File, ?> o2) {
|
||||||
|
return files.indexOf(o1.getValue()) - files.indexOf(o2.getValue());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
return matches;
|
return matches;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,12 +92,17 @@ class MovieHashMatcher implements AutoCompleteMatcher {
|
||||||
|
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
Scanner scanner = new Scanner(file);
|
Scanner scanner = new Scanner(file);
|
||||||
|
|
||||||
|
try {
|
||||||
|
// scan for imdb id patterns like tt1234567
|
||||||
String imdb = null;
|
String imdb = null;
|
||||||
|
|
||||||
// scan for imdb id patterns like tt1234567
|
|
||||||
while ((imdb = scanner.findWithinHorizon("(?<=tt)\\d{7}", 32 * 1024)) != null) {
|
while ((imdb = scanner.findWithinHorizon("(?<=tt)\\d{7}", 32 * 1024)) != null) {
|
||||||
collection.add(Integer.parseInt(imdb));
|
collection.add(Integer.parseInt(imdb));
|
||||||
}
|
}
|
||||||
|
} finally {
|
||||||
|
scanner.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return collection;
|
return collection;
|
||||||
|
|
Loading…
Reference in New Issue