* clean up

This commit is contained in:
Reinhard Pointner 2008-07-06 03:22:47 +00:00
parent cd09a67c5e
commit 7317717a3e
9 changed files with 9 additions and 327 deletions

View File

@ -1,36 +0,0 @@
package net.sourceforge.filebot.ui.panel.rename.similarity;
import net.sourceforge.filebot.ui.panel.rename.entry.AbstractFileEntry;
import net.sourceforge.filebot.ui.panel.rename.entry.ListEntry;
public class LengthEqualsMetric extends SimilarityMetric {
@Override
public float getSimilarity(ListEntry a, ListEntry b) {
if ((a instanceof AbstractFileEntry) && (b instanceof AbstractFileEntry)) {
long lengthA = ((AbstractFileEntry) a).getLength();
long lengthB = ((AbstractFileEntry) b).getLength();
if (lengthA == lengthB)
return 1;
}
return 0;
}
@Override
public String getDescription() {
return "Check whether file size is equal or not";
}
@Override
public String getName() {
return "Length";
}
}

View File

@ -1,51 +0,0 @@
package net.sourceforge.filebot.ui.panel.rename.similarity;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import net.sourceforge.filebot.ui.panel.rename.entry.ListEntry;
public class MultiSimilarityMetric extends SimilarityMetric implements Iterable<SimilarityMetric> {
private List<SimilarityMetric> similarityMetrics;
public MultiSimilarityMetric(SimilarityMetric... metrics) {
similarityMetrics = Arrays.asList(metrics);
}
@Override
public float getSimilarity(ListEntry a, ListEntry b) {
float similarity = 0;
for (SimilarityMetric metric : similarityMetrics) {
similarity += metric.getSimilarity(a, b) / similarityMetrics.size();
}
return similarity;
}
@Override
public String getDescription() {
return null;
}
@Override
public String getName() {
return "Average";
}
@Override
public Iterator<SimilarityMetric> iterator() {
return similarityMetrics.iterator();
}
}

View File

@ -1,17 +0,0 @@
package net.sourceforge.filebot.ui.panel.rename.similarity;
import net.sourceforge.filebot.ui.panel.rename.entry.ListEntry;
public abstract class SimilarityMetric {
public abstract float getSimilarity(ListEntry a, ListEntry b);
public abstract String getDescription();
public abstract String getName();
}

View File

@ -1,31 +0,0 @@
package net.sourceforge.filebot.ui.panel.rename.similarity;
import net.sourceforge.filebot.ui.panel.rename.entry.ListEntry;
public class StringEqualsMetric extends SimilarityMetric {
@Override
public float getSimilarity(ListEntry a, ListEntry b) {
if (a.getName().equalsIgnoreCase(b.getName())) {
return 1;
}
return 0;
}
@Override
public String getDescription() {
return "Check whether names are equal or not";
}
@Override
public String getName() {
return "String";
}
}

View File

@ -1,42 +0,0 @@
package net.sourceforge.filebot.ui.panel.rename.similarity;
import net.sourceforge.filebot.ui.panel.rename.entry.ListEntry;
import uk.ac.shef.wit.simmetrics.similaritymetrics.AbstractStringMetric;
import uk.ac.shef.wit.simmetrics.similaritymetrics.MongeElkan;
public class StringSimilarityMetric extends SimilarityMetric {
private AbstractStringMetric metric;
public StringSimilarityMetric() {
this(new MongeElkan());
}
public StringSimilarityMetric(AbstractStringMetric metric) {
this.metric = metric;
}
@Override
public float getSimilarity(ListEntry a, ListEntry b) {
return metric.getSimilarity(a.getName(), b.getName());
}
@Override
public String getDescription() {
return "Similarity of names";
}
@Override
public String getName() {
return metric.getShortDescriptionString();
}
}

View File

@ -2,7 +2,7 @@
package net.sourceforge.filebot.ui.panel.search;
import javax.swing.ImageIcon;
import javax.swing.Icon;
import javax.swing.JComponent;
import net.sourceforge.filebot.resources.ResourceManager;
@ -14,7 +14,7 @@ public class EpisodeListPanel extends FileBotList {
private final FileBotTabComponent tabComponent = new FileBotTabComponent();
private ImageIcon icon;
private Icon icon;
private boolean loading = false;
@ -36,7 +36,7 @@ public class EpisodeListPanel extends FileBotList {
}
public void setIcon(ImageIcon icon) {
public void setIcon(Icon icon) {
synchronized (tabComponent) {
this.icon = icon;
@ -47,7 +47,7 @@ public class EpisodeListPanel extends FileBotList {
}
public ImageIcon getIcon() {
public Icon getIcon() {
return icon;
}

View File

@ -45,7 +45,6 @@ import net.sourceforge.tuned.ui.SelectButton;
import net.sourceforge.tuned.ui.SelectButtonTextField;
import net.sourceforge.tuned.ui.SimpleIconProvider;
import net.sourceforge.tuned.ui.SwingWorkerPropertyChangeAdapter;
import net.sourceforge.tuned.ui.TextCompletion;
import net.sourceforge.tuned.ui.TunedUtil;
@ -59,8 +58,6 @@ public class SearchPanel extends FileBotPanel {
private SelectButtonTextField<EpisodeListClient> searchField;
private TextCompletion searchFieldCompletion;
public SearchPanel() {
super("Search", ResourceManager.getIcon("panel.search"));
@ -132,7 +129,7 @@ public class SearchPanel extends FileBotPanel {
public void propertyChange(PropertyChangeEvent evt) {
EpisodeListClient client = searchField.getSelected();
if (!client.isSingleSeasonSupported()) {
if (!client.hasSingleSeasonSupport()) {
seasonSpinnerModel.setValue(SeasonSpinnerEditor.ALL_SEASONS);
seasonSpinnerModel.setMaximum(SeasonSpinnerEditor.ALL_SEASONS);
} else {
@ -275,7 +272,8 @@ public class SearchPanel extends FileBotPanel {
SelectDialog<SearchResult> select = new SelectDialog<SearchResult>(window, searchResults);
select.setText("Select a Show:");
select.setIconImage(episodeList.getIcon().getImage());
select.setIconImage(TunedUtil.getImage(episodeList.getIcon()));
select.setVisible(true);
selectedResult = select.getSelectedValue();
@ -290,7 +288,7 @@ public class SearchPanel extends FileBotPanel {
String title = selectedResult.getName();
searchFieldCompletion.addTerm(title);
// searchFieldCompletion.addTerm(title);
//TODO fix
// Settings.getSettings().putStringList(Settings.SEARCH_HISTORY, searchFieldCompletion.getTerms());

View File

@ -44,7 +44,7 @@ public class ChecksumComputationService {
private ChecksumComputationService() {
// hide constructor
}

View File

@ -1,139 +0,0 @@
package net.sourceforge.filebot.web;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sourceforge.filebot.resources.ResourceManager;
import net.sourceforge.tuned.XPathUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
public class TvdotcomClient extends EpisodeListClient {
private final SearchResultCache cache = new SearchResultCache();
private final String host = "www.tv.com";
public TvdotcomClient() {
super("TV.com", ResourceManager.getIcon("search.tvdotcom"), true);
}
@Override
public List<SearchResult> search(String searchterm) throws IOException, SAXException {
if (cache.containsKey(searchterm)) {
return Collections.singletonList(cache.get(searchterm));
}
Document dom = HtmlUtil.getHtmlDocument(getSearchUrl(searchterm));
List<Node> nodes = XPathUtil.selectNodes("id('search-results')//SPAN/A", dom);
List<SearchResult> searchResults = new ArrayList<SearchResult>(nodes.size());
for (Node node : nodes) {
String category = node.getParentNode().getTextContent();
// we only want search results that are shows
if (category.toLowerCase().startsWith("show")) {
String title = node.getTextContent();
String href = XPathUtil.selectString("@href", node);
try {
URL url = new URL(href);
searchResults.add(new HyperLink(title, url));
} catch (MalformedURLException e) {
Logger.getLogger(Logger.GLOBAL_LOGGER_NAME).log(Level.WARNING, "Invalid href: " + href, e);
}
}
}
cache.addAll(searchResults);
return searchResults;
}
@Override
public List<Episode> getEpisodeList(SearchResult searchResult, int season) throws IOException, SAXException {
Document dom = HtmlUtil.getHtmlDocument(getEpisodeListLink(searchResult, season));
List<Node> nodes = XPathUtil.selectNodes("id('episode-listing')/DIV/TABLE/TR/TD/ancestor::TR", dom);
NumberFormat numberFormat = NumberFormat.getInstance(Locale.ENGLISH);
numberFormat.setMinimumIntegerDigits(Math.max(Integer.toString(nodes.size()).length(), 2));
numberFormat.setGroupingUsed(false);
Integer episodeOffset = null;
String seasonString = (season >= 1) ? Integer.toString(season) : null;
ArrayList<Episode> episodes = new ArrayList<Episode>(nodes.size());
for (Node node : nodes) {
String episodeNumber = XPathUtil.selectString("./TD[1]", node);
String title = XPathUtil.selectString("./TD[2]/A", node);
try {
// format number of episode
int n = Integer.parseInt(episodeNumber);
if (episodeOffset == null)
episodeOffset = n - 1;
episodeNumber = numberFormat.format(n - episodeOffset);
} catch (NumberFormatException e) {
// episode number may be "Pilot", "Special", ...
}
episodes.add(new Episode(searchResult.getName(), seasonString, episodeNumber, title));
}
return episodes;
}
@Override
public URI getEpisodeListLink(SearchResult searchResult, int season) {
String summaryFile = ((HyperLink) searchResult).getUrl().getPath();
String base = summaryFile.substring(0, summaryFile.indexOf("summary.html"));
String file = base + "episode_listings.html";
String query = "season=" + season;
try {
return new URI("http", host, file, query, null);
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
}
private URL getSearchUrl(String searchterm) throws UnsupportedEncodingException, MalformedURLException {
String qs = URLEncoder.encode(searchterm, "UTF-8");
String file = "/search.php?qs=" + qs + "&type=11&stype=all";
return new URL("http", host, file);
}
}