Merge pull request #259 from ProperGeezer/master
Add Command Arg -R to re-rip only selected history items
This commit is contained in:
commit
c8fdd9d0aa
@ -1,11 +1,15 @@
|
|||||||
package com.rarchives.ripme;
|
package com.rarchives.ripme;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.DefaultListModel;
|
||||||
|
|
||||||
import org.apache.commons.cli.BasicParser;
|
import org.apache.commons.cli.BasicParser;
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
@ -16,8 +20,11 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
import com.rarchives.ripme.ripper.AbstractRipper;
|
import com.rarchives.ripme.ripper.AbstractRipper;
|
||||||
import com.rarchives.ripme.ui.MainWindow;
|
import com.rarchives.ripme.ui.MainWindow;
|
||||||
|
import com.rarchives.ripme.ui.History;
|
||||||
|
import com.rarchives.ripme.ui.HistoryEntry;
|
||||||
import com.rarchives.ripme.ui.UpdateUtils;
|
import com.rarchives.ripme.ui.UpdateUtils;
|
||||||
import com.rarchives.ripme.utils.Utils;
|
import com.rarchives.ripme.utils.Utils;
|
||||||
|
import com.rarchives.ripme.utils.RipUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@ -25,6 +32,8 @@ import com.rarchives.ripme.utils.Utils;
|
|||||||
public class App {
|
public class App {
|
||||||
|
|
||||||
public static Logger logger;
|
public static Logger logger;
|
||||||
|
private static final History HISTORY = new History();
|
||||||
|
private static DefaultListModel queueListModel;
|
||||||
|
|
||||||
public static void main(String[] args) throws MalformedURLException {
|
public static void main(String[] args) throws MalformedURLException {
|
||||||
Utils.configureLogger();
|
Utils.configureLogger();
|
||||||
@ -84,6 +93,38 @@ public class App {
|
|||||||
// Exit
|
// Exit
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
if (cl.hasOption('R')) {
|
||||||
|
loadHistory();
|
||||||
|
|
||||||
|
if (HISTORY.toList().size() == 0) {
|
||||||
|
System.err.println("There are no history entries to re-rip. Rip some albums first");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
int added = 0;
|
||||||
|
for (HistoryEntry entry : HISTORY.toList()) {
|
||||||
|
if (entry.selected) {
|
||||||
|
added++;
|
||||||
|
try {
|
||||||
|
URL url = new URL(entry.url);
|
||||||
|
rip(url);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("[!] Failed to rip URL " + entry.url, e);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Thread.sleep(500);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.warn("[!] Interrupted while re-ripping history");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (added == 0) {
|
||||||
|
System.err.println("No history entries have been 'Checked'\n" +
|
||||||
|
"Check an entry by clicking the checkbox to the right of the URL or Right-click a URL to check/uncheck all items");
|
||||||
|
System.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (cl.hasOption('d')) {
|
if (cl.hasOption('d')) {
|
||||||
Utils.setConfigBoolean("download.save_order", true);
|
Utils.setConfigBoolean("download.save_order", true);
|
||||||
}
|
}
|
||||||
@ -117,11 +158,6 @@ public class App {
|
|||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!cl.hasOption('u')) {
|
|
||||||
System.err.println("\nRequired URL ('-u' or '--url') not provided");
|
|
||||||
System.err.println("\n\tExample: java -jar ripme.jar -u http://imgur.com/a/abcde");
|
|
||||||
System.exit(-1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Options getOptions() {
|
public static Options getOptions() {
|
||||||
@ -131,6 +167,7 @@ public class App {
|
|||||||
opts.addOption("t", "threads", true, "Number of download threads per rip");
|
opts.addOption("t", "threads", true, "Number of download threads per rip");
|
||||||
opts.addOption("w", "overwrite", false, "Overwrite existing files");
|
opts.addOption("w", "overwrite", false, "Overwrite existing files");
|
||||||
opts.addOption("r", "rerip", false, "Re-rip all ripped albums");
|
opts.addOption("r", "rerip", false, "Re-rip all ripped albums");
|
||||||
|
opts.addOption("R", "rerip-selected", false, "Re-rip all selected albums");
|
||||||
opts.addOption("d", "saveorder", false, "Save the order of images in album");
|
opts.addOption("d", "saveorder", false, "Save the order of images in album");
|
||||||
opts.addOption("D", "nosaveorder", false, "Don't save order of images");
|
opts.addOption("D", "nosaveorder", false, "Don't save order of images");
|
||||||
opts.addOption("4", "skip404", false, "Don't retry after a 404 (not found) error");
|
opts.addOption("4", "skip404", false, "Don't retry after a 404 (not found) error");
|
||||||
@ -149,4 +186,44 @@ public class App {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void loadHistory() {
|
||||||
|
File historyFile = new File("history.json");
|
||||||
|
HISTORY.clear();
|
||||||
|
if (historyFile.exists()) {
|
||||||
|
try {
|
||||||
|
logger.info("Loading history from history.json");
|
||||||
|
HISTORY.fromFile("history.json");
|
||||||
|
} catch (IOException e) {
|
||||||
|
logger.error("Failed to load history from file " + historyFile, e);
|
||||||
|
System.out.println(
|
||||||
|
"RipMe failed to load the history file at " + historyFile.getAbsolutePath() + "\n\n" +
|
||||||
|
"Error: " + e.getMessage() + "\n\n" +
|
||||||
|
"Closing RipMe will automatically overwrite the contents of this file,\n" +
|
||||||
|
"so you may want to back the file up before closing RipMe!");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
logger.info("Loading history from configuration");
|
||||||
|
HISTORY.fromList(Utils.getConfigList("download.history"));
|
||||||
|
if (HISTORY.toList().size() == 0) {
|
||||||
|
// Loaded from config, still no entries.
|
||||||
|
// Guess rip history based on rip folder
|
||||||
|
String[] dirs = Utils.getWorkingDirectory().list(new FilenameFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String file) {
|
||||||
|
return new File(dir.getAbsolutePath() + File.separator + file).isDirectory();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
for (String dir : dirs) {
|
||||||
|
String url = RipUtils.urlFromDirectoryName(dir);
|
||||||
|
if (url != null) {
|
||||||
|
// We found one, add it to history
|
||||||
|
HistoryEntry entry = new HistoryEntry();
|
||||||
|
entry.url = url;
|
||||||
|
HISTORY.add(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ public class HistoryEntry {
|
|||||||
public int count = 0;
|
public int count = 0;
|
||||||
public Date startDate = new Date(),
|
public Date startDate = new Date(),
|
||||||
modifiedDate = new Date();
|
modifiedDate = new Date();
|
||||||
boolean selected = false;
|
public boolean selected = false;
|
||||||
|
|
||||||
public HistoryEntry() {
|
public HistoryEntry() {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user