Skip to content

Commit

Permalink
原图下载
Browse files Browse the repository at this point in the history
  • Loading branch information
dipoo committed Mar 30, 2016
1 parent 1a85d1b commit bcd80af
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
8 changes: 6 additions & 2 deletions script/download.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var mark = {
original : ['http://exhentai.org/fullimg.php', '">Download original'],
realUrl : ['<img id="img" src="', '" style=']
};

Expand All @@ -9,7 +10,10 @@ function interceptFromSource(source, prefix, suffix){
}

function parse(source){
var realUrl = interceptFromSource(source, mark.realUrl[0], mark.realUrl[1]);
return realUrl;
if("undefined" != typeof down_original && down_original && source.indexOf(mark.original[0]) != -1){
return mark.original[0] + interceptFromSource(source, mark.original[0], mark.original[1]).replace(/&amp;/g, '&');
}else{
return interceptFromSource(source, mark.realUrl[0], mark.realUrl[1]);
}
}
parse(htmlSource);
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ private Element setting2Element(Setting t) {
ele.addAttribute("cookieInfo", t.getCookieInfo());
ele.addAttribute("saveAsName", t.isSaveAsName() + "");
ele.addAttribute("autoDownload", t.isAutoDownload() + "");
ele.addAttribute("downloadOriginal", t.isDownloadOriginal() + "");
ele.addAttribute("maxThread", t.getMaxThread() + "");
/*ele.addAttribute("gidPrefix", t.getGidPrefix());
ele.addAttribute("hentaiHome.uri", t.getHentaiHome().getUri());
Expand Down Expand Up @@ -236,6 +237,7 @@ private Setting node2Setting(Node node) {
t.setCookieInfo(ele.attributeValue("cookieInfo") == null ? t.getCookieInfo() : ele.attributeValue("cookieInfo"));
t.setSaveAsName("true".equals(ele.attributeValue("saveAsName")) ? true : false);
t.setAutoDownload("true".equals(ele.attributeValue("autoDownload")) ? true : false);
t.setDownloadOriginal("true".equals(ele.attributeValue("downloadOriginal")) ? true : false);
t.setGidPrefix(ele.attributeValue("gidPrefix") == null ? t.getGidPrefix() : ele.attributeValue("gidPrefix"));
t.setMaxThread(ele.attributeValue("maxThread") == null ? 0 : Integer.parseInt(ele.attributeValue("maxThread")));
/*t.getHentaiHome().setUri(ele.attributeValue("hentaiHome.uri"));
Expand Down
2 changes: 2 additions & 0 deletions src/org/arong/egdownloader/model/ScriptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,10 @@ public static String getdownloadUrl(String taskName, String sourceUrl, Setting s
try {
Map<String, Object> param = new HashMap<String, Object>();
param.put("htmlSource", source);
param.put("down_original", setting.isDownloadOriginal());//是否下载原图
url = parseJsScript(param, getDownloadScriptFile(setting.getDownloadScriptPath())).toString();
} catch (Exception e) {
e.printStackTrace();
Tracker.println(ScriptParser.class, taskName + ":getdownloadUrl异常,请检查" + setting.getDownloadScriptPath() + "脚本是否出现问题!");
return null;
}
Expand Down
7 changes: 7 additions & 0 deletions src/org/arong/egdownloader/model/Setting.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class Setting {
private String defaultSaveDir = "save";//默认保存路劲
private boolean saveAsName = false;//是否以真实名称保存
private boolean autoDownload;//创建任务后是否自动下载
private boolean downloadOriginal = true;//下载原图
private int maxThread = 5;
private String cookieInfo = "igneous=4baadb8381b3bb5c20257b33b725e4ec93f51b4fe2ab7e97621c9fe260bbda7de47a44d6394b31783a0af329a20197c80d2ab687ccf0b667ca5c558ee1b9310b;ipb_member_id=1059070;ipb_pass_hash=e8e36f507753214279ee9df5d98c476c;";

Expand Down Expand Up @@ -382,4 +383,10 @@ public String getProxyPwd() {
public void setProxyPwd(String proxyPwd) {
this.proxyPwd = proxyPwd;
}
public boolean isDownloadOriginal() {
return downloadOriginal;
}
public void setDownloadOriginal(boolean downloadOriginal) {
this.downloadOriginal = downloadOriginal;
}
}
13 changes: 10 additions & 3 deletions src/org/arong/egdownloader/spider/WebClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ public static String postRequest(String url, String encoding) throws ConnectTime
public static String postRequestWithCookie(String url, String cookieInfo) throws ConnectTimeoutException, SocketTimeoutException, WebClientException{
return postRequestWithCookie(url, "utf-8", null, cookieInfo);
}
public static String postRequestWithCookie(String url, String encoding, Map<String, String> rawParams, String cookieInfo) throws WebClientException, ConnectTimeoutException, SocketTimeoutException {
return postRequestWithCookie( url, encoding, rawParams, cookieInfo, true);
}


/**
* @param url
* 发送请求的URL
Expand All @@ -64,7 +66,7 @@ public static String postRequestWithCookie(String url, String cookieInfo) throws
* @throws ConnectTimeoutException
* @throws SocketTimeoutException
*/
public static String postRequestWithCookie(String url, String encoding, Map<String, String> rawParams, String cookieInfo) throws WebClientException, ConnectTimeoutException, SocketTimeoutException {
public static String postRequestWithCookie(String url, String encoding, Map<String, String> rawParams, String cookieInfo, boolean requestLocation) throws WebClientException, ConnectTimeoutException, SocketTimeoutException {
HttpClient httpClient = Proxy.getHttpClient();
// 创建HttpPost对象。
PostMethod postMethod = new PostMethod(url);
Expand Down Expand Up @@ -105,7 +107,12 @@ public static String postRequestWithCookie(String url, String encoding, Map<Stri
}else if (statusCode == 302) {
// 重定向
String location = postMethod.getResponseHeader("Location").getValue();
return postRequestWithCookie(location, encoding, rawParams, cookieInfo);
if(requestLocation){
return postRequestWithCookie(location, encoding, rawParams, cookieInfo);
}else{
return location;
}

}
} catch (SocketTimeoutException e1){
throw e1;
Expand Down
18 changes: 13 additions & 5 deletions src/org/arong/egdownloader/ui/window/SettingWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public class SettingWindow extends JFrame{
public JCheckBox saveAsNameBox;
JLabel autoDownloadLabel;
public JCheckBox autoDownloadBox;
JLabel downloadOriginalLabel;
public JCheckBox downloadOriginalBox;
JLabel maxThreadLabel;
public JTextField maxThreadField;
JLabel loginUrlLabel;
Expand Down Expand Up @@ -176,12 +178,15 @@ public void doWork(Window window, MouseEvent e) {
//当存在原图时,下载原图http://exhentai.org/s/72aa78ff00/913125-7
saveAsNameLabel = new AJLabel("以真实名称保存:", labelColor, 25, 70, 100, 30);
saveAsNameBox = new JCheckBox("", setting.isSaveAsName());
saveAsNameBox.setBounds(120, 70, 30, 30);
autoDownloadLabel = new AJLabel("创建后自动下载:", labelColor, 360, 70, 100, 30);
saveAsNameBox.setBounds(118, 70, 30, 30);
autoDownloadLabel = new AJLabel("创建后自动下载:", labelColor, 200, 70, 100, 30);
autoDownloadBox = new JCheckBox("", setting.isAutoDownload());
autoDownloadBox.setBounds(460, 70, 30, 30);
autoDownloadBox.setBounds(290, 70, 30, 30);
downloadOriginalLabel = new AJLabel("下载原图:", labelColor, 400, 70, 100, 30);
downloadOriginalBox = new JCheckBox("", setting.isDownloadOriginal());
downloadOriginalBox.setBounds(460, 70, 30, 30);
maxThreadLabel = new AJLabel("最多开启任务数:", labelColor, 25, 110, 100, 30);
maxThreadField = new AJTextField(setting.getMaxThread() + "", "", 125, 110, 100, 30);
maxThreadField = new AJTextField(setting.getMaxThread() + "", "", 125, 110, 60, 30);
loginUrlLabel = new AJLabel("登录地址:", labelColor, 25, 150, 100, 30);
loginUrlField = new AJTextField(setting.getLoginUrl(), "", 125, 150, 360, 30);
cookieLabel = new AJLabel("登录信息:", labelColor, 25, 190, 100, 30);
Expand Down Expand Up @@ -210,7 +215,8 @@ public void doWork(Window window, MouseEvent e) {
}
}), 500, 290, 60, 30);
addComponentsJpanel(basicPanel, saveDirLabel, saveDirField, browseDirButton, openDirButton,
saveAsNameLabel, saveAsNameBox, autoDownloadLabel,autoDownloadBox, maxThreadLabel, maxThreadField,
saveAsNameLabel, saveAsNameBox, autoDownloadLabel, autoDownloadBox, downloadOriginalLabel,
downloadOriginalBox, maxThreadLabel, maxThreadField,
loginUrlLabel, loginUrlField, cookieLabel, cookieArea,
cookieButton, resumeButton);

Expand Down Expand Up @@ -339,6 +345,7 @@ public void doWork(Window window, MouseEvent e) {
String loginUrl = settingWindow.loginUrlField.getText();
boolean saveAsName = settingWindow.saveAsNameBox.getSelectedObjects() == null ? false : true;//是否选择了
boolean autoDownload = settingWindow.autoDownloadBox.getSelectedObjects() == null ? false : true;
boolean downloadOriginal = settingWindow.downloadOriginalBox.getSelectedObjects() == null ? false : true;
String cookieInfo = settingWindow.cookieArea.getText();
Pattern p = Pattern.compile("[0-9]");
if("".equals(saveDir)){
Expand All @@ -363,6 +370,7 @@ public void doWork(Window window, MouseEvent e) {
setting.setDefaultSaveDir(saveDir);
setting.setSaveAsName(saveAsName);
setting.setAutoDownload(autoDownload);
setting.setDownloadOriginal(downloadOriginal);
setting.setMaxThread(Integer.parseInt(maxThread));
setting.setLoginUrl(loginUrl);
setting.setCookieInfo(cookieInfo);
Expand Down
3 changes: 2 additions & 1 deletion src/org/arong/egdownloader/ui/work/DownloadWorker.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ protected Void doInBackground() throws Exception {
if(this.isCancelled())//是否暂停
return null;
if(pic.getRealUrl().contains("exhentai.org")){
is = WebClient.postRequestAsStreamWithCookie(pic.getRealUrl(), setting.getCookieInfo());
pic.setRealUrl(WebClient.postRequestWithCookie(pic.getRealUrl(), "utf-8", null, setting.getCookieInfo(), false));
is = WebClient.getStreamUseJava(pic.getRealUrl());
}else{
is = WebClient.getStreamUseJava(pic.getRealUrl());
}
Expand Down

0 comments on commit bcd80af

Please sign in to comment.