mirror of
https://github.com/mitb-archive/filebot
synced 2025-03-10 06:20:27 -04:00
* refactoring
This commit is contained in:
parent
67d53605af
commit
73273b8b5b
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||||
<project name="FileBot" default="jar">
|
<project name="FileBot" default="jar">
|
||||||
|
|
||||||
<property name="title" value="${ant.project.name}" />
|
<property name="title" value="${ant.project.name}" />
|
||||||
@ -15,7 +15,6 @@
|
|||||||
<property name="dir.lib" location="${basedir}/lib" />
|
<property name="dir.lib" location="${basedir}/lib" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<target name="jar" depends="build">
|
<target name="jar" depends="build">
|
||||||
<!-- create dist dir -->
|
<!-- create dist dir -->
|
||||||
<mkdir dir="${dir.dist}" />
|
<mkdir dir="${dir.dist}" />
|
||||||
@ -155,6 +154,7 @@
|
|||||||
</junit>
|
</junit>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
|
|
||||||
<target name="run-fatjar" depends="fatjar">
|
<target name="run-fatjar" depends="fatjar">
|
||||||
<java jar="${dir.dist}/fatjar/FileBot.jar" fork="true" />
|
<java jar="${dir.dist}/fatjar/FileBot.jar" fork="true" />
|
||||||
</target>
|
</target>
|
||||||
|
@ -548,7 +548,7 @@ class HistoryDialog extends JDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean accept(List<File> files) {
|
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
|
@Override
|
||||||
public String getFileFilterDescription() {
|
public String getFileFilterDescription() {
|
||||||
return "xml files";
|
return "history files (.xml.gz)";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -596,7 +596,7 @@ class HistoryDialog extends JDialog {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDefaultFileName() {
|
public String getDefaultFileName() {
|
||||||
return "history.xml";
|
return "history.xml.gz";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -145,11 +145,11 @@ public class SubsceneSubtitleClient implements SubtitleProvider {
|
|||||||
throw new IllegalArgumentException("Cannot parse download parameters: " + href);
|
throw new IllegalArgumentException("Cannot parse download parameters: " + href);
|
||||||
|
|
||||||
String subtitleId = matcher.group(1);
|
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) {
|
} catch (Exception e) {
|
||||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Cannot parse subtitle node", 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 basePath = FileUtilities.getNameWithoutExtension(referer.getFile());
|
||||||
String path = String.format("%s-dlpath-%s/%s.zipx", basePath, subtitleId, typeId);
|
String path = String.format("%s-dlpath-%s/%s.zipx", basePath, subtitleId, typeId);
|
||||||
|
|
||||||
|
@ -13,19 +13,19 @@ public class SubsceneSubtitleDescriptor implements SubtitleDescriptor {
|
|||||||
private final String title;
|
private final String title;
|
||||||
private final String language;
|
private final String language;
|
||||||
|
|
||||||
private final String typeId;
|
private final String archiveType;
|
||||||
|
|
||||||
private final URL downloadUrl;
|
private final URL downloadLink;
|
||||||
private final URL referer;
|
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.title = title;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
|
|
||||||
this.typeId = typeId;
|
this.archiveType = archiveType;
|
||||||
|
|
||||||
this.downloadUrl = downloadUrl;
|
this.downloadLink = downloadLink;
|
||||||
this.referer = referer;
|
this.referer = referer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ public class SubsceneSubtitleDescriptor implements SubtitleDescriptor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DownloadTask createDownloadTask() {
|
public DownloadTask createDownloadTask() {
|
||||||
DownloadTask downloadTask = new DownloadTask(downloadUrl);
|
DownloadTask downloadTask = new DownloadTask(downloadLink);
|
||||||
downloadTask.setRequestHeaders(Collections.singletonMap("Referer", referer.toString()));
|
downloadTask.setRequestHeaders(Collections.singletonMap("Referer", referer.toString()));
|
||||||
|
|
||||||
return downloadTask;
|
return downloadTask;
|
||||||
@ -52,7 +52,7 @@ public class SubsceneSubtitleDescriptor implements SubtitleDescriptor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getArchiveType() {
|
public String getArchiveType() {
|
||||||
return typeId;
|
return archiveType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
|
|
||||||
@ -26,9 +25,9 @@ import org.w3c.dom.Node;
|
|||||||
|
|
||||||
public class SubtitleSourceClient implements SubtitleProvider {
|
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
|
@Override
|
||||||
@ -51,29 +50,23 @@ public class SubtitleSourceClient implements SubtitleProvider {
|
|||||||
|
|
||||||
public List<SearchResult> search(String query, String language) throws Exception {
|
public List<SearchResult> search(String query, String language) throws Exception {
|
||||||
// e.g. http://www.subtitlesource.org/api/xmlsearch/firefly/all/0
|
// 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);
|
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)) {
|
for (Node node : selectNodes("//sub", dom)) {
|
||||||
Integer imdb = Integer.valueOf(getTextContent("imdb", node));
|
Integer imdb = Integer.valueOf(getTextContent("imdb", node));
|
||||||
|
|
||||||
if (!movieMap.containsKey(imdb)) {
|
if (!movieMap.containsKey(imdb)) {
|
||||||
String title = getTextContent("title", node);
|
String title = getTextContent("title", node);
|
||||||
movieMap.put(imdb, title);
|
|
||||||
|
movieMap.put(imdb, new MovieDescriptor(title, imdb));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create SearchResult collection
|
return new ArrayList<SearchResult>(movieMap.values());
|
||||||
List<SearchResult> result = new ArrayList<SearchResult>();
|
|
||||||
|
|
||||||
for (Entry<Integer, String> movie : movieMap.entrySet()) {
|
|
||||||
result.add(new MovieDescriptor(movie.getValue(), movie.getKey()));
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -97,13 +90,13 @@ public class SubtitleSourceClient implements SubtitleProvider {
|
|||||||
public List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult) throws Exception {
|
public List<SubtitleDescriptor> getSubtitleList(SearchResult searchResult) throws Exception {
|
||||||
List<SubtitleDescriptor> subtitles = new ArrayList<SubtitleDescriptor>();
|
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);
|
List<SubtitleDescriptor> page = getSubtitleList(searchResult, offset);
|
||||||
|
|
||||||
// add new subtitles
|
// add new subtitles
|
||||||
subtitles.addAll(page);
|
subtitles.addAll(page);
|
||||||
|
|
||||||
if (page.size() < PAGE_SIZE) {
|
if (page.size() < pageSize) {
|
||||||
// last page reached
|
// last page reached
|
||||||
return subtitles;
|
return subtitles;
|
||||||
}
|
}
|
||||||
@ -115,7 +108,7 @@ public class SubtitleSourceClient implements SubtitleProvider {
|
|||||||
int imdb = ((MovieDescriptor) searchResult).getImdbId();
|
int imdb = ((MovieDescriptor) searchResult).getImdbId();
|
||||||
|
|
||||||
// e.g. http://www.subtitlesource.org/api/xmlsearch/0303461/imdb/0
|
// 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);
|
Document dom = getDocument(url);
|
||||||
|
|
||||||
@ -129,7 +122,10 @@ public class SubtitleSourceClient implements SubtitleProvider {
|
|||||||
int season = Integer.parseInt(getTextContent("season", node));
|
int season = Integer.parseInt(getTextContent("season", node));
|
||||||
int episode = Integer.parseInt(getTextContent("episode", 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;
|
return subtitles;
|
||||||
@ -141,7 +137,7 @@ public class SubtitleSourceClient implements SubtitleProvider {
|
|||||||
int imdb = ((MovieDescriptor) searchResult).getImdbId();
|
int imdb = ((MovieDescriptor) searchResult).getImdbId();
|
||||||
|
|
||||||
try {
|
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) {
|
} catch (URISyntaxException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,6 @@
|
|||||||
package net.sourceforge.filebot.web;
|
package net.sourceforge.filebot.web;
|
||||||
|
|
||||||
|
|
||||||
import static net.sourceforge.filebot.web.SubtitleSourceClient.*;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
import net.sourceforge.tuned.DownloadTask;
|
import net.sourceforge.tuned.DownloadTask;
|
||||||
@ -12,8 +9,6 @@ import net.sourceforge.tuned.DownloadTask;
|
|||||||
|
|
||||||
public class SubtitleSourceSubtitleDescriptor implements SubtitleDescriptor {
|
public class SubtitleSourceSubtitleDescriptor implements SubtitleDescriptor {
|
||||||
|
|
||||||
private final int id;
|
|
||||||
|
|
||||||
private final String releaseName;
|
private final String releaseName;
|
||||||
private final String language;
|
private final String language;
|
||||||
|
|
||||||
@ -21,14 +16,16 @@ public class SubtitleSourceSubtitleDescriptor implements SubtitleDescriptor {
|
|||||||
private final int season;
|
private final int season;
|
||||||
private final int episode;
|
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.releaseName = releaseName;
|
||||||
this.language = language;
|
this.language = language;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.season = season;
|
this.season = season;
|
||||||
this.episode = episode;
|
this.episode = episode;
|
||||||
|
this.downloadLink = downloadLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -67,12 +64,7 @@ public class SubtitleSourceSubtitleDescriptor implements SubtitleDescriptor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DownloadTask createDownloadTask() {
|
public DownloadTask createDownloadTask() {
|
||||||
try {
|
return new DownloadTask(downloadLink);
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user