1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-11-10 11:25:04 -05:00

* refactor subtitle lookup code

This commit is contained in:
Reinhard Pointner 2015-05-11 11:58:31 +00:00
parent 97c9643871
commit d1c6ef75a8
6 changed files with 25 additions and 7 deletions

View File

@ -200,7 +200,7 @@ public final class WebServices {
}
@Override
public synchronized List<SubtitleSearchResult> search(final String query, final boolean byMovie, final boolean bySeries) throws Exception {
public synchronized List<SubtitleSearchResult> search(final String query) throws Exception {
List<SubtitleSearchResult> results = getLocalIndex().search(query);
return sortBySimilarity(results, singleton(query), new MetricAvg(getSeriesMatchMetric(), getMovieMatchMetric()), false);

View File

@ -29,6 +29,7 @@ import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Stream;
import net.filebot.Language;
import net.filebot.similarity.EpisodeMetrics;
@ -196,7 +197,12 @@ public final class SubtitleUtilities {
// search for and automatically select movie / show entry
Set<SubtitleSearchResult> resultSet = new HashSet<SubtitleSearchResult>();
for (String query : querySet) {
resultSet.addAll(findProbableSearchResults(query, service.search(query, searchByMovie, searchBySeries), querySet.size() == 1 ? 4 : 2));
// search and filter by movie/series as required
Stream<SubtitleSearchResult> searchResults = service.search(query).stream().filter((it) -> {
return (searchByMovie && it.isMovie()) || (searchBySeries && it.isSeries());
});
resultSet.addAll(findProbableSearchResults(query, searchResults::iterator, querySet.size() == 1 ? 4 : 2));
}
// fetch subtitles for all search results

View File

@ -151,8 +151,12 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
protected Collection<String> getHistory(SubtitleProvider engine) throws Exception {
List<String> names = new ArrayList<String>();
for (SearchResult it : MediaDetection.releaseInfo.getOpenSubtitlesIndex()) {
names.addAll(it.getEffectiveNames());
for (SubtitleSearchResult it : MediaDetection.releaseInfo.getOpenSubtitlesIndex()) {
if (it.isMovie()) {
names.add(it.getNameWithYear());
} else if (it.isSeries()) {
names.add(it.getName());
}
}
return names;
};
@ -220,7 +224,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
@Override
public Collection<SubtitleSearchResult> search() throws Exception {
return request.getProvider().search(request.getSearchText(), true, true);
return request.getProvider().search(request.getSearchText());
}
@Override

View File

@ -88,7 +88,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
}
@Override
public synchronized List<SubtitleSearchResult> search(String query, boolean byMovie, boolean bySeries) throws Exception {
public synchronized List<SubtitleSearchResult> search(String query) throws Exception {
throw new UnsupportedOperationException(); // XMLRPC::SearchMoviesOnIMDB is not allowed due to abuse
}

View File

@ -7,7 +7,7 @@ import javax.swing.Icon;
public interface SubtitleProvider {
public List<SubtitleSearchResult> search(String query, boolean byMovie, boolean bySeries) throws Exception;
public List<SubtitleSearchResult> search(String query) throws Exception;
public List<SubtitleDescriptor> getSubtitleList(SubtitleSearchResult searchResult, String languageName) throws Exception;

View File

@ -25,4 +25,12 @@ public class SubtitleSearchResult extends Movie {
return score;
}
public boolean isMovie() {
return kind == KIND_MOVIE;
}
public boolean isSeries() {
return kind == KIND_SERIES;
}
}