1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-21 21:15:19 +02:00

assure filname with prefix is file system safe

This commit is contained in:
soloturn
2022-04-15 16:01:03 +02:00
parent 4be9ebaec7
commit 3eca9fa620

View File

@@ -10,6 +10,7 @@ import java.lang.reflect.Constructor;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -316,14 +317,13 @@ public abstract class AbstractRipper
return false;
}
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;
try {
if (!subdirectory.equals("")) {
subdirectory = Utils.filesystemSafe(subdirectory);
subdirectory = File.separator + subdirectory;
}
prefix = Utils.filesystemSanitized(prefix);
String topFolderName = workingDir.getCanonicalPath();
if (App.stringToAppendToFoldername != null) {
topFolderName = topFolderName + App.stringToAppendToFoldername;
@@ -332,7 +332,6 @@ public abstract class AbstractRipper
topFolderName
+ subdirectory
+ File.separator
+ prefix
+ saveAs);
} catch (IOException e) {
LOGGER.error("[!] Error creating save file path for URL '" + url + "':", e);
@@ -394,7 +393,7 @@ public abstract class AbstractRipper
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
if (fileName == null || fileName.trim().isEmpty()) {
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(':')); }
// add prefix
if (prefix != null && !prefix.trim().isEmpty()) {
fileName = prefix + fileName;
}
// retrieve extension from URL if not passed, no extension if nothing found
if (extension == null || extension.trim().isEmpty()) {
// Get the extension of the file