mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-26 23:34:53 +02:00
Merge pull request #1367 from Isaaku/issues/1195_fix_download.history_in_history.json
Fix history when rip using -u
This commit is contained in:
@@ -9,8 +9,12 @@ import java.io.FileNotFoundException;
|
|||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
|
||||||
@@ -97,6 +101,21 @@ public class App {
|
|||||||
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
||||||
ripper.setup();
|
ripper.setup();
|
||||||
ripper.rip();
|
ripper.rip();
|
||||||
|
|
||||||
|
String u = ripper.getURL().toExternalForm();
|
||||||
|
Date date = new Date();
|
||||||
|
if (HISTORY.containsURL(u)) {
|
||||||
|
HistoryEntry entry = HISTORY.getEntryByURL(u);
|
||||||
|
entry.modifiedDate = date;
|
||||||
|
} else {
|
||||||
|
HistoryEntry entry = new HistoryEntry();
|
||||||
|
entry.url = u;
|
||||||
|
entry.dir = ripper.getWorkingDir().getAbsolutePath();
|
||||||
|
try {
|
||||||
|
entry.title = ripper.getAlbumTitle(ripper.getURL());
|
||||||
|
} catch (MalformedURLException e) { }
|
||||||
|
HISTORY.add(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -146,13 +165,17 @@ public class App {
|
|||||||
//Re-rip <i>all</i> previous albums
|
//Re-rip <i>all</i> previous albums
|
||||||
if (cl.hasOption('r')) {
|
if (cl.hasOption('r')) {
|
||||||
// Re-rip all via command-line
|
// Re-rip all via command-line
|
||||||
List<String> history = Utils.getConfigList("download.history");
|
loadHistory();
|
||||||
for (String urlString : history) {
|
if (HISTORY.toList().isEmpty()) {
|
||||||
|
logger.error("There are no history entries to re-rip. Rip some albums first");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
for (HistoryEntry entry : HISTORY.toList()) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(urlString.trim());
|
URL url = new URL(entry.url);
|
||||||
rip(url);
|
rip(url);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.error("[!] Failed to rip URL " + urlString, e);
|
logger.error("[!] Failed to rip URL " + entry.url, e);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@@ -244,6 +267,7 @@ public class App {
|
|||||||
|
|
||||||
//The URL to rip.
|
//The URL to rip.
|
||||||
if (cl.hasOption('u')) {
|
if (cl.hasOption('u')) {
|
||||||
|
loadHistory();
|
||||||
String url = cl.getOptionValue('u').trim();
|
String url = cl.getOptionValue('u').trim();
|
||||||
ripURL(url, !cl.hasOption("n"));
|
ripURL(url, !cl.hasOption("n"));
|
||||||
}
|
}
|
||||||
@@ -263,14 +287,7 @@ public class App {
|
|||||||
try {
|
try {
|
||||||
URL url = new URL(targetURL);
|
URL url = new URL(targetURL);
|
||||||
rip(url);
|
rip(url);
|
||||||
List<String> history = Utils.getConfigList("download.history");
|
saveHistory();
|
||||||
if (!history.contains(url.toExternalForm())) {//if you haven't already downloaded the file before
|
|
||||||
history.add(url.toExternalForm());//add it to history so you won't have to redownload
|
|
||||||
Utils.setConfigList("download.history", Arrays.asList(history.toArray()));
|
|
||||||
if (saveConfig) {
|
|
||||||
Utils.saveConfig();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (MalformedURLException e) {
|
} catch (MalformedURLException e) {
|
||||||
logger.error("[!] Given URL is not valid. Expected URL format is http://domain.com/...");
|
logger.error("[!] Given URL is not valid. Expected URL format is http://domain.com/...");
|
||||||
// System.exit(-1);
|
// System.exit(-1);
|
||||||
@@ -324,6 +341,7 @@ public class App {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads history from history file into memory.
|
* Loads history from history file into memory.
|
||||||
|
* @see MainWindow.loadHistory
|
||||||
*/
|
*/
|
||||||
private static void loadHistory() {
|
private static void loadHistory() {
|
||||||
File historyFile = new File(Utils.getConfigDir() + File.separator + "history.json");
|
File historyFile = new File(Utils.getConfigDir() + File.separator + "history.json");
|
||||||
@@ -359,4 +377,22 @@ public class App {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see MainWindow.saveHistory
|
||||||
|
*/
|
||||||
|
private static void saveHistory() {
|
||||||
|
Path historyFile = Paths.get(Utils.getConfigDir() + File.separator + "history.json");
|
||||||
|
try {
|
||||||
|
if (!Files.exists(historyFile)) {
|
||||||
|
Files.createDirectories(historyFile.getParent());
|
||||||
|
Files.createFile(historyFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
HISTORY.toFile(historyFile.toString());
|
||||||
|
Utils.setConfigList("download.history", Collections.emptyList());
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Failed to save history to file " + historyFile, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user