mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-01-17 20:58:31 +01:00
downloadCompleted java.nio
This commit is contained in:
parent
65eed02bf2
commit
5d5ce9d0dd
@ -6,7 +6,11 @@ import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
@ -26,7 +30,7 @@ import com.rarchives.ripme.ui.RipStatusMessage;
|
||||
public abstract class AbstractHTMLRipper extends AbstractRipper {
|
||||
|
||||
private final Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<>());
|
||||
private final Map<URL, File> itemsCompleted = Collections.synchronizedMap(new HashMap<>());
|
||||
private final Map<URL, Path> itemsCompleted = Collections.synchronizedMap(new HashMap<>());
|
||||
private final Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<>());
|
||||
|
||||
protected AbstractHTMLRipper(URL url) throws IOException {
|
||||
@ -320,11 +324,11 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
||||
}
|
||||
if (Utils.getConfigBoolean("urls_only.save", false)) {
|
||||
// Output URL to file
|
||||
String urlFile = this.workingDir + File.separator + "urls.txt";
|
||||
try (FileWriter fw = new FileWriter(urlFile, true)) {
|
||||
fw.write(url.toExternalForm());
|
||||
fw.write(System.lineSeparator());
|
||||
itemsCompleted.put(url, new File(urlFile));
|
||||
Path urlFile = Paths.get(this.workingDir + "/urls.txt");
|
||||
String text = url.toExternalForm() + System.lineSeparator();
|
||||
try {
|
||||
Files.write(urlFile, text.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
|
||||
itemsCompleted.put(url, urlFile);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error while writing to " + urlFile, e);
|
||||
}
|
||||
@ -366,12 +370,12 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
||||
/*
|
||||
Cleans up & tells user about successful download
|
||||
*/
|
||||
public void downloadCompleted(URL url, File saveAs) {
|
||||
public void downloadCompleted(URL url, Path saveAs) {
|
||||
if (observer == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String path = Utils.removeCWD(saveAs.toPath());
|
||||
String path = Utils.removeCWD(saveAs);
|
||||
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, path);
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, saveAs);
|
||||
@ -409,7 +413,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
|
||||
}
|
||||
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, file.toFile());
|
||||
itemsCompleted.put(url, file);
|
||||
observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " already saved as " + file));
|
||||
|
||||
checkIfComplete();
|
||||
|
@ -6,13 +6,14 @@ import com.rarchives.ripme.utils.Utils;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -24,7 +25,7 @@ import java.util.Map;
|
||||
public abstract class AbstractJSONRipper extends AbstractRipper {
|
||||
|
||||
private Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<URL, File>());
|
||||
private Map<URL, File> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, File>());
|
||||
private Map<URL, Path> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, Path>());
|
||||
private Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<URL, String>());
|
||||
|
||||
protected AbstractJSONRipper(URL url) throws IOException {
|
||||
@ -161,11 +162,11 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
|
||||
}
|
||||
if (Utils.getConfigBoolean("urls_only.save", false)) {
|
||||
// Output URL to file
|
||||
String urlFile = this.workingDir + File.separator + "urls.txt";
|
||||
try (FileWriter fw = new FileWriter(urlFile, true)) {
|
||||
fw.write(url.toExternalForm());
|
||||
fw.write(System.lineSeparator());
|
||||
itemsCompleted.put(url, new File(urlFile));
|
||||
Path urlFile = Paths.get(this.workingDir + "/urls.txt");
|
||||
String text = url.toExternalForm() + System.lineSeparator();
|
||||
try {
|
||||
Files.write(urlFile, text.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
|
||||
itemsCompleted.put(url, urlFile);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error while writing to " + urlFile, e);
|
||||
}
|
||||
@ -207,12 +208,12 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
|
||||
/**
|
||||
* Cleans up & tells user about successful download
|
||||
*/
|
||||
public void downloadCompleted(URL url, File saveAs) {
|
||||
public void downloadCompleted(URL url, Path saveAs) {
|
||||
if (observer == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String path = Utils.removeCWD(saveAs.toPath());
|
||||
String path = Utils.removeCWD(saveAs);
|
||||
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, path);
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, saveAs);
|
||||
@ -250,7 +251,7 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
|
||||
}
|
||||
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, file.toFile());
|
||||
itemsCompleted.put(url, file);
|
||||
observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " already saved as " + file));
|
||||
|
||||
checkIfComplete();
|
||||
|
@ -452,7 +452,7 @@ public abstract class AbstractRipper
|
||||
* @param saveAs
|
||||
* Where the downloaded file is stored.
|
||||
*/
|
||||
public abstract void downloadCompleted(URL url, File saveAs);
|
||||
public abstract void downloadCompleted(URL url, Path saveAs);
|
||||
/**
|
||||
* Notifies observers that a file could not be downloaded (includes a reason).
|
||||
* @param url
|
||||
|
@ -1,19 +1,22 @@
|
||||
package com.rarchives.ripme.ripper;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Path;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import com.rarchives.ripme.ui.RipStatusMessage;
|
||||
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
||||
import com.rarchives.ripme.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
// Should this file even exist? It does the same thing as abstractHTML ripper
|
||||
|
||||
/**'
|
||||
@ -22,7 +25,7 @@ import com.rarchives.ripme.utils.Utils;
|
||||
public abstract class AlbumRipper extends AbstractRipper {
|
||||
|
||||
private Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<URL, File>());
|
||||
private Map<URL, File> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, File>());
|
||||
private Map<URL, Path> itemsCompleted = Collections.synchronizedMap(new HashMap<URL, Path>());
|
||||
private Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<URL, String>());
|
||||
|
||||
protected AlbumRipper(URL url) throws IOException {
|
||||
@ -68,11 +71,11 @@ public abstract class AlbumRipper extends AbstractRipper {
|
||||
}
|
||||
if (Utils.getConfigBoolean("urls_only.save", false)) {
|
||||
// Output URL to file
|
||||
String urlFile = this.workingDir + File.separator + "urls.txt";
|
||||
try (FileWriter fw = new FileWriter(urlFile, true)) {
|
||||
fw.write(url.toExternalForm());
|
||||
fw.write(System.lineSeparator());
|
||||
itemsCompleted.put(url, new File(urlFile));
|
||||
Path urlFile = Paths.get(this.workingDir + "/urls.txt");
|
||||
String text = url.toExternalForm() + System.lineSeparator();
|
||||
try {
|
||||
Files.write(urlFile, text.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
|
||||
itemsCompleted.put(url, urlFile);
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error while writing to " + urlFile, e);
|
||||
}
|
||||
@ -114,12 +117,12 @@ public abstract class AlbumRipper extends AbstractRipper {
|
||||
/**
|
||||
* Cleans up & tells user about successful download
|
||||
*/
|
||||
public void downloadCompleted(URL url, File saveAs) {
|
||||
public void downloadCompleted(URL url, Path saveAs) {
|
||||
if (observer == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
String path = Utils.removeCWD(saveAs.toPath());
|
||||
String path = Utils.removeCWD(saveAs);
|
||||
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, path);
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, saveAs);
|
||||
@ -157,7 +160,7 @@ public abstract class AlbumRipper extends AbstractRipper {
|
||||
}
|
||||
|
||||
itemsPending.remove(url);
|
||||
itemsCompleted.put(url, file.toFile());
|
||||
itemsCompleted.put(url, file);
|
||||
observer.update(this, new RipStatusMessage(STATUS.DOWNLOAD_WARN, url + " already saved as " + file));
|
||||
|
||||
checkIfComplete();
|
||||
|
@ -315,7 +315,7 @@ class DownloadFileThread extends Thread {
|
||||
return;
|
||||
}
|
||||
} while (true);
|
||||
observer.downloadCompleted(url, saveAs);
|
||||
observer.downloadCompleted(url, saveAs.toPath());
|
||||
logger.info("[+] Saved " + url + " as " + this.prettySaveAs);
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ class DownloadVideoThread extends Thread {
|
||||
return;
|
||||
}
|
||||
} while (true);
|
||||
observer.downloadCompleted(url, saveAs.toFile());
|
||||
observer.downloadCompleted(url, saveAs);
|
||||
logger.info("[+] Saved " + url + " as " + this.prettySaveAs);
|
||||
}
|
||||
|
||||
|
@ -118,13 +118,13 @@ public abstract class VideoRipper extends AbstractRipper {
|
||||
* @param saveAs Path to file, including filename.
|
||||
*/
|
||||
@Override
|
||||
public void downloadCompleted(URL url, File saveAs) {
|
||||
public void downloadCompleted(URL url, Path saveAs) {
|
||||
if (observer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
String path = Utils.removeCWD(saveAs.toPath());
|
||||
String path = Utils.removeCWD(saveAs);
|
||||
RipStatusMessage msg = new RipStatusMessage(STATUS.DOWNLOAD_COMPLETE, path);
|
||||
observer.update(this, msg);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user