* less code duplication, renamed interfaces *Client to *Provider
This commit is contained in:
parent
df143e0305
commit
480c848bda
|
@ -29,7 +29,7 @@ import net.sourceforge.filebot.ui.transfer.FileExportHandler;
|
||||||
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
import net.sourceforge.filebot.ui.transfer.SaveAction;
|
||||||
import net.sourceforge.filebot.web.AnidbClient;
|
import net.sourceforge.filebot.web.AnidbClient;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
import net.sourceforge.filebot.web.EpisodeListClient;
|
import net.sourceforge.filebot.web.EpisodeListProvider;
|
||||||
import net.sourceforge.filebot.web.IMDbClient;
|
import net.sourceforge.filebot.web.IMDbClient;
|
||||||
import net.sourceforge.filebot.web.SearchResult;
|
import net.sourceforge.filebot.web.SearchResult;
|
||||||
import net.sourceforge.filebot.web.TVDotComClient;
|
import net.sourceforge.filebot.web.TVDotComClient;
|
||||||
|
@ -41,7 +41,7 @@ import net.sourceforge.tuned.ui.SimpleLabelProvider;
|
||||||
import net.sourceforge.tuned.ui.TunedUtilities;
|
import net.sourceforge.tuned.ui.TunedUtilities;
|
||||||
|
|
||||||
|
|
||||||
public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Episode> {
|
public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListProvider, Episode> {
|
||||||
|
|
||||||
private SeasonSpinnerModel seasonSpinnerModel = new SeasonSpinnerModel();
|
private SeasonSpinnerModel seasonSpinnerModel = new SeasonSpinnerModel();
|
||||||
|
|
||||||
|
@ -69,8 +69,8 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Epi
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<EpisodeListClient> createSearchEngines() {
|
protected List<EpisodeListProvider> createSearchEngines() {
|
||||||
List<EpisodeListClient> engines = new ArrayList<EpisodeListClient>(4);
|
List<EpisodeListProvider> engines = new ArrayList<EpisodeListProvider>(4);
|
||||||
|
|
||||||
engines.add(new TVRageClient());
|
engines.add(new TVRageClient());
|
||||||
engines.add(new AnidbClient());
|
engines.add(new AnidbClient());
|
||||||
|
@ -83,8 +83,8 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Epi
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LabelProvider<EpisodeListClient> createSearchEngineLabelProvider() {
|
protected LabelProvider<EpisodeListProvider> createSearchEngineLabelProvider() {
|
||||||
return SimpleLabelProvider.forClass(EpisodeListClient.class);
|
return SimpleLabelProvider.forClass(EpisodeListProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,20 +96,20 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Epi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected EpisodeListRequestProcessor createRequestProcessor() {
|
protected EpisodeListRequestProcessor createRequestProcessor() {
|
||||||
EpisodeListClient client = searchTextField.getSelectButton().getSelectedValue();
|
EpisodeListProvider provider = searchTextField.getSelectButton().getSelectedValue();
|
||||||
String text = searchTextField.getText().trim();
|
String text = searchTextField.getText().trim();
|
||||||
int season = seasonSpinnerModel.getSeason();
|
int season = seasonSpinnerModel.getSeason();
|
||||||
|
|
||||||
return new EpisodeListRequestProcessor(new EpisodeListRequest(client, text, season));
|
return new EpisodeListRequestProcessor(new EpisodeListRequest(provider, text, season));
|
||||||
};
|
};
|
||||||
|
|
||||||
private final PropertyChangeListener selectButtonListener = new PropertyChangeListener() {
|
private final PropertyChangeListener selectButtonListener = new PropertyChangeListener() {
|
||||||
|
|
||||||
public void propertyChange(PropertyChangeEvent evt) {
|
public void propertyChange(PropertyChangeEvent evt) {
|
||||||
EpisodeListClient client = searchTextField.getSelectButton().getSelectedValue();
|
EpisodeListProvider provider = searchTextField.getSelectButton().getSelectedValue();
|
||||||
|
|
||||||
// lock season spinner on "All Seasons" if client doesn't support fetching of single seasons
|
// lock season spinner on "All Seasons" if provider doesn't support fetching of single seasons
|
||||||
if (!client.hasSingleSeasonSupport()) {
|
if (!provider.hasSingleSeasonSupport()) {
|
||||||
seasonSpinnerModel.lock(ALL_SEASONS);
|
seasonSpinnerModel.lock(ALL_SEASONS);
|
||||||
} else {
|
} else {
|
||||||
seasonSpinnerModel.unlock();
|
seasonSpinnerModel.unlock();
|
||||||
|
@ -175,19 +175,19 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Epi
|
||||||
|
|
||||||
protected static class EpisodeListRequest extends Request {
|
protected static class EpisodeListRequest extends Request {
|
||||||
|
|
||||||
private final EpisodeListClient client;
|
private final EpisodeListProvider provider;
|
||||||
private final int season;
|
private final int season;
|
||||||
|
|
||||||
|
|
||||||
public EpisodeListRequest(EpisodeListClient client, String searchText, int season) {
|
public EpisodeListRequest(EpisodeListProvider provider, String searchText, int season) {
|
||||||
super(searchText);
|
super(searchText);
|
||||||
this.client = client;
|
this.provider = provider;
|
||||||
this.season = season;
|
this.season = season;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public EpisodeListClient getClient() {
|
public EpisodeListProvider getProvider() {
|
||||||
return client;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -207,26 +207,26 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Epi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SearchResult> search() throws Exception {
|
public Collection<SearchResult> search() throws Exception {
|
||||||
return request.getClient().search(request.getSearchText());
|
return request.getProvider().search(request.getSearchText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Episode> fetch() throws Exception {
|
public Collection<Episode> fetch() throws Exception {
|
||||||
if (request.getSeason() != ALL_SEASONS)
|
if (request.getSeason() != ALL_SEASONS)
|
||||||
return request.getClient().getEpisodeList(getSearchResult(), request.getSeason());
|
return request.getProvider().getEpisodeList(getSearchResult(), request.getSeason());
|
||||||
else
|
else
|
||||||
return request.getClient().getEpisodeList(getSearchResult());
|
return request.getProvider().getEpisodeList(getSearchResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI getLink() {
|
public URI getLink() {
|
||||||
if (request.getSeason() != ALL_SEASONS) {
|
if (request.getSeason() != ALL_SEASONS) {
|
||||||
return request.getClient().getEpisodeListLink(getSearchResult(), request.getSeason());
|
return request.getProvider().getEpisodeListLink(getSearchResult(), request.getSeason());
|
||||||
}
|
}
|
||||||
|
|
||||||
return request.getClient().getEpisodeListLink(getSearchResult());
|
return request.getProvider().getEpisodeListLink(getSearchResult());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -263,7 +263,7 @@ public class EpisodeListPanel extends AbstractSearchPanel<EpisodeListClient, Epi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Icon getIcon() {
|
public Icon getIcon() {
|
||||||
return request.getClient().getIcon();
|
return request.getProvider().getIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ import net.sourceforge.filebot.similarity.Matcher;
|
||||||
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
|
import net.sourceforge.filebot.similarity.SeriesNameMatcher;
|
||||||
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
import net.sourceforge.filebot.similarity.SimilarityMetric;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
import net.sourceforge.filebot.web.EpisodeListClient;
|
import net.sourceforge.filebot.web.EpisodeListProvider;
|
||||||
import net.sourceforge.filebot.web.SearchResult;
|
import net.sourceforge.filebot.web.SearchResult;
|
||||||
import net.sourceforge.tuned.FileUtilities;
|
import net.sourceforge.tuned.FileUtilities;
|
||||||
|
|
||||||
|
@ -36,13 +36,13 @@ class AutoFetchEpisodeListMatcher extends SwingWorker<List<Match<File, Episode>>
|
||||||
|
|
||||||
private final List<File> files;
|
private final List<File> files;
|
||||||
|
|
||||||
private final EpisodeListClient client;
|
private final EpisodeListProvider provider;
|
||||||
|
|
||||||
private final Collection<SimilarityMetric> metrics;
|
private final Collection<SimilarityMetric> metrics;
|
||||||
|
|
||||||
|
|
||||||
public AutoFetchEpisodeListMatcher(EpisodeListClient client, List<File> files, Collection<SimilarityMetric> metrics) {
|
public AutoFetchEpisodeListMatcher(EpisodeListProvider provider, List<File> files, Collection<SimilarityMetric> metrics) {
|
||||||
this.client = client;
|
this.provider = provider;
|
||||||
this.files = new LinkedList<File>(files);
|
this.files = new LinkedList<File>(files);
|
||||||
this.metrics = new ArrayList<SimilarityMetric>(metrics);
|
this.metrics = new ArrayList<SimilarityMetric>(metrics);
|
||||||
}
|
}
|
||||||
|
@ -79,13 +79,13 @@ class AutoFetchEpisodeListMatcher extends SwingWorker<List<Match<File, Episode>>
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<Episode> call() throws Exception {
|
public Collection<Episode> call() throws Exception {
|
||||||
Collection<SearchResult> results = client.search(seriesName);
|
Collection<SearchResult> results = provider.search(seriesName);
|
||||||
|
|
||||||
if (results.size() > 0) {
|
if (results.size() > 0) {
|
||||||
SearchResult selectedSearchResult = selectSearchResult(seriesName, results);
|
SearchResult selectedSearchResult = selectSearchResult(seriesName, results);
|
||||||
|
|
||||||
if (selectedSearchResult != null) {
|
if (selectedSearchResult != null) {
|
||||||
return client.getEpisodeList(selectedSearchResult);
|
return provider.getEpisodeList(selectedSearchResult);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ import net.sourceforge.filebot.ui.EpisodeFormatDialog;
|
||||||
import net.sourceforge.filebot.ui.SelectDialog;
|
import net.sourceforge.filebot.ui.SelectDialog;
|
||||||
import net.sourceforge.filebot.web.AnidbClient;
|
import net.sourceforge.filebot.web.AnidbClient;
|
||||||
import net.sourceforge.filebot.web.Episode;
|
import net.sourceforge.filebot.web.Episode;
|
||||||
import net.sourceforge.filebot.web.EpisodeListClient;
|
import net.sourceforge.filebot.web.EpisodeListProvider;
|
||||||
import net.sourceforge.filebot.web.IMDbClient;
|
import net.sourceforge.filebot.web.IMDbClient;
|
||||||
import net.sourceforge.filebot.web.SearchResult;
|
import net.sourceforge.filebot.web.SearchResult;
|
||||||
import net.sourceforge.filebot.web.TVDotComClient;
|
import net.sourceforge.filebot.web.TVDotComClient;
|
||||||
|
@ -201,13 +201,13 @@ public class RenamePanel extends JComponent {
|
||||||
|
|
||||||
protected class AutoFetchEpisodeListAction extends AbstractAction {
|
protected class AutoFetchEpisodeListAction extends AbstractAction {
|
||||||
|
|
||||||
private final EpisodeListClient client;
|
private final EpisodeListProvider provider;
|
||||||
|
|
||||||
|
|
||||||
public AutoFetchEpisodeListAction(EpisodeListClient client) {
|
public AutoFetchEpisodeListAction(EpisodeListProvider provider) {
|
||||||
super(client.getName(), client.getIcon());
|
super(provider.getName(), provider.getIcon());
|
||||||
|
|
||||||
this.client = client;
|
this.provider = provider;
|
||||||
|
|
||||||
// disable action while episode list matcher is working
|
// disable action while episode list matcher is working
|
||||||
namesList.addPropertyChangeListener(LOADING_PROPERTY, new PropertyChangeListener() {
|
namesList.addPropertyChangeListener(LOADING_PROPERTY, new PropertyChangeListener() {
|
||||||
|
@ -229,7 +229,7 @@ public class RenamePanel extends JComponent {
|
||||||
// clear names list
|
// clear names list
|
||||||
model.names().clear();
|
model.names().clear();
|
||||||
|
|
||||||
AutoFetchEpisodeListMatcher worker = new AutoFetchEpisodeListMatcher(client, model.files(), matchAction.getMetrics()) {
|
AutoFetchEpisodeListMatcher worker = new AutoFetchEpisodeListMatcher(provider, model.files(), matchAction.getMetrics()) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void done() {
|
protected void done() {
|
||||||
|
|
|
@ -19,14 +19,14 @@ import net.sourceforge.filebot.ui.SelectDialog;
|
||||||
import net.sourceforge.filebot.web.OpenSubtitlesSubtitleClient;
|
import net.sourceforge.filebot.web.OpenSubtitlesSubtitleClient;
|
||||||
import net.sourceforge.filebot.web.SearchResult;
|
import net.sourceforge.filebot.web.SearchResult;
|
||||||
import net.sourceforge.filebot.web.SubsceneSubtitleClient;
|
import net.sourceforge.filebot.web.SubsceneSubtitleClient;
|
||||||
import net.sourceforge.filebot.web.SubtitleClient;
|
|
||||||
import net.sourceforge.filebot.web.SubtitleDescriptor;
|
import net.sourceforge.filebot.web.SubtitleDescriptor;
|
||||||
|
import net.sourceforge.filebot.web.SubtitleProvider;
|
||||||
import net.sourceforge.filebot.web.SubtitleSourceClient;
|
import net.sourceforge.filebot.web.SubtitleSourceClient;
|
||||||
import net.sourceforge.tuned.ui.LabelProvider;
|
import net.sourceforge.tuned.ui.LabelProvider;
|
||||||
import net.sourceforge.tuned.ui.SimpleLabelProvider;
|
import net.sourceforge.tuned.ui.SimpleLabelProvider;
|
||||||
|
|
||||||
|
|
||||||
public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitlePackage> {
|
public class SubtitlePanel extends AbstractSearchPanel<SubtitleProvider, SubtitlePackage> {
|
||||||
|
|
||||||
public SubtitlePanel() {
|
public SubtitlePanel() {
|
||||||
historyPanel.setColumnHeader(0, "Show / Movie");
|
historyPanel.setColumnHeader(0, "Show / Movie");
|
||||||
|
@ -35,8 +35,8 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected List<SubtitleClient> createSearchEngines() {
|
protected List<SubtitleProvider> createSearchEngines() {
|
||||||
List<SubtitleClient> engines = new ArrayList<SubtitleClient>(2);
|
List<SubtitleProvider> engines = new ArrayList<SubtitleProvider>(2);
|
||||||
|
|
||||||
engines.add(new OpenSubtitlesSubtitleClient(String.format("%s v%s", getApplicationName(), getApplicationVersion())));
|
engines.add(new OpenSubtitlesSubtitleClient(String.format("%s v%s", getApplicationName(), getApplicationVersion())));
|
||||||
engines.add(new SubsceneSubtitleClient());
|
engines.add(new SubsceneSubtitleClient());
|
||||||
|
@ -47,8 +47,8 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected LabelProvider<SubtitleClient> createSearchEngineLabelProvider() {
|
protected LabelProvider<SubtitleProvider> createSearchEngineLabelProvider() {
|
||||||
return SimpleLabelProvider.forClass(SubtitleClient.class);
|
return SimpleLabelProvider.forClass(SubtitleProvider.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,31 +60,31 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SubtitleRequestProcessor createRequestProcessor() {
|
protected SubtitleRequestProcessor createRequestProcessor() {
|
||||||
SubtitleClient client = searchTextField.getSelectButton().getSelectedValue();
|
SubtitleProvider provider = searchTextField.getSelectButton().getSelectedValue();
|
||||||
String text = searchTextField.getText().trim();
|
String text = searchTextField.getText().trim();
|
||||||
|
|
||||||
//TODO language selection combobox
|
//TODO language selection combobox
|
||||||
Locale language = Locale.ENGLISH;
|
Locale language = Locale.ENGLISH;
|
||||||
|
|
||||||
return new SubtitleRequestProcessor(new SubtitleRequest(client, text, language));
|
return new SubtitleRequestProcessor(new SubtitleRequest(provider, text, language));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static class SubtitleRequest extends Request {
|
protected static class SubtitleRequest extends Request {
|
||||||
|
|
||||||
private final SubtitleClient client;
|
private final SubtitleProvider provider;
|
||||||
private final Locale language;
|
private final Locale language;
|
||||||
|
|
||||||
|
|
||||||
public SubtitleRequest(SubtitleClient client, String searchText, Locale language) {
|
public SubtitleRequest(SubtitleProvider provider, String searchText, Locale language) {
|
||||||
super(searchText);
|
super(searchText);
|
||||||
this.client = client;
|
this.provider = provider;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SubtitleClient getClient() {
|
public SubtitleProvider getProvider() {
|
||||||
return client;
|
return provider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,7 +104,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<SearchResult> search() throws Exception {
|
public Collection<SearchResult> search() throws Exception {
|
||||||
return request.getClient().search(request.getSearchText());
|
return request.getProvider().search(request.getSearchText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,7 +112,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
|
||||||
public Collection<SubtitlePackage> fetch() throws Exception {
|
public Collection<SubtitlePackage> fetch() throws Exception {
|
||||||
List<SubtitlePackage> packages = new ArrayList<SubtitlePackage>(20);
|
List<SubtitlePackage> packages = new ArrayList<SubtitlePackage>(20);
|
||||||
|
|
||||||
for (SubtitleDescriptor subtitle : request.getClient().getSubtitleList(getSearchResult(), request.getLanguage())) {
|
for (SubtitleDescriptor subtitle : request.getProvider().getSubtitleList(getSearchResult(), request.getLanguage())) {
|
||||||
packages.add(new SubtitlePackage(subtitle));
|
packages.add(new SubtitlePackage(subtitle));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URI getLink() {
|
public URI getLink() {
|
||||||
return request.getClient().getSubtitleListLink(getSearchResult(), request.getLanguage());
|
return request.getProvider().getSubtitleListLink(getSearchResult(), request.getLanguage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ public class SubtitlePanel extends AbstractSearchPanel<SubtitleClient, SubtitleP
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Icon getIcon() {
|
public Icon getIcon() {
|
||||||
return request.client.getIcon();
|
return request.provider.getIcon();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ import org.w3c.dom.Node;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
public class AnidbClient implements EpisodeListClient {
|
public class AnidbClient implements EpisodeListProvider {
|
||||||
|
|
||||||
private static final String host = "anidb.net";
|
private static final String host = "anidb.net";
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.List;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
|
||||||
|
|
||||||
public interface EpisodeListClient {
|
public interface EpisodeListProvider {
|
||||||
|
|
||||||
public List<SearchResult> search(String query) throws Exception;
|
public List<SearchResult> search(String query) throws Exception;
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
|
||||||
|
package net.sourceforge.filebot.web;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public final class EpisodeListUtilities {
|
||||||
|
|
||||||
|
public static List<Episode> filterBySeason(Iterable<Episode> episodes, int season) {
|
||||||
|
|
||||||
|
List<Episode> results = new ArrayList<Episode>(25);
|
||||||
|
|
||||||
|
// filter given season from all seasons
|
||||||
|
for (Episode episode : episodes) {
|
||||||
|
try {
|
||||||
|
if (season == Integer.parseInt(episode.getSeasonNumber())) {
|
||||||
|
results.add(episode);
|
||||||
|
}
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// ignore illegal episodes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static int getLastSeason(Iterable<Episode> episodes) {
|
||||||
|
int lastSeason = 0;
|
||||||
|
|
||||||
|
// filter given season from all seasons
|
||||||
|
for (Episode episode : episodes) {
|
||||||
|
try {
|
||||||
|
lastSeason = Math.max(lastSeason, Integer.parseInt(episode.getSeasonNumber()));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// ignore illegal episodes
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return lastSeason;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private EpisodeListUtilities() {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,8 @@
|
||||||
package net.sourceforge.filebot.web;
|
package net.sourceforge.filebot.web;
|
||||||
|
|
||||||
|
|
||||||
|
import static net.sourceforge.filebot.web.EpisodeListUtilities.filterBySeason;
|
||||||
|
import static net.sourceforge.filebot.web.EpisodeListUtilities.getLastSeason;
|
||||||
import static net.sourceforge.filebot.web.WebRequest.getHtmlDocument;
|
import static net.sourceforge.filebot.web.WebRequest.getHtmlDocument;
|
||||||
import static net.sourceforge.tuned.XPathUtilities.getAttribute;
|
import static net.sourceforge.tuned.XPathUtilities.getAttribute;
|
||||||
import static net.sourceforge.tuned.XPathUtilities.selectNodes;
|
import static net.sourceforge.tuned.XPathUtilities.selectNodes;
|
||||||
|
@ -15,8 +17,6 @@ import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ import org.w3c.dom.Node;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
public class IMDbClient implements EpisodeListClient {
|
public class IMDbClient implements EpisodeListProvider {
|
||||||
|
|
||||||
private static final String host = "www.imdb.com";
|
private static final String host = "www.imdb.com";
|
||||||
|
|
||||||
|
@ -102,34 +102,14 @@ public class IMDbClient implements EpisodeListClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Episode> getEpisodeList(SearchResult searchResult, int season) throws Exception {
|
public List<Episode> getEpisodeList(SearchResult searchResult, int season) throws Exception {
|
||||||
|
List<Episode> all = getEpisodeList(searchResult);
|
||||||
|
List<Episode> eps = filterBySeason(all, season);
|
||||||
|
|
||||||
List<Episode> episodes = new ArrayList<Episode>(25);
|
if (eps.isEmpty()) {
|
||||||
|
throw new SeasonOutOfBoundsException(searchResult.getName(), season, getLastSeason(all));
|
||||||
// remember max. season, so we can throw a proper exception, in case an illegal season number was requested
|
|
||||||
int maxSeason = 0;
|
|
||||||
|
|
||||||
// filter given season from all seasons
|
|
||||||
for (Episode episode : getEpisodeList(searchResult)) {
|
|
||||||
try {
|
|
||||||
int seasonNumber = Integer.parseInt(episode.getSeasonNumber());
|
|
||||||
|
|
||||||
if (season == seasonNumber) {
|
|
||||||
episodes.add(episode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seasonNumber > maxSeason) {
|
return eps;
|
||||||
maxSeason = seasonNumber;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal season number", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (episodes.isEmpty()) {
|
|
||||||
throw new SeasonOutOfBoundsException(searchResult.getName(), season, maxSeason);
|
|
||||||
}
|
|
||||||
|
|
||||||
return episodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import net.sourceforge.tuned.Timer;
|
||||||
/**
|
/**
|
||||||
* SubtitleClient for OpenSubtitles.
|
* SubtitleClient for OpenSubtitles.
|
||||||
*/
|
*/
|
||||||
public class OpenSubtitlesSubtitleClient implements SubtitleClient {
|
public class OpenSubtitlesSubtitleClient implements SubtitleProvider {
|
||||||
|
|
||||||
private final OpenSubtitlesClient client;
|
private final OpenSubtitlesClient client;
|
||||||
|
|
||||||
|
|
|
@ -6,19 +6,19 @@ public class SeasonOutOfBoundsException extends IndexOutOfBoundsException {
|
||||||
|
|
||||||
private final String seriesName;
|
private final String seriesName;
|
||||||
private final int season;
|
private final int season;
|
||||||
private final int maxSeason;
|
private final int lastSeason;
|
||||||
|
|
||||||
|
|
||||||
public SeasonOutOfBoundsException(String seriesName, int season, int maxSeason) {
|
public SeasonOutOfBoundsException(String seriesName, int season, int lastSeason) {
|
||||||
this.seriesName = seriesName;
|
this.seriesName = seriesName;
|
||||||
this.season = season;
|
this.season = season;
|
||||||
this.maxSeason = maxSeason;
|
this.lastSeason = lastSeason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
return String.format("%s has only %d season%s.", seriesName, maxSeason, maxSeason != 1 ? "s" : "");
|
return String.format("%s has only %d season%s.", seriesName, lastSeason, lastSeason != 1 ? "s" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,8 +32,8 @@ public class SeasonOutOfBoundsException extends IndexOutOfBoundsException {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public int getMaxSeason() {
|
public int getLastSeason() {
|
||||||
return maxSeason;
|
return lastSeason;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ import org.w3c.dom.Node;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
public class SubsceneSubtitleClient implements SubtitleClient {
|
public class SubsceneSubtitleClient implements SubtitleProvider {
|
||||||
|
|
||||||
private static final String host = "subscene.com";
|
private static final String host = "subscene.com";
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ import java.util.Locale;
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
|
||||||
|
|
||||||
public interface SubtitleClient {
|
public interface SubtitleProvider {
|
||||||
|
|
||||||
public List<SearchResult> search(String query) throws Exception;
|
public List<SearchResult> search(String query) throws Exception;
|
||||||
|
|
|
@ -25,7 +25,7 @@ import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Node;
|
import org.w3c.dom.Node;
|
||||||
|
|
||||||
|
|
||||||
public class SubtitleSourceClient implements SubtitleClient {
|
public class SubtitleSourceClient implements SubtitleProvider {
|
||||||
|
|
||||||
protected static final String HOST = "www.subtitlesource.org";
|
protected static final String HOST = "www.subtitlesource.org";
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.w3c.dom.Node;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
public class TVDotComClient implements EpisodeListClient {
|
public class TVDotComClient implements EpisodeListProvider {
|
||||||
|
|
||||||
private static final String host = "www.tv.com";
|
private static final String host = "www.tv.com";
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
package net.sourceforge.filebot.web;
|
package net.sourceforge.filebot.web;
|
||||||
|
|
||||||
|
|
||||||
|
import static net.sourceforge.filebot.web.EpisodeListUtilities.filterBySeason;
|
||||||
|
import static net.sourceforge.filebot.web.EpisodeListUtilities.getLastSeason;
|
||||||
import static net.sourceforge.filebot.web.WebRequest.getDocument;
|
import static net.sourceforge.filebot.web.WebRequest.getDocument;
|
||||||
import static net.sourceforge.tuned.XPathUtilities.getTextContent;
|
import static net.sourceforge.tuned.XPathUtilities.getTextContent;
|
||||||
import static net.sourceforge.tuned.XPathUtilities.selectNodes;
|
import static net.sourceforge.tuned.XPathUtilities.selectNodes;
|
||||||
|
@ -13,8 +15,6 @@ import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
@ -29,7 +29,7 @@ import org.w3c.dom.Node;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
public class TVRageClient implements EpisodeListClient {
|
public class TVRageClient implements EpisodeListProvider {
|
||||||
|
|
||||||
private static final String host = "www.tvrage.com";
|
private static final String host = "www.tvrage.com";
|
||||||
|
|
||||||
|
@ -115,33 +115,14 @@ public class TVRageClient implements EpisodeListClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Episode> getEpisodeList(SearchResult searchResult, int season) throws IOException, SAXException, ParserConfigurationException {
|
public List<Episode> getEpisodeList(SearchResult searchResult, int season) throws IOException, SAXException, ParserConfigurationException {
|
||||||
|
List<Episode> all = getEpisodeList(searchResult);
|
||||||
|
List<Episode> eps = filterBySeason(all, season);
|
||||||
|
|
||||||
List<Episode> episodes = new ArrayList<Episode>(25);
|
if (eps.isEmpty()) {
|
||||||
|
throw new SeasonOutOfBoundsException(searchResult.getName(), season, getLastSeason(all));
|
||||||
// remember max. season, so we can throw a proper exception, in case an illegal season number was requested
|
|
||||||
int maxSeason = 0;
|
|
||||||
|
|
||||||
// filter given season from all seasons
|
|
||||||
for (Episode episode : getEpisodeList(searchResult)) {
|
|
||||||
try {
|
|
||||||
int seasonNumber = Integer.parseInt(episode.getSeasonNumber());
|
|
||||||
|
|
||||||
if (season == seasonNumber) {
|
|
||||||
episodes.add(episode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seasonNumber > maxSeason) {
|
return eps;
|
||||||
maxSeason = seasonNumber;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal season number", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (episodes.isEmpty())
|
|
||||||
throw new SeasonOutOfBoundsException(searchResult.getName(), season, maxSeason);
|
|
||||||
|
|
||||||
return episodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
package net.sourceforge.filebot.web;
|
package net.sourceforge.filebot.web;
|
||||||
|
|
||||||
|
|
||||||
|
import static net.sourceforge.filebot.web.EpisodeListUtilities.filterBySeason;
|
||||||
|
import static net.sourceforge.filebot.web.EpisodeListUtilities.getLastSeason;
|
||||||
import static net.sourceforge.filebot.web.WebRequest.getDocument;
|
import static net.sourceforge.filebot.web.WebRequest.getDocument;
|
||||||
import static net.sourceforge.tuned.XPathUtilities.getTextContent;
|
import static net.sourceforge.tuned.XPathUtilities.getTextContent;
|
||||||
import static net.sourceforge.tuned.XPathUtilities.selectNodes;
|
import static net.sourceforge.tuned.XPathUtilities.selectNodes;
|
||||||
|
@ -38,7 +40,7 @@ import org.w3c.dom.Node;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
|
|
||||||
public class TheTVDBClient implements EpisodeListClient {
|
public class TheTVDBClient implements EpisodeListProvider {
|
||||||
|
|
||||||
private static final String host = "www.thetvdb.com";
|
private static final String host = "www.thetvdb.com";
|
||||||
|
|
||||||
|
@ -110,34 +112,14 @@ public class TheTVDBClient implements EpisodeListClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Episode> getEpisodeList(SearchResult searchResult, int season) throws Exception {
|
public List<Episode> getEpisodeList(SearchResult searchResult, int season) throws Exception {
|
||||||
|
List<Episode> all = getEpisodeList(searchResult);
|
||||||
|
List<Episode> eps = filterBySeason(all, season);
|
||||||
|
|
||||||
List<Episode> episodes = new ArrayList<Episode>(25);
|
if (eps.isEmpty()) {
|
||||||
|
throw new SeasonOutOfBoundsException(searchResult.getName(), season, getLastSeason(all));
|
||||||
// remember max. season, so we can throw a proper exception, in case an illegal season number was requested
|
|
||||||
int maxSeason = 0;
|
|
||||||
|
|
||||||
// filter given season from all seasons
|
|
||||||
for (Episode episode : getEpisodeList(searchResult)) {
|
|
||||||
try {
|
|
||||||
int seasonNumber = Integer.parseInt(episode.getSeasonNumber());
|
|
||||||
|
|
||||||
if (season == seasonNumber) {
|
|
||||||
episodes.add(episode);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (seasonNumber > maxSeason) {
|
return eps;
|
||||||
maxSeason = seasonNumber;
|
|
||||||
}
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Illegal season number", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (episodes.isEmpty()) {
|
|
||||||
throw new SeasonOutOfBoundsException(searchResult.getName(), season, maxSeason);
|
|
||||||
}
|
|
||||||
|
|
||||||
return episodes;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue