1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-22 13:33:18 +02:00

reddit sanitize filename, fixes #82

sanitize now does not care about / in filenames any more, it is
a subdirectory then. in case some pieces of code rely on replacing
a /, fix it later and different.
This commit is contained in:
soloturn
2022-04-22 08:41:03 +02:00
parent 01fc7acdf4
commit f728bed5d2
2 changed files with 9 additions and 6 deletions

View File

@@ -6,7 +6,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
@@ -287,9 +286,9 @@ public class RedditRipper extends AlbumRipper {
).renderFormatted();
try {
saveFileAs = Paths.get(workingDir
saveFileAs = Utils.getPath(workingDir
+ "/"
+ id + "_" + title.replaceAll("[\\\\/:*?\"<>|]", "")
+ id + "_" + title
+ ".html");
OutputStream out = Files.newOutputStream(saveFileAs);
out.write(html.getBytes());
@@ -406,7 +405,7 @@ public class RedditRipper extends AlbumRipper {
// It's from reddituploads. Assume .jpg extension.
String savePath = this.workingDir + "/";
savePath += id + "-" + m.group(1) + title + ".jpg";
addURLToDownload(urls.get(0), Paths.get(savePath));
addURLToDownload(urls.get(0), Utils.getPath(savePath));
}
if (url.contains("v.redd.it")) {
String savePath = this.workingDir + "/";
@@ -414,7 +413,7 @@ public class RedditRipper extends AlbumRipper {
URL urlToDownload = parseRedditVideoMPD(urls.get(0).toExternalForm());
if (urlToDownload != null) {
LOGGER.info("url: " + urlToDownload + " file: " + savePath);
addURLToDownload(urlToDownload, Paths.get(savePath));
addURLToDownload(urlToDownload, Utils.getPath(savePath));
}
}
else {

View File

@@ -830,8 +830,12 @@ public class Utils {
return Files.exists(folder.resolve(filename));
}
public static Path getPath(String pathToSanitize) {
return Paths.get(sanitizeSaveAs(pathToSanitize));
}
public static String sanitizeSaveAs(String fileNameToSan) {
return fileNameToSan.replaceAll("[\\\\/:*?\"<>|]", "_");
return fileNameToSan.replaceAll("[\\\\:*?\"<>|]", "_");
}
public static Path shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException {