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:
parent
97c9643871
commit
d1c6ef75a8
@ -200,7 +200,7 @@ public final class WebServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
List<SubtitleSearchResult> results = getLocalIndex().search(query);
|
||||||
|
|
||||||
return sortBySimilarity(results, singleton(query), new MetricAvg(getSeriesMatchMetric(), getMovieMatchMetric()), false);
|
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.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import net.filebot.Language;
|
import net.filebot.Language;
|
||||||
import net.filebot.similarity.EpisodeMetrics;
|
import net.filebot.similarity.EpisodeMetrics;
|
||||||
@ -196,7 +197,12 @@ public final class SubtitleUtilities {
|
|||||||
// search for and automatically select movie / show entry
|
// search for and automatically select movie / show entry
|
||||||
Set<SubtitleSearchResult> resultSet = new HashSet<SubtitleSearchResult>();
|
Set<SubtitleSearchResult> resultSet = new HashSet<SubtitleSearchResult>();
|
||||||
for (String query : querySet) {
|
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
|
// 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 {
|
protected Collection<String> getHistory(SubtitleProvider engine) throws Exception {
|
||||||
List<String> names = new ArrayList<String>();
|
List<String> names = new ArrayList<String>();
|
||||||
for (SearchResult it : MediaDetection.releaseInfo.getOpenSubtitlesIndex()) {
|
for (SubtitleSearchResult it : MediaDetection.releaseInfo.getOpenSubtitlesIndex()) {
|
||||||
names.addAll(it.getEffectiveNames());
|
if (it.isMovie()) {
|
||||||
|
names.add(it.getNameWithYear());
|
||||||
|
} else if (it.isSeries()) {
|
||||||
|
names.add(it.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return names;
|
return names;
|
||||||
};
|
};
|
||||||
@ -220,7 +224,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SubtitleSearchResult> search() throws Exception {
|
public Collection<SubtitleSearchResult> search() throws Exception {
|
||||||
return request.getProvider().search(request.getSearchText(), true, true);
|
return request.getProvider().search(request.getSearchText());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -88,7 +88,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
throw new UnsupportedOperationException(); // XMLRPC::SearchMoviesOnIMDB is not allowed due to abuse
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@ import javax.swing.Icon;
|
|||||||
|
|
||||||
public interface SubtitleProvider {
|
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;
|
public List<SubtitleDescriptor> getSubtitleList(SubtitleSearchResult searchResult, String languageName) throws Exception;
|
||||||
|
|
||||||
|
@ -25,4 +25,12 @@ public class SubtitleSearchResult extends Movie {
|
|||||||
return score;
|
return score;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMovie() {
|
||||||
|
return kind == KIND_MOVIE;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSeries() {
|
||||||
|
return kind == KIND_SERIES;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user