mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-09 22:09:47 -04:00
* refactor
This commit is contained in:
parent
c21e544e08
commit
97c9643871
@ -32,9 +32,9 @@ import net.filebot.web.MovieIdentificationService;
|
|||||||
import net.filebot.web.MusicIdentificationService;
|
import net.filebot.web.MusicIdentificationService;
|
||||||
import net.filebot.web.OMDbClient;
|
import net.filebot.web.OMDbClient;
|
||||||
import net.filebot.web.OpenSubtitlesClient;
|
import net.filebot.web.OpenSubtitlesClient;
|
||||||
import net.filebot.web.OpenSubtitlesSearchResult;
|
|
||||||
import net.filebot.web.SearchResult;
|
import net.filebot.web.SearchResult;
|
||||||
import net.filebot.web.SubtitleProvider;
|
import net.filebot.web.SubtitleProvider;
|
||||||
|
import net.filebot.web.SubtitleSearchResult;
|
||||||
import net.filebot.web.TMDbClient;
|
import net.filebot.web.TMDbClient;
|
||||||
import net.filebot.web.TVRageClient;
|
import net.filebot.web.TVRageClient;
|
||||||
import net.filebot.web.TheTVDBClient;
|
import net.filebot.web.TheTVDBClient;
|
||||||
@ -179,18 +179,18 @@ public final class WebServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// index of local OpenSubtitles data dump
|
// index of local OpenSubtitles data dump
|
||||||
private static LocalSearch<SearchResult> localIndex;
|
private static LocalSearch<SubtitleSearchResult> localIndex;
|
||||||
|
|
||||||
public synchronized LocalSearch<SearchResult> getLocalIndex() throws IOException {
|
public synchronized LocalSearch<SubtitleSearchResult> getLocalIndex() throws IOException {
|
||||||
if (localIndex == null) {
|
if (localIndex == null) {
|
||||||
// fetch data dump
|
// fetch data dump
|
||||||
OpenSubtitlesSearchResult[] data = releaseInfo.getOpenSubtitlesIndex();
|
SubtitleSearchResult[] data = releaseInfo.getOpenSubtitlesIndex();
|
||||||
|
|
||||||
// index data dump
|
// index data dump
|
||||||
localIndex = new LocalSearch<SearchResult>(asList(data)) {
|
localIndex = new LocalSearch<SubtitleSearchResult>(asList(data)) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<String> getFields(SearchResult object) {
|
protected Set<String> getFields(SubtitleSearchResult object) {
|
||||||
return set(object.getEffectiveNames());
|
return set(object.getEffectiveNames());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -200,8 +200,8 @@ public final class WebServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<SearchResult> search(final String query, final boolean byMovie, final boolean bySeries) throws Exception {
|
public synchronized List<SubtitleSearchResult> search(final String query, final boolean byMovie, final boolean bySeries) throws Exception {
|
||||||
List<SearchResult> 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);
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ import net.filebot.util.FileUtilities.RegexFileFilter;
|
|||||||
import net.filebot.web.AnidbSearchResult;
|
import net.filebot.web.AnidbSearchResult;
|
||||||
import net.filebot.web.CachedResource;
|
import net.filebot.web.CachedResource;
|
||||||
import net.filebot.web.Movie;
|
import net.filebot.web.Movie;
|
||||||
import net.filebot.web.OpenSubtitlesSearchResult;
|
import net.filebot.web.SubtitleSearchResult;
|
||||||
import net.filebot.web.TheTVDBSearchResult;
|
import net.filebot.web.TheTVDBSearchResult;
|
||||||
|
|
||||||
import org.tukaani.xz.XZInputStream;
|
import org.tukaani.xz.XZInputStream;
|
||||||
@ -306,7 +306,7 @@ public class ReleaseInfo {
|
|||||||
return anidbIndexResource.get();
|
return anidbIndexResource.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OpenSubtitlesSearchResult[] getOpenSubtitlesIndex() throws IOException {
|
public SubtitleSearchResult[] getOpenSubtitlesIndex() throws IOException {
|
||||||
return osdbIndexResource.get();
|
return osdbIndexResource.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -354,7 +354,7 @@ public class ReleaseInfo {
|
|||||||
protected final CachedResource<String[]> seriesDirectMappingsResource = new PatternResource(getProperty("url.series-mappings"));
|
protected final CachedResource<String[]> seriesDirectMappingsResource = new PatternResource(getProperty("url.series-mappings"));
|
||||||
protected final CachedResource<TheTVDBSearchResult[]> tvdbIndexResource = new TheTVDBIndexResource(getProperty("url.thetvdb-index"));
|
protected final CachedResource<TheTVDBSearchResult[]> tvdbIndexResource = new TheTVDBIndexResource(getProperty("url.thetvdb-index"));
|
||||||
protected final CachedResource<AnidbSearchResult[]> anidbIndexResource = new AnidbIndexResource(getProperty("url.anidb-index"));
|
protected final CachedResource<AnidbSearchResult[]> anidbIndexResource = new AnidbIndexResource(getProperty("url.anidb-index"));
|
||||||
protected final CachedResource<OpenSubtitlesSearchResult[]> osdbIndexResource = new OpenSubtitlesIndexResource(getProperty("url.osdb-index"));
|
protected final CachedResource<SubtitleSearchResult[]> osdbIndexResource = new OpenSubtitlesIndexResource(getProperty("url.osdb-index"));
|
||||||
|
|
||||||
protected String getProperty(String propertyName) {
|
protected String getProperty(String propertyName) {
|
||||||
// allow override via Java System properties
|
// allow override via Java System properties
|
||||||
@ -441,16 +441,16 @@ public class ReleaseInfo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class OpenSubtitlesIndexResource extends CachedResource<OpenSubtitlesSearchResult[]> {
|
protected static class OpenSubtitlesIndexResource extends CachedResource<SubtitleSearchResult[]> {
|
||||||
|
|
||||||
public OpenSubtitlesIndexResource(String resource) {
|
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
|
@Override
|
||||||
public OpenSubtitlesSearchResult[] process(ByteBuffer data) throws IOException {
|
public SubtitleSearchResult[] process(ByteBuffer data) throws IOException {
|
||||||
List<String[]> rows = readCSV(new XZInputStream(new ByteBufferInputStream(data)), "UTF-8", "\t");
|
List<String[]> rows = readCSV(new XZInputStream(new ByteBufferInputStream(data)), "UTF-8", "\t");
|
||||||
List<OpenSubtitlesSearchResult> result = new ArrayList<OpenSubtitlesSearchResult>(rows.size());
|
List<SubtitleSearchResult> result = new ArrayList<SubtitleSearchResult>(rows.size());
|
||||||
|
|
||||||
for (String[] row : rows) {
|
for (String[] row : rows) {
|
||||||
int imdbid = parseInt(row[0]);
|
int imdbid = parseInt(row[0]);
|
||||||
@ -458,10 +458,10 @@ public class ReleaseInfo {
|
|||||||
int year = parseInt(row[2]);
|
int year = parseInt(row[2]);
|
||||||
char kind = row[3].charAt(0);
|
char kind = row[3].charAt(0);
|
||||||
int score = parseInt(row[4]);
|
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]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,9 +42,9 @@ import net.filebot.similarity.SimilarityMetric;
|
|||||||
import net.filebot.vfs.ArchiveType;
|
import net.filebot.vfs.ArchiveType;
|
||||||
import net.filebot.vfs.MemoryFile;
|
import net.filebot.vfs.MemoryFile;
|
||||||
import net.filebot.web.Movie;
|
import net.filebot.web.Movie;
|
||||||
import net.filebot.web.SearchResult;
|
|
||||||
import net.filebot.web.SubtitleDescriptor;
|
import net.filebot.web.SubtitleDescriptor;
|
||||||
import net.filebot.web.SubtitleProvider;
|
import net.filebot.web.SubtitleProvider;
|
||||||
|
import net.filebot.web.SubtitleSearchResult;
|
||||||
|
|
||||||
public final class SubtitleUtilities {
|
public final class SubtitleUtilities {
|
||||||
|
|
||||||
@ -194,28 +194,28 @@ public final class SubtitleUtilities {
|
|||||||
Set<SubtitleDescriptor> subtitles = new LinkedHashSet<SubtitleDescriptor>();
|
Set<SubtitleDescriptor> subtitles = new LinkedHashSet<SubtitleDescriptor>();
|
||||||
|
|
||||||
// search for and automatically select movie / show entry
|
// search for and automatically select movie / show entry
|
||||||
Set<SearchResult> resultSet = new HashSet<SearchResult>();
|
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));
|
resultSet.addAll(findProbableSearchResults(query, service.search(query, searchByMovie, searchBySeries), querySet.size() == 1 ? 4 : 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
// fetch subtitles for all search results
|
// fetch subtitles for all search results
|
||||||
for (SearchResult it : resultSet) {
|
for (SubtitleSearchResult it : resultSet) {
|
||||||
subtitles.addAll(service.getSubtitleList(it, languageName));
|
subtitles.addAll(service.getSubtitleList(it, languageName));
|
||||||
}
|
}
|
||||||
|
|
||||||
return subtitles;
|
return subtitles;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Collection<SearchResult> findProbableSearchResults(String query, Iterable<? extends SearchResult> searchResults, int limit) {
|
protected static Collection<SubtitleSearchResult> findProbableSearchResults(String query, Iterable<SubtitleSearchResult> searchResults, int limit) {
|
||||||
// auto-select most probable search result
|
// auto-select most probable search result
|
||||||
Set<SearchResult> probableMatches = new LinkedHashSet<SearchResult>();
|
Set<SubtitleSearchResult> probableMatches = new LinkedHashSet<SubtitleSearchResult>();
|
||||||
|
|
||||||
// use name similarity metric
|
// use name similarity metric
|
||||||
SimilarityMetric metric = new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric());
|
SimilarityMetric metric = new MetricAvg(new SequenceMatchSimilarity(), new NameSimilarityMetric());
|
||||||
|
|
||||||
// find probable matches using name similarity > threshold
|
// find probable matches using name similarity > threshold
|
||||||
for (SearchResult result : searchResults) {
|
for (SubtitleSearchResult result : searchResults) {
|
||||||
if (probableMatches.size() <= limit) {
|
if (probableMatches.size() <= limit) {
|
||||||
if (metric.getSimilarity(query, removeTrailingBrackets(result.getName())) > 0.8f || result.getName().toLowerCase().startsWith(query.toLowerCase())) {
|
if (metric.getSimilarity(query, removeTrailingBrackets(result.getName())) > 0.8f || result.getName().toLowerCase().startsWith(query.toLowerCase())) {
|
||||||
probableMatches.add(result);
|
probableMatches.add(result);
|
||||||
|
@ -50,6 +50,7 @@ import net.filebot.web.OpenSubtitlesClient;
|
|||||||
import net.filebot.web.SearchResult;
|
import net.filebot.web.SearchResult;
|
||||||
import net.filebot.web.SubtitleDescriptor;
|
import net.filebot.web.SubtitleDescriptor;
|
||||||
import net.filebot.web.SubtitleProvider;
|
import net.filebot.web.SubtitleProvider;
|
||||||
|
import net.filebot.web.SubtitleSearchResult;
|
||||||
import net.filebot.web.VideoHashSubtitleService;
|
import net.filebot.web.VideoHashSubtitleService;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
@ -218,10 +219,15 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, Subtitl
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SearchResult> search() throws Exception {
|
public Collection<SubtitleSearchResult> search() throws Exception {
|
||||||
return request.getProvider().search(request.getSearchText(), true, true);
|
return request.getProvider().search(request.getSearchText(), true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SubtitleSearchResult getSearchResult() {
|
||||||
|
return (SubtitleSearchResult) super.getSearchResult();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SubtitlePackage> fetch() throws Exception {
|
public Collection<SubtitlePackage> fetch() throws Exception {
|
||||||
List<SubtitlePackage> packages = new ArrayList<SubtitlePackage>();
|
List<SubtitlePackage> packages = new ArrayList<SubtitlePackage>();
|
||||||
|
@ -88,12 +88,12 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<SearchResult> search(String query, boolean byMovie, boolean bySeries) throws Exception {
|
public synchronized List<SubtitleSearchResult> search(String query, boolean byMovie, boolean bySeries) throws Exception {
|
||||||
throw new UnsupportedOperationException(); // XMLRPC::SearchMoviesOnIMDB is not allowed due to abuse
|
throw new UnsupportedOperationException(); // XMLRPC::SearchMoviesOnIMDB is not allowed due to abuse
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult, String languageName) throws Exception {
|
public synchronized List<SubtitleDescriptor> getSubtitleList(SubtitleSearchResult searchResult, String languageName) throws Exception {
|
||||||
List<SubtitleDescriptor> subtitles = getCache().getSubtitleDescriptorList(searchResult, languageName);
|
List<SubtitleDescriptor> subtitles = getCache().getSubtitleDescriptorList(searchResult, languageName);
|
||||||
if (subtitles != null) {
|
if (subtitles != null) {
|
||||||
return subtitles;
|
return subtitles;
|
||||||
@ -452,7 +452,7 @@ public class OpenSubtitlesClient implements SubtitleProvider, VideoHashSubtitleS
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI getSubtitleListLink(SearchResult searchResult, String languageName) {
|
public URI getSubtitleListLink(SubtitleSearchResult searchResult, String languageName) {
|
||||||
Movie movie = (Movie) searchResult;
|
Movie movie = (Movie) searchResult;
|
||||||
String sublanguageid = "all";
|
String sublanguageid = "all";
|
||||||
|
|
||||||
|
@ -7,11 +7,11 @@ import javax.swing.Icon;
|
|||||||
|
|
||||||
public interface SubtitleProvider {
|
public interface SubtitleProvider {
|
||||||
|
|
||||||
public List<SearchResult> search(String query, boolean byMovie, boolean bySeries) throws Exception;
|
public List<SubtitleSearchResult> search(String query, boolean byMovie, boolean bySeries) throws Exception;
|
||||||
|
|
||||||
public List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult, String languageName) throws Exception;
|
public List<SubtitleDescriptor> getSubtitleList(SubtitleSearchResult searchResult, String languageName) throws Exception;
|
||||||
|
|
||||||
public URI getSubtitleListLink(SearchResult searchResult, String languageName);
|
public URI getSubtitleListLink(SubtitleSearchResult searchResult, String languageName);
|
||||||
|
|
||||||
public String getName();
|
public String getName();
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ package net.filebot.web;
|
|||||||
|
|
||||||
import java.util.Locale;
|
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_MOVIE = 'm';
|
||||||
public static final char KIND_SERIES = 's';
|
public static final char KIND_SERIES = 's';
|
||||||
@ -10,7 +10,7 @@ public class OpenSubtitlesSearchResult extends Movie {
|
|||||||
private char kind;
|
private char kind;
|
||||||
private int score;
|
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);
|
super(name, null, year, imdbId, -1, Locale.ENGLISH);
|
||||||
|
|
||||||
this.kind = kind;
|
this.kind = kind;
|
Loading…
x
Reference in New Issue
Block a user