mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-09-02 18:33:13 +02:00
Utils.removeCWD java.nio
This commit is contained in:
@@ -315,7 +315,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
||||
|| itemsCompleted.containsKey(url)
|
||||
|| itemsErrored.containsKey(url) )) {
|
||||
// Item is already downloaded/downloading, skip it.
|
||||
LOGGER.info("[!] Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs.toFile()));
|
||||
LOGGER.info("[!] Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs));
|
||||
return false;
|
||||
}
|
||||
if (Utils.getConfigBoolean("urls_only.save", false)) {
|
||||
@@ -371,7 +371,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String path = Utils.removeCWD(saveAs);
|
||||
String path = Utils.removeCWD(saveAs.toPath());
|
||||
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, path);
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, saveAs);
|
||||
@@ -457,7 +457,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
||||
|
||||
this.workingDir = new File(path);
|
||||
if (!this.workingDir.exists()) {
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir));
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir.toPath()));
|
||||
if (!this.workingDir.mkdirs()) {
|
||||
throw new IOException("Failed creating dir: \"" + this.workingDir + "\"");
|
||||
}
|
||||
|
@@ -10,7 +10,9 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
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.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -154,7 +156,7 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
|
||||
|| itemsCompleted.containsKey(url)
|
||||
|| itemsErrored.containsKey(url) )) {
|
||||
// Item is already downloaded/downloading, skip it.
|
||||
LOGGER.info("[!] Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs.toFile()));
|
||||
LOGGER.info("[!] Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs));
|
||||
return false;
|
||||
}
|
||||
if (Utils.getConfigBoolean("urls_only.save", false)) {
|
||||
@@ -210,7 +212,7 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String path = Utils.removeCWD(saveAs);
|
||||
String path = Utils.removeCWD(saveAs.toPath());
|
||||
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, path);
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, saveAs);
|
||||
@@ -277,11 +279,6 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
|
||||
@Override
|
||||
public void setWorkingDir(URL url) throws IOException {
|
||||
Path wd = Utils.getWorkingDirectory();
|
||||
// TODO - change to nio
|
||||
String path = wd.toAbsolutePath().toString();
|
||||
if (!path.endsWith(File.separator)) {
|
||||
path += File.separator;
|
||||
}
|
||||
String title;
|
||||
if (Utils.getConfigBoolean("album_titles.save", true)) {
|
||||
title = getAlbumTitle(this.url);
|
||||
@@ -291,15 +288,11 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
|
||||
LOGGER.debug("Using album title '" + title + "'");
|
||||
|
||||
title = Utils.filesystemSafe(title);
|
||||
path += title;
|
||||
path = Utils.getOriginalDirectory(path) + File.separator; // check for case sensitive (unix only)
|
||||
|
||||
this.workingDir = new File(path);
|
||||
if (!this.workingDir.exists()) {
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir));
|
||||
if (!this.workingDir.mkdirs()) {
|
||||
throw new IOException("Failed creating dir: \"" + this.workingDir + "\"");
|
||||
}
|
||||
wd = wd.resolve(title);
|
||||
if (!Files.exists(wd)) {
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(wd));
|
||||
Files.createDirectory(wd);
|
||||
this.workingDir = wd.toFile();
|
||||
}
|
||||
LOGGER.debug("Set working directory to: " + this.workingDir);
|
||||
}
|
||||
|
@@ -63,7 +63,7 @@ public abstract class AlbumRipper extends AbstractRipper {
|
||||
|| itemsCompleted.containsKey(url)
|
||||
|| itemsErrored.containsKey(url) )) {
|
||||
// Item is already downloaded/downloading, skip it.
|
||||
LOGGER.info("[!] Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs.toFile()));
|
||||
LOGGER.info("[!] Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs));
|
||||
return false;
|
||||
}
|
||||
if (Utils.getConfigBoolean("urls_only.save", false)) {
|
||||
@@ -119,7 +119,7 @@ public abstract class AlbumRipper extends AbstractRipper {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String path = Utils.removeCWD(saveAs);
|
||||
String path = Utils.removeCWD(saveAs.toPath());
|
||||
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, path);
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, saveAs);
|
||||
@@ -205,7 +205,7 @@ public abstract class AlbumRipper extends AbstractRipper {
|
||||
|
||||
this.workingDir = new File(path);
|
||||
if (!this.workingDir.exists()) {
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir));
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir.toPath()));
|
||||
this.workingDir.mkdirs();
|
||||
}
|
||||
LOGGER.debug("Set working directory to: " + this.workingDir);
|
||||
|
@@ -45,7 +45,7 @@ class DownloadFileThread extends Thread {
|
||||
super();
|
||||
this.url = url;
|
||||
this.saveAs = saveAs;
|
||||
this.prettySaveAs = Utils.removeCWD(saveAs);
|
||||
this.prettySaveAs = Utils.removeCWD(saveAs.toPath());
|
||||
this.observer = observer;
|
||||
this.retries = Utils.getConfigInteger("download.retries", 1);
|
||||
this.TIMEOUT = Utils.getConfigInteger("download.timeout", 60000);
|
||||
|
@@ -34,7 +34,7 @@ class DownloadVideoThread extends Thread {
|
||||
super();
|
||||
this.url = url;
|
||||
this.saveAs = saveAs;
|
||||
this.prettySaveAs = Utils.removeCWD(saveAs.toFile());
|
||||
this.prettySaveAs = Utils.removeCWD(saveAs);
|
||||
this.observer = observer;
|
||||
this.retries = Utils.getConfigInteger("download.retries", 1);
|
||||
}
|
||||
|
@@ -96,7 +96,7 @@ public abstract class VideoRipper extends AbstractRipper {
|
||||
workingDir = new File(path);
|
||||
|
||||
if (!workingDir.exists()) {
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(workingDir));
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(workingDir.toPath()));
|
||||
workingDir.mkdirs();
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public abstract class VideoRipper extends AbstractRipper {
|
||||
}
|
||||
|
||||
try {
|
||||
String path = Utils.removeCWD(saveAs);
|
||||
String path = Utils.removeCWD(saveAs.toPath());
|
||||
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, path);
|
||||
observer.update(this, msg);
|
||||
|
||||
|
@@ -208,7 +208,7 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
|
||||
}
|
||||
LOGGER.debug("Downloading " + url + "'s description to " + saveFileAs);
|
||||
if (!Files.exists(saveFileAs.getParent())) {
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(saveFileAs.getParent().toFile()));
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(saveFileAs.getParent()));
|
||||
try {
|
||||
Files.createDirectory(saveFileAs.getParent());
|
||||
} catch (IOException e) {
|
||||
|
@@ -302,7 +302,7 @@ public class RedditRipper extends AlbumRipper {
|
||||
LOGGER.debug("Downloading " + url + "'s self post to " + saveFileAs);
|
||||
super.retrievingSource(permalink);
|
||||
if (!Files.exists(saveFileAs.getParent())) {
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(saveFileAs.getParent().toFile()));
|
||||
LOGGER.info("[+] Creating directory: " + Utils.removeCWD(saveFileAs.getParent()));
|
||||
try {
|
||||
Files.createDirectory(saveFileAs.getParent());
|
||||
} catch (IOException e) {
|
||||
|
@@ -320,15 +320,8 @@ public class Utils {
|
||||
* @param saveAs The File path
|
||||
* @return saveAs in relation to the CWD
|
||||
*/
|
||||
public static String removeCWD(File saveAs) {
|
||||
String prettySaveAs = saveAs.toString();
|
||||
try {
|
||||
prettySaveAs = saveAs.getCanonicalPath();
|
||||
String cwd = new File(".").getCanonicalPath() + File.separator;
|
||||
prettySaveAs = prettySaveAs.replace(cwd, "." + File.separator);
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Exception: ", e);
|
||||
}
|
||||
public static String removeCWD(Path saveAs) {
|
||||
String prettySaveAs = saveAs.relativize(Paths.get(".").toAbsolutePath()).toString();
|
||||
return prettySaveAs;
|
||||
}
|
||||
|
||||
@@ -371,7 +364,7 @@ public class Utils {
|
||||
* @return 'file' without the leading current working directory
|
||||
*/
|
||||
public static String removeCWD(String file) {
|
||||
return removeCWD(new File(file));
|
||||
return removeCWD(Paths.get(file));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -465,7 +458,7 @@ public class Utils {
|
||||
* @return The simplified path to the file.
|
||||
*/
|
||||
public static String shortenPath(File file) {
|
||||
String path = removeCWD(file);
|
||||
String path = removeCWD(file.toPath());
|
||||
if (path.length() < SHORTENED_PATH_LENGTH * 2) {
|
||||
return path;
|
||||
}
|
||||
|
Reference in New Issue
Block a user