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:
@@ -6,7 +6,6 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
@@ -287,9 +286,9 @@ public class RedditRipper extends AlbumRipper {
|
|||||||
).renderFormatted();
|
).renderFormatted();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
saveFileAs = Paths.get(workingDir
|
saveFileAs = Utils.getPath(workingDir
|
||||||
+ "/"
|
+ "/"
|
||||||
+ id + "_" + title.replaceAll("[\\\\/:*?\"<>|]", "")
|
+ id + "_" + title
|
||||||
+ ".html");
|
+ ".html");
|
||||||
OutputStream out = Files.newOutputStream(saveFileAs);
|
OutputStream out = Files.newOutputStream(saveFileAs);
|
||||||
out.write(html.getBytes());
|
out.write(html.getBytes());
|
||||||
@@ -406,7 +405,7 @@ public class RedditRipper extends AlbumRipper {
|
|||||||
// It's from reddituploads. Assume .jpg extension.
|
// It's from reddituploads. Assume .jpg extension.
|
||||||
String savePath = this.workingDir + "/";
|
String savePath = this.workingDir + "/";
|
||||||
savePath += id + "-" + m.group(1) + title + ".jpg";
|
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")) {
|
if (url.contains("v.redd.it")) {
|
||||||
String savePath = this.workingDir + "/";
|
String savePath = this.workingDir + "/";
|
||||||
@@ -414,7 +413,7 @@ public class RedditRipper extends AlbumRipper {
|
|||||||
URL urlToDownload = parseRedditVideoMPD(urls.get(0).toExternalForm());
|
URL urlToDownload = parseRedditVideoMPD(urls.get(0).toExternalForm());
|
||||||
if (urlToDownload != null) {
|
if (urlToDownload != null) {
|
||||||
LOGGER.info("url: " + urlToDownload + " file: " + savePath);
|
LOGGER.info("url: " + urlToDownload + " file: " + savePath);
|
||||||
addURLToDownload(urlToDownload, Paths.get(savePath));
|
addURLToDownload(urlToDownload, Utils.getPath(savePath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@@ -830,8 +830,12 @@ public class Utils {
|
|||||||
return Files.exists(folder.resolve(filename));
|
return Files.exists(folder.resolve(filename));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Path getPath(String pathToSanitize) {
|
||||||
|
return Paths.get(sanitizeSaveAs(pathToSanitize));
|
||||||
|
}
|
||||||
|
|
||||||
public static String sanitizeSaveAs(String fileNameToSan) {
|
public static String sanitizeSaveAs(String fileNameToSan) {
|
||||||
return fileNameToSan.replaceAll("[\\\\/:*?\"<>|]", "_");
|
return fileNameToSan.replaceAll("[\\\\:*?\"<>|]", "_");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Path shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException {
|
public static Path shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException {
|
||||||
|
Reference in New Issue
Block a user