mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-10 19:35:15 -05:00
* refactor subtitle lookup code
This commit is contained in:
parent
97c9643871
commit
d1c6ef75a8
@ -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);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user