From 73273b8b5b0a8406f42ee5122e4caece522e64ad Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Thu, 21 May 2009 10:00:48 +0000 Subject: [PATCH] * refactoring --- build.xml | 6 ++-- .../ui/panel/rename/HistoryDialog.java | 6 ++-- .../filebot/web/SubsceneSubtitleClient.java | 8 ++--- .../web/SubsceneSubtitleDescriptor.java | 14 ++++---- .../filebot/web/SubtitleSourceClient.java | 34 ++++++++----------- .../web/SubtitleSourceSubtitleDescriptor.java | 18 +++------- 6 files changed, 37 insertions(+), 49 deletions(-) diff --git a/build.xml b/build.xml index bd82b618..01cb1c75 100644 --- a/build.xml +++ b/build.xml @@ -1,6 +1,6 @@ - + - + @@ -15,7 +15,6 @@ - @@ -155,6 +154,7 @@ + diff --git a/source/net/sourceforge/filebot/ui/panel/rename/HistoryDialog.java b/source/net/sourceforge/filebot/ui/panel/rename/HistoryDialog.java index 31a6bc37..92eafc28 100644 --- a/source/net/sourceforge/filebot/ui/panel/rename/HistoryDialog.java +++ b/source/net/sourceforge/filebot/ui/panel/rename/HistoryDialog.java @@ -548,7 +548,7 @@ class HistoryDialog extends JDialog { @Override protected boolean accept(List 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"; } }; diff --git a/source/net/sourceforge/filebot/web/SubsceneSubtitleClient.java b/source/net/sourceforge/filebot/web/SubsceneSubtitleClient.java index ac77afa5..9399b08b 100644 --- a/source/net/sourceforge/filebot/web/SubsceneSubtitleClient.java +++ b/source/net/sourceforge/filebot/web/SubsceneSubtitleClient.java @@ -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); diff --git a/source/net/sourceforge/filebot/web/SubsceneSubtitleDescriptor.java b/source/net/sourceforge/filebot/web/SubsceneSubtitleDescriptor.java index e9716141..53b3e368 100644 --- a/source/net/sourceforge/filebot/web/SubsceneSubtitleDescriptor.java +++ b/source/net/sourceforge/filebot/web/SubsceneSubtitleDescriptor.java @@ -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; } diff --git a/source/net/sourceforge/filebot/web/SubtitleSourceClient.java b/source/net/sourceforge/filebot/web/SubtitleSourceClient.java index bad4712a..a477b4cf 100644 --- a/source/net/sourceforge/filebot/web/SubtitleSourceClient.java +++ b/source/net/sourceforge/filebot/web/SubtitleSourceClient.java @@ -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 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 movieMap = new LinkedHashMap(); + Map movieMap = new LinkedHashMap(); 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 result = new ArrayList(); - - for (Entry movie : movieMap.entrySet()) { - result.add(new MovieDescriptor(movie.getValue(), movie.getKey())); - } - - return result; + return new ArrayList(movieMap.values()); } @@ -97,13 +90,13 @@ public class SubtitleSourceClient implements SubtitleProvider { public List getSubtitleList(SearchResult searchResult) throws Exception { List subtitles = new ArrayList(); - for (int offset = 0; true; offset += PAGE_SIZE) { + for (int offset = 0; true; offset += pageSize) { List 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); } diff --git a/source/net/sourceforge/filebot/web/SubtitleSourceSubtitleDescriptor.java b/source/net/sourceforge/filebot/web/SubtitleSourceSubtitleDescriptor.java index af459188..052dc685 100644 --- a/source/net/sourceforge/filebot/web/SubtitleSourceSubtitleDescriptor.java +++ b/source/net/sourceforge/filebot/web/SubtitleSourceSubtitleDescriptor.java @@ -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); }