* refactor

This commit is contained in:
Reinhard Pointner 2011-12-31 10:21:58 +00:00
parent 2734278249
commit 07fd0a0e89
7 changed files with 29 additions and 14 deletions

View File

@ -297,7 +297,7 @@ public class CmdlineOperations implements CmdlineInterface {
// unknown hash, try via imdb id from nfo file
if (movie == null) {
Collection<Movie> results = detectMovie(movieFiles[i], service, locale, strict);
Collection<Movie> results = detectMovie(movieFiles[i], null, service, locale, strict);
movie = (Movie) selectSearchResult(query, results, strict).get(0);
if (movie != null) {

View File

@ -148,7 +148,12 @@ def parseDate(path) {
def detectSeriesName(files) {
def names = MediaDetection.detectSeriesNames(files.findAll { it.isVideo() || it.isSubtitle() })
return names == null || names.isEmpty() ? null : names[0]
return names == null || names.isEmpty() ? null : names.toList()[0]
}
def detectMovie(movieFile, strict = false) {
def movies = MediaDetection.detectMovie(movieFile, OpenSubtitles, TheMovieDB, Locale.ENGLISH, strict)
return movies == null || movies.isEmpty() ? null : movies.toList()[0]
}
def similarity(o1, o2) {

View File

@ -145,19 +145,29 @@ public class MediaDetection {
}
public static Collection<Movie> detectMovie(File movieFile, MovieIdentificationService service, Locale locale, boolean strict) throws Exception {
public static Collection<Movie> detectMovie(File movieFile, MovieIdentificationService hashLookupService, MovieIdentificationService queryLookupService, Locale locale, boolean strict) throws Exception {
Set<Movie> options = new LinkedHashSet<Movie>();
// try to grep imdb id from nfo files
for (int imdbid : grepImdbIdFor(movieFile)) {
Movie movie = service.getMovieDescriptor(imdbid, locale);
if (movie != null) {
options.add(movie);
if (hashLookupService != null) {
for (Movie movie : hashLookupService.getMovieDescriptors(new File[] { movieFile }, locale)) {
if (movie != null) {
options.add(movie);
}
}
}
if (!strict && options.isEmpty()) {
if (queryLookupService != null) {
// try to grep imdb id from nfo files
for (int imdbid : grepImdbIdFor(movieFile)) {
Movie movie = queryLookupService.getMovieDescriptor(imdbid, locale);
if (movie != null) {
options.add(movie);
}
}
}
if (queryLookupService != null && !strict && options.isEmpty()) {
// search by file name or folder name
Collection<String> searchQueries = new LinkedHashSet<String>();
searchQueries.add(getName(movieFile));
@ -169,7 +179,7 @@ public class MediaDetection {
final SimilarityMetric metric = new NameSimilarityMetric();
final Map<Movie, Float> probabilityMap = new LinkedHashMap<Movie, Float>();
for (String query : searchQueries) {
for (Movie movie : service.searchMovie(query, locale)) {
for (Movie movie : queryLookupService.searchMovie(query, locale)) {
probabilityMap.put(movie, metric.getSimilarity(query, movie));
}
}

View File

@ -133,7 +133,7 @@ public class ReleaseInfo {
// fetch release group names online and try to update the data every other day
protected final PatternResource releaseGroupResource = new PatternResource(getBundle(getClass().getName()).getString("url.release-groups"));
protected final PatternResource blacklistResource = new PatternResource(getBundle(getClass().getName()).getString("url.term-blacklist"));
protected final PatternResource blacklistResource = new PatternResource(getBundle(getClass().getName()).getString("url.query-blacklist"));
protected static class PatternResource extends CachedResource<String[]> {

View File

@ -8,4 +8,4 @@ pattern.video.format: DivX|Xvid|AVC|x264|h264|3ivx|mpeg|mpeg4|mp3|aac|ac3|2ch|6c
url.release-groups: http://filebot.sourceforge.net/data/release-groups.txt
# blacklisted terms that will be ignored
url.term-blacklist: http://filebot.sourceforge.net/data/term-blacklist.txt
url.term-blacklist: http://filebot.sourceforge.net/data/query-blacklist.txt

View File

@ -153,7 +153,7 @@ class MovieHashMatcher implements AutoCompleteMatcher {
}
// auto-detect movie from nfo or folder / file name
options.addAll(detectMovie(movieFile, service, locale, false));
options.addAll(detectMovie(movieFile, null, service, locale, false));
// allow manual user input
if (options.isEmpty() || !autodetect) {