diff --git a/source/net/filebot/WebServices.java b/source/net/filebot/WebServices.java index 281a7343..5e5543e4 100644 --- a/source/net/filebot/WebServices.java +++ b/source/net/filebot/WebServices.java @@ -32,9 +32,9 @@ import net.filebot.web.MovieIdentificationService; import net.filebot.web.MusicIdentificationService; import net.filebot.web.OMDbClient; import net.filebot.web.OpenSubtitlesClient; -import net.filebot.web.OpenSubtitlesSearchResult; import net.filebot.web.SearchResult; import net.filebot.web.SubtitleProvider; +import net.filebot.web.SubtitleSearchResult; import net.filebot.web.TMDbClient; import net.filebot.web.TVRageClient; import net.filebot.web.TheTVDBClient; @@ -179,18 +179,18 @@ public final class WebServices { } // index of local OpenSubtitles data dump - private static LocalSearch localIndex; + private static LocalSearch localIndex; - public synchronized LocalSearch getLocalIndex() throws IOException { + public synchronized LocalSearch getLocalIndex() throws IOException { if (localIndex == null) { // fetch data dump - OpenSubtitlesSearchResult[] data = releaseInfo.getOpenSubtitlesIndex(); + SubtitleSearchResult[] data = releaseInfo.getOpenSubtitlesIndex(); // index data dump - localIndex = new LocalSearch(asList(data)) { + localIndex = new LocalSearch(asList(data)) { @Override - protected Set getFields(SearchResult object) { + protected Set getFields(SubtitleSearchResult object) { return set(object.getEffectiveNames()); } }; @@ -200,8 +200,8 @@ public final class WebServices { } @Override - public synchronized List search(final String query, final boolean byMovie, final boolean bySeries) throws Exception { - List results = getLocalIndex().search(query); + public synchronized List search(final String query, final boolean byMovie, final boolean bySeries) throws Exception { + List results = getLocalIndex().search(query); return sortBySimilarity(results, singleton(query), new MetricAvg(getSeriesMatchMetric(), getMovieMatchMetric()), false); } diff --git a/source/net/filebot/media/ReleaseInfo.java b/source/net/filebot/media/ReleaseInfo.java index 3cdbd5a6..f2f391e4 100644 --- a/source/net/filebot/media/ReleaseInfo.java +++ b/source/net/filebot/media/ReleaseInfo.java @@ -36,7 +36,7 @@ import net.filebot.util.FileUtilities.RegexFileFilter; import net.filebot.web.AnidbSearchResult; import net.filebot.web.CachedResource; import net.filebot.web.Movie; -import net.filebot.web.OpenSubtitlesSearchResult; +import net.filebot.web.SubtitleSearchResult; import net.filebot.web.TheTVDBSearchResult; import org.tukaani.xz.XZInputStream; @@ -306,7 +306,7 @@ public class ReleaseInfo { return anidbIndexResource.get(); } - public OpenSubtitlesSearchResult[] getOpenSubtitlesIndex() throws IOException { + public SubtitleSearchResult[] getOpenSubtitlesIndex() throws IOException { return osdbIndexResource.get(); } @@ -354,7 +354,7 @@ public class ReleaseInfo { protected final CachedResource seriesDirectMappingsResource = new PatternResource(getProperty("url.series-mappings")); protected final CachedResource tvdbIndexResource = new TheTVDBIndexResource(getProperty("url.thetvdb-index")); protected final CachedResource anidbIndexResource = new AnidbIndexResource(getProperty("url.anidb-index")); - protected final CachedResource osdbIndexResource = new OpenSubtitlesIndexResource(getProperty("url.osdb-index")); + protected final CachedResource osdbIndexResource = new OpenSubtitlesIndexResource(getProperty("url.osdb-index")); protected String getProperty(String propertyName) { // allow override via Java System properties @@ -441,16 +441,16 @@ public class ReleaseInfo { } } - protected static class OpenSubtitlesIndexResource extends CachedResource { + protected static class OpenSubtitlesIndexResource extends CachedResource { public OpenSubtitlesIndexResource(String resource) { - super(resource, OpenSubtitlesSearchResult[].class, ONE_MONTH); // check for updates every month + super(resource, SubtitleSearchResult[].class, ONE_MONTH); // check for updates every month } @Override - public OpenSubtitlesSearchResult[] process(ByteBuffer data) throws IOException { + public SubtitleSearchResult[] process(ByteBuffer data) throws IOException { List rows = readCSV(new XZInputStream(new ByteBufferInputStream(data)), "UTF-8", "\t"); - List result = new ArrayList(rows.size()); + List result = new ArrayList(rows.size()); for (String[] row : rows) { int imdbid = parseInt(row[0]); @@ -458,10 +458,10 @@ public class ReleaseInfo { int year = parseInt(row[2]); char kind = row[3].charAt(0); int score = parseInt(row[4]); - result.add(new OpenSubtitlesSearchResult(imdbid, name, year, kind, score)); + result.add(new SubtitleSearchResult(imdbid, name, year, kind, score)); } - return result.toArray(new OpenSubtitlesSearchResult[0]); + return result.toArray(new SubtitleSearchResult[0]); } } diff --git a/source/net/filebot/subtitle/SubtitleUtilities.java b/source/net/filebot/subtitle/SubtitleUtilities.java index 56e128e6..6f0ce2d4 100644 --- a/source/net/filebot/subtitle/SubtitleUtilities.java +++ b/source/net/filebot/subtitle/SubtitleUtilities.java @@ -42,9 +42,9 @@ import net.filebot.similarity.SimilarityMetric; import net.filebot.vfs.ArchiveType; import net.filebot.vfs.MemoryFile; import net.filebot.web.Movie; -import net.filebot.web.SearchResult; import net.filebot.web.SubtitleDescriptor; import net.filebot.web.SubtitleProvider; +import net.filebot.web.SubtitleSearchResult; public final class SubtitleUtilities { @@ -194,28 +194,28 @@ public final class SubtitleUtilities { Set subtitles = new LinkedHashSet(); // search for and automatically select movie / show entry - Set resultSet = new HashSet(); + Set resultSet = new HashSet(); for (String query : querySet) { resultSet.addAll(findProbableSearchResults(query, service.search(query, searchByMovie, searchBySeries), querySet.size() == 1 ? 4 : 2)); } // fetch subtitles for all search results - for (SearchResult it : resultSet) { + for (SubtitleSearchResult it : resultSet) { subtitles.addAll(service.getSubtitleList(it, languageName)); } return subtitles; } - protected static Collection findProbableSearchResults(String query, Iterable searchResults, int limit) { + protected static Collection findProbableSearchResults(String query, Iterable searchResults, int limit) { // auto-select most probable search result - Set probableMatches = new LinkedHashSet(); + Set probableMatches = new LinkedHashSet(); // use name similarity metric SimilarityMetric metric = new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric()); // find probable matches using name similarity > threshold - for (SearchResult result : searchResults) { + for (SubtitleSearchResult result : searchResults) { if (probableMatches.size() <= limit) { if (metric.getSimilarity(query, removeTrailingBrackets(result.getName())) > 0.8f || result.getName().toLowerCase().startsWith(query.toLowerCase())) { probableMatches.add(result); diff --git a/source/net/filebot/ui/subtitle/SubtitlePanel.java b/source/net/filebot/ui/subtitle/SubtitlePanel.java index e981582f..894d43c9 100644 --- a/source/net/filebot/ui/subtitle/SubtitlePanel.java +++ b/source/net/filebot/ui/subtitle/SubtitlePanel.java @@ -50,6 +50,7 @@ import net.filebot.web.OpenSubtitlesClient; import net.filebot.web.SearchResult; import net.filebot.web.SubtitleDescriptor; import net.filebot.web.SubtitleProvider; +import net.filebot.web.SubtitleSearchResult; import net.filebot.web.VideoHashSubtitleService; import net.miginfocom.swing.MigLayout; @@ -218,10 +219,15 @@ public class SubtitlePanel extends AbstractSearchPanel search() throws Exception { + public Collection search() throws Exception { return request.getProvider().search(request.getSearchText(), true, true); } + @Override + public SubtitleSearchResult getSearchResult() { + return (SubtitleSearchResult) super.getSearchResult(); + } + @Override public Collection fetch() throws Exception { List packages = new ArrayList(); diff --git a/source/net/filebot/web/OpenSubtitlesClient.java b/source/net/filebot/web/OpenSubtitlesClient.java index 31d3effc..4b099208 100644 --- a/source/net/filebot/web/OpenSubtitlesClient.java +++ b/source/net/filebot/web/OpenSubtitlesClient.java @@ -88,12 +88,12 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS } @Override - public synchronized List search(String query, boolean byMovie, boolean bySeries) throws Exception { + public synchronized List search(String query, boolean byMovie, boolean bySeries) throws Exception { throw new UnsupportedOperationException(); // XMLRPC::SearchMoviesOnIMDB is not allowed due to abuse } @Override - public synchronized List getSubtitleList(SearchResult searchResult, String languageName) throws Exception { + public synchronized List getSubtitleList(SubtitleSearchResult searchResult, String languageName) throws Exception { List subtitles = getCache().getSubtitleDescriptorList(searchResult, languageName); if (subtitles != null) { return subtitles; @@ -452,7 +452,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS } @Override - public URI getSubtitleListLink(SearchResult searchResult, String languageName) { + public URI getSubtitleListLink(SubtitleSearchResult searchResult, String languageName) { Movie movie = (Movie) searchResult; String sublanguageid = "all"; diff --git a/source/net/filebot/web/SubtitleProvider.java b/source/net/filebot/web/SubtitleProvider.java index 9256a764..9078e966 100644 --- a/source/net/filebot/web/SubtitleProvider.java +++ b/source/net/filebot/web/SubtitleProvider.java @@ -7,11 +7,11 @@ import javax.swing.Icon; public interface SubtitleProvider { - public List search(String query, boolean byMovie, boolean bySeries) throws Exception; + public List search(String query, boolean byMovie, boolean bySeries) throws Exception; - public List getSubtitleList(SearchResult searchResult, String languageName) throws Exception; + public List getSubtitleList(SubtitleSearchResult searchResult, String languageName) throws Exception; - public URI getSubtitleListLink(SearchResult searchResult, String languageName); + public URI getSubtitleListLink(SubtitleSearchResult searchResult, String languageName); public String getName(); diff --git a/source/net/filebot/web/OpenSubtitlesSearchResult.java b/source/net/filebot/web/SubtitleSearchResult.java similarity index 71% rename from source/net/filebot/web/OpenSubtitlesSearchResult.java rename to source/net/filebot/web/SubtitleSearchResult.java index 6189d43e..0293c156 100644 --- a/source/net/filebot/web/OpenSubtitlesSearchResult.java +++ b/source/net/filebot/web/SubtitleSearchResult.java @@ -2,7 +2,7 @@ package net.filebot.web; import java.util.Locale; -public class OpenSubtitlesSearchResult extends Movie { +public class SubtitleSearchResult extends Movie { public static final char KIND_MOVIE = 'm'; public static final char KIND_SERIES = 's'; @@ -10,7 +10,7 @@ public class OpenSubtitlesSearchResult extends Movie { private char kind; private int score; - public OpenSubtitlesSearchResult(int imdbId, String name, int year, char kind, int score) { + public SubtitleSearchResult(int imdbId, String name, int year, char kind, int score) { super(name, null, year, imdbId, -1, Locale.ENGLISH); this.kind = kind;