mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-22 13:33:18 +02:00
assure filname with prefix is file system safe
This commit is contained in:
@@ -10,6 +10,7 @@ import java.lang.reflect.Constructor;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -316,14 +317,13 @@ public abstract class AbstractRipper
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
LOGGER.debug("url: " + url + ", subdirectory" + subdirectory + ", referrer: " + referrer + ", cookies: " + cookies + ", prefix: " + prefix + ", fileName: " + fileName);
|
LOGGER.debug("url: " + url + ", subdirectory" + subdirectory + ", referrer: " + referrer + ", cookies: " + cookies + ", prefix: " + prefix + ", fileName: " + fileName);
|
||||||
String saveAs = getFileName(url, fileName, extension);
|
String saveAs = getFileName(url, prefix, fileName, extension);
|
||||||
File saveFileAs;
|
File saveFileAs;
|
||||||
try {
|
try {
|
||||||
if (!subdirectory.equals("")) {
|
if (!subdirectory.equals("")) {
|
||||||
subdirectory = Utils.filesystemSafe(subdirectory);
|
subdirectory = Utils.filesystemSafe(subdirectory);
|
||||||
subdirectory = File.separator + subdirectory;
|
subdirectory = File.separator + subdirectory;
|
||||||
}
|
}
|
||||||
prefix = Utils.filesystemSanitized(prefix);
|
|
||||||
String topFolderName = workingDir.getCanonicalPath();
|
String topFolderName = workingDir.getCanonicalPath();
|
||||||
if (App.stringToAppendToFoldername != null) {
|
if (App.stringToAppendToFoldername != null) {
|
||||||
topFolderName = topFolderName + App.stringToAppendToFoldername;
|
topFolderName = topFolderName + App.stringToAppendToFoldername;
|
||||||
@@ -332,7 +332,6 @@ public abstract class AbstractRipper
|
|||||||
topFolderName
|
topFolderName
|
||||||
+ subdirectory
|
+ subdirectory
|
||||||
+ File.separator
|
+ File.separator
|
||||||
+ prefix
|
|
||||||
+ saveAs);
|
+ saveAs);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOGGER.error("[!] Error creating save file path for URL '" + url + "':", e);
|
LOGGER.error("[!] Error creating save file path for URL '" + url + "':", e);
|
||||||
@@ -394,7 +393,7 @@ public abstract class AbstractRipper
|
|||||||
return addURLToDownload(url, prefix, "");
|
return addURLToDownload(url, prefix, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFileName(URL url, String fileName, String extension) {
|
public static String getFileName(URL url, String prefix, String fileName, String extension) {
|
||||||
// retrieve filename from URL if not passed
|
// retrieve filename from URL if not passed
|
||||||
if (fileName == null || fileName.trim().isEmpty()) {
|
if (fileName == null || fileName.trim().isEmpty()) {
|
||||||
fileName = url.toExternalForm();
|
fileName = url.toExternalForm();
|
||||||
@@ -405,6 +404,11 @@ public abstract class AbstractRipper
|
|||||||
if (fileName.indexOf('&') >= 0) { fileName = fileName.substring(0, fileName.indexOf('&')); }
|
if (fileName.indexOf('&') >= 0) { fileName = fileName.substring(0, fileName.indexOf('&')); }
|
||||||
if (fileName.indexOf(':') >= 0) { fileName = fileName.substring(0, fileName.indexOf(':')); }
|
if (fileName.indexOf(':') >= 0) { fileName = fileName.substring(0, fileName.indexOf(':')); }
|
||||||
|
|
||||||
|
// add prefix
|
||||||
|
if (prefix != null && !prefix.trim().isEmpty()) {
|
||||||
|
fileName = prefix + fileName;
|
||||||
|
}
|
||||||
|
|
||||||
// retrieve extension from URL if not passed, no extension if nothing found
|
// retrieve extension from URL if not passed, no extension if nothing found
|
||||||
if (extension == null || extension.trim().isEmpty()) {
|
if (extension == null || extension.trim().isEmpty()) {
|
||||||
// Get the extension of the file
|
// Get the extension of the file
|
||||||
|
Reference in New Issue
Block a user