* refactoring

This commit is contained in:
Reinhard Pointner 2009-05-21 10:00:48 +00:00
parent 67d53605af
commit 73273b8b5b
6 changed files with 37 additions and 49 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project name="FileBot" default="jar">
<property name="title" value="${ant.project.name}" />
<property name="version" value="1.9" />
@ -15,7 +15,6 @@
<property name="dir.lib" location="${basedir}/lib" />
<target name="jar" depends="build">
<!-- create dist dir -->
<mkdir dir="${dir.dist}" />
@ -155,6 +154,7 @@
</junit>
</target>
<target name="run-fatjar" depends="fatjar">
<java jar="${dir.dist}/fatjar/FileBot.jar" fork="true" />
</target>

View File

@ -548,7 +548,7 @@ class HistoryDialog extends JDialog {
@Override
protected boolean accept(List<File> files) {
return FileUtilities.containsOnly(files, new ExtensionFileFilter("xml"));
return FileUtilities.containsOnly(files, new ExtensionFileFilter("xml", "gz"));
}
@ -575,7 +575,7 @@ class HistoryDialog extends JDialog {
@Override
public String getFileFilterDescription() {
return "xml files";
return "history files (.xml.gz)";
}
};
@ -596,7 +596,7 @@ class HistoryDialog extends JDialog {
@Override
public String getDefaultFileName() {
return "history.xml";
return "history.xml.gz";
}
};

View File

@ -145,11 +145,11 @@ public class SubsceneSubtitleClient implements SubtitleProvider {
throw new IllegalArgumentException("Cannot parse download parameters: " + href);
String subtitleId = matcher.group(1);
String typeId = matcher.group(2);
String archiveType = matcher.group(2);
URL downloadUrl = getDownloadUrl(subtitleListUrl, subtitleId, typeId);
URL downloadUrl = getDownloadLink(subtitleListUrl, subtitleId, archiveType);
subtitles.add(new SubsceneSubtitleDescriptor(name, lang, typeId, downloadUrl, subtitleListUrl));
subtitles.add(new SubsceneSubtitleDescriptor(name, lang, archiveType, downloadUrl, subtitleListUrl));
}
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Cannot parse subtitle node", e);
@ -197,7 +197,7 @@ public class SubsceneSubtitleClient implements SubtitleProvider {
}
protected URL getDownloadUrl(URL referer, String subtitleId, String typeId) throws MalformedURLException {
protected URL getDownloadLink(URL referer, String subtitleId, String typeId) throws MalformedURLException {
String basePath = FileUtilities.getNameWithoutExtension(referer.getFile());
String path = String.format("%s-dlpath-%s/%s.zipx", basePath, subtitleId, typeId);

View File

@ -13,19 +13,19 @@ public class SubsceneSubtitleDescriptor implements SubtitleDescriptor {
private final String title;
private final String language;
private final String typeId;
private final String archiveType;
private final URL downloadUrl;
private final URL downloadLink;
private final URL referer;
public SubsceneSubtitleDescriptor(String title, String language, String typeId, URL downloadUrl, URL referer) {
public SubsceneSubtitleDescriptor(String title, String language, String archiveType, URL downloadLink, URL referer) {
this.title = title;
this.language = language;
this.typeId = typeId;
this.archiveType = archiveType;
this.downloadUrl = downloadUrl;
this.downloadLink = downloadLink;
this.referer = referer;
}
@ -43,7 +43,7 @@ public class SubsceneSubtitleDescriptor implements SubtitleDescriptor {
@Override
public DownloadTask createDownloadTask() {
DownloadTask downloadTask = new DownloadTask(downloadUrl);
DownloadTask downloadTask = new DownloadTask(downloadLink);
downloadTask.setRequestHeaders(Collections.singletonMap("Referer", referer.toString()));
return downloadTask;
@ -52,7 +52,7 @@ public class SubsceneSubtitleDescriptor implements SubtitleDescriptor {
@Override
public String getArchiveType() {
return typeId;
return archiveType;
}

View File

@ -14,7 +14,6 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import javax.swing.Icon;
@ -26,9 +25,9 @@ import org.w3c.dom.Node;
public class SubtitleSourceClient implements SubtitleProvider {
protected static final String HOST = "www.subtitlesource.org";
private static final String host = "www.subtitlesource.org";
private static final int PAGE_SIZE = 20;
private static final int pageSize = 20;
@Override
@ -51,29 +50,23 @@ public class SubtitleSourceClient implements SubtitleProvider {
public List<SearchResult> search(String query, String language) throws Exception {
// e.g. http://www.subtitlesource.org/api/xmlsearch/firefly/all/0
URL url = new URL("http", HOST, "/api/xmlsearch/" + URLEncoder.encode(query, "utf-8") + "/" + language + "/0");
URL url = new URL("http", host, "/api/xmlsearch/" + URLEncoder.encode(query, "utf-8") + "/" + language + "/0");
Document dom = getDocument(url);
Map<Integer, String> movieMap = new LinkedHashMap<Integer, String>();
Map<Integer, MovieDescriptor> movieMap = new LinkedHashMap<Integer, MovieDescriptor>();
for (Node node : selectNodes("//sub", dom)) {
Integer imdb = Integer.valueOf(getTextContent("imdb", node));
if (!movieMap.containsKey(imdb)) {
String title = getTextContent("title", node);
movieMap.put(imdb, title);
movieMap.put(imdb, new MovieDescriptor(title, imdb));
}
}
// create SearchResult collection
List<SearchResult> result = new ArrayList<SearchResult>();
for (Entry<Integer, String> movie : movieMap.entrySet()) {
result.add(new MovieDescriptor(movie.getValue(), movie.getKey()));
}
return result;
return new ArrayList<SearchResult>(movieMap.values());
}
@ -97,13 +90,13 @@ public class SubtitleSourceClient implements SubtitleProvider {
public List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult) throws Exception {
List<SubtitleDescriptor> subtitles = new ArrayList<SubtitleDescriptor>();
for (int offset = 0; true; offset += PAGE_SIZE) {
for (int offset = 0; true; offset += pageSize) {
List<SubtitleDescriptor> page = getSubtitleList(searchResult, offset);
// add new subtitles
subtitles.addAll(page);
if (page.size() < PAGE_SIZE) {
if (page.size() < pageSize) {
// last page reached
return subtitles;
}
@ -115,7 +108,7 @@ public class SubtitleSourceClient implements SubtitleProvider {
int imdb = ((MovieDescriptor) searchResult).getImdbId();
// e.g. http://www.subtitlesource.org/api/xmlsearch/0303461/imdb/0
URL url = new URL("http", HOST, "/api/xmlsearch/" + imdb + "/imdb/" + offset);
URL url = new URL("http", host, "/api/xmlsearch/" + imdb + "/imdb/" + offset);
Document dom = getDocument(url);
@ -129,7 +122,10 @@ public class SubtitleSourceClient implements SubtitleProvider {
int season = Integer.parseInt(getTextContent("season", node));
int episode = Integer.parseInt(getTextContent("episode", node));
subtitles.add(new SubtitleSourceSubtitleDescriptor(id, releaseName, language, title, season, episode));
// e.g. http://www.subtitlesource.org/download/zip/760
URL downloadLink = new URL("http", host, "/download/zip/" + id);
subtitles.add(new SubtitleSourceSubtitleDescriptor(releaseName, language, title, season, episode, downloadLink));
}
return subtitles;
@ -141,7 +137,7 @@ public class SubtitleSourceClient implements SubtitleProvider {
int imdb = ((MovieDescriptor) searchResult).getImdbId();
try {
return new URI("http://" + HOST + "/title/" + String.format("tt%07d", imdb));
return new URI("http://" + host + "/title/" + String.format("tt%07d", imdb));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}

View File

@ -2,9 +2,6 @@
package net.sourceforge.filebot.web;
import static net.sourceforge.filebot.web.SubtitleSourceClient.*;
import java.net.MalformedURLException;
import java.net.URL;
import net.sourceforge.tuned.DownloadTask;
@ -12,8 +9,6 @@ import net.sourceforge.tuned.DownloadTask;
public class SubtitleSourceSubtitleDescriptor implements SubtitleDescriptor {
private final int id;
private final String releaseName;
private final String language;
@ -21,14 +16,16 @@ public class SubtitleSourceSubtitleDescriptor implements SubtitleDescriptor {
private final int season;
private final int episode;
private final URL downloadLink;
public SubtitleSourceSubtitleDescriptor(int id, String releaseName, String language, String title, int season, int episode) {
this.id = id;
public SubtitleSourceSubtitleDescriptor(String releaseName, String language, String title, int season, int episode, URL downloadLink) {
this.releaseName = releaseName;
this.language = language;
this.title = title;
this.season = season;
this.episode = episode;
this.downloadLink = downloadLink;
}
@ -67,12 +64,7 @@ public class SubtitleSourceSubtitleDescriptor implements SubtitleDescriptor {
@Override
public DownloadTask createDownloadTask() {
try {
// e.g. http://www.subtitlesource.org/download/zip/760
return new DownloadTask(new URL("http", HOST, "/download/zip/" + id));
} catch (MalformedURLException e) {
throw new UnsupportedOperationException(e);
}
return new DownloadTask(downloadLink);
}