Fixed issue with downloading images without an extension
This commit is contained in:
parent
eccce1b4a6
commit
19ce96eae5
@ -212,7 +212,7 @@ public abstract class AbstractRipper
|
|||||||
* True if downloaded successfully
|
* True if downloaded successfully
|
||||||
* False if failed to download
|
* False if failed to download
|
||||||
*/
|
*/
|
||||||
protected boolean addURLToDownload(URL url, String prefix, String subdirectory, String referrer, Map<String, String> cookies, String fileName) {
|
protected boolean addURLToDownload(URL url, String prefix, String subdirectory, String referrer, Map<String, String> cookies, String fileName, String extension) {
|
||||||
// Don't re-add the url if it was downloaded in a previous rip
|
// Don't re-add the url if it was downloaded in a previous rip
|
||||||
if (Utils.getConfigBoolean("remember.url_history", true) && !isThisATest()) {
|
if (Utils.getConfigBoolean("remember.url_history", true) && !isThisATest()) {
|
||||||
if (hasDownloadedURL(url.toExternalForm())) {
|
if (hasDownloadedURL(url.toExternalForm())) {
|
||||||
@ -228,21 +228,7 @@ public abstract class AbstractRipper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
logger.debug("url: " + url + ", prefix: " + prefix + ", subdirectory" + subdirectory + ", referrer: " + referrer + ", cookies: " + cookies + ", fileName: " + fileName);
|
logger.debug("url: " + url + ", prefix: " + prefix + ", subdirectory" + subdirectory + ", referrer: " + referrer + ", cookies: " + cookies + ", fileName: " + fileName);
|
||||||
String saveAs;
|
String saveAs = getFileName(url, fileName, extension);
|
||||||
if (fileName != null) {
|
|
||||||
saveAs = fileName;
|
|
||||||
// Get the extension of the file
|
|
||||||
String extension = url.toExternalForm().substring(url.toExternalForm().lastIndexOf(".") + 1);
|
|
||||||
saveAs = saveAs + "." + extension;
|
|
||||||
} else {
|
|
||||||
saveAs = url.toExternalForm();
|
|
||||||
saveAs = saveAs.substring(saveAs.lastIndexOf('/')+1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (saveAs.indexOf('?') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('?')); }
|
|
||||||
if (saveAs.indexOf('#') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('#')); }
|
|
||||||
if (saveAs.indexOf('&') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('&')); }
|
|
||||||
if (saveAs.indexOf(':') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf(':')); }
|
|
||||||
File saveFileAs;
|
File saveFileAs;
|
||||||
try {
|
try {
|
||||||
if (!subdirectory.equals("")) {
|
if (!subdirectory.equals("")) {
|
||||||
@ -274,6 +260,10 @@ public abstract class AbstractRipper
|
|||||||
return addURLToDownload(url, saveFileAs, referrer, cookies);
|
return addURLToDownload(url, saveFileAs, referrer, cookies);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean addURLToDownload(URL url, String prefix, String subdirectory, String referrer, Map<String, String> cookies, String fileName) {
|
||||||
|
return addURLToDownload(url, prefix, subdirectory, referrer, cookies, fileName, null);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queues file to be downloaded and saved. With options.
|
* Queues file to be downloaded and saved. With options.
|
||||||
* @param url
|
* @param url
|
||||||
@ -306,6 +296,35 @@ public abstract class AbstractRipper
|
|||||||
return addURLToDownload(url, prefix, "");
|
return addURLToDownload(url, prefix, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getFileName(URL url, String fileName, String extension) {
|
||||||
|
String saveAs;
|
||||||
|
if (fileName != null) {
|
||||||
|
saveAs = fileName;
|
||||||
|
} else {
|
||||||
|
saveAs = url.toExternalForm();
|
||||||
|
saveAs = saveAs.substring(saveAs.lastIndexOf('/')+1);
|
||||||
|
}
|
||||||
|
if (extension == null) {
|
||||||
|
// Get the extension of the file
|
||||||
|
String[] lastBitOfURL = url.toExternalForm().split("/");
|
||||||
|
|
||||||
|
String[] lastBit = lastBitOfURL[lastBitOfURL.length - 1].split(".");
|
||||||
|
if (lastBit.length != 0) {
|
||||||
|
extension = lastBit[lastBit.length - 1];
|
||||||
|
saveAs = saveAs + "." + extension;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveAs.indexOf('?') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('?')); }
|
||||||
|
if (saveAs.indexOf('#') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('#')); }
|
||||||
|
if (saveAs.indexOf('&') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf('&')); }
|
||||||
|
if (saveAs.indexOf(':') >= 0) { saveAs = saveAs.substring(0, saveAs.indexOf(':')); }
|
||||||
|
if (extension != null) {
|
||||||
|
saveAs = saveAs + "." + extension;
|
||||||
|
}
|
||||||
|
return saveAs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Waits for downloading threads to complete.
|
* Waits for downloading threads to complete.
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package com.rarchives.ripme.tst;
|
||||||
|
|
||||||
|
public class AbstractRipperTest {
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user