2014-02-25 10:28:22 +01:00
|
|
|
package com.rarchives.ripme;
|
|
|
|
|
2014-02-27 10:28:23 +01:00
|
|
|
import java.net.MalformedURLException;
|
2014-02-25 10:28:22 +01:00
|
|
|
import java.net.URL;
|
2014-04-23 06:16:23 +02:00
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
2014-02-25 10:28:22 +01:00
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
import javax.swing.SwingUtilities;
|
|
|
|
|
2014-02-27 10:28:23 +01:00
|
|
|
import org.apache.commons.cli.BasicParser;
|
|
|
|
import org.apache.commons.cli.CommandLine;
|
|
|
|
import org.apache.commons.cli.HelpFormatter;
|
|
|
|
import org.apache.commons.cli.Options;
|
|
|
|
import org.apache.commons.cli.ParseException;
|
2014-02-26 08:44:22 +01:00
|
|
|
import org.apache.log4j.Logger;
|
|
|
|
|
2014-02-27 10:28:23 +01:00
|
|
|
import com.rarchives.ripme.ripper.AbstractRipper;
|
2014-03-01 11:13:32 +01:00
|
|
|
import com.rarchives.ripme.ui.MainWindow;
|
2014-04-05 11:11:04 +02:00
|
|
|
import com.rarchives.ripme.ui.UpdateUtils;
|
2014-02-27 10:28:23 +01:00
|
|
|
import com.rarchives.ripme.utils.Utils;
|
2014-02-25 10:28:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
public class App {
|
2014-02-27 10:28:23 +01:00
|
|
|
|
2014-06-12 07:21:09 +02:00
|
|
|
public static Logger logger;
|
2014-02-27 10:28:23 +01:00
|
|
|
|
|
|
|
public static void main(String[] args) throws MalformedURLException {
|
2014-06-12 07:21:09 +02:00
|
|
|
Utils.configureLogger();
|
2014-04-08 06:57:18 +02:00
|
|
|
System.setProperty("apple.laf.useScreenMenuBar", "true");
|
|
|
|
System.setProperty("com.apple.mrj.application.apple.menu.about.name", "RipMe");
|
2014-06-12 07:21:09 +02:00
|
|
|
logger = Logger.getLogger(App.class);
|
2014-04-05 11:11:04 +02:00
|
|
|
logger.info("Initialized ripme v" + UpdateUtils.getThisJarVersion());
|
2014-04-11 08:00:11 +02:00
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
if (args.length > 0) {
|
2014-04-23 06:16:23 +02:00
|
|
|
handleArguments(args);
|
2014-03-01 11:13:32 +01:00
|
|
|
} else {
|
|
|
|
MainWindow mw = new MainWindow();
|
|
|
|
SwingUtilities.invokeLater(mw);
|
2014-02-27 10:28:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-23 06:16:23 +02:00
|
|
|
public static void rip(URL url) throws Exception {
|
|
|
|
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
2014-06-11 05:22:28 +02:00
|
|
|
ripper.setup();
|
2014-04-23 06:16:23 +02:00
|
|
|
ripper.rip();
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
2014-02-28 04:49:28 +01:00
|
|
|
|
2014-04-23 06:16:23 +02:00
|
|
|
public static void handleArguments(String[] args) {
|
2014-02-27 10:28:23 +01:00
|
|
|
CommandLine cl = getArgs(args);
|
|
|
|
if (cl.hasOption('h')) {
|
|
|
|
HelpFormatter hf = new HelpFormatter();
|
2014-04-23 06:16:23 +02:00
|
|
|
hf.printHelp("java -jar ripme.jar [OPTIONS]", getOptions());
|
2014-02-27 10:28:23 +01:00
|
|
|
System.exit(0);
|
|
|
|
}
|
|
|
|
if (cl.hasOption('w')) {
|
|
|
|
Utils.setConfigBoolean("file.overwrite", true);
|
|
|
|
}
|
2014-04-06 11:41:04 +02:00
|
|
|
if (cl.hasOption('t')) {
|
|
|
|
Utils.setConfigInteger("threads.size", Integer.parseInt(cl.getOptionValue('t')));
|
|
|
|
}
|
2014-12-24 05:19:52 +01:00
|
|
|
if (cl.hasOption('4')) {
|
|
|
|
Utils.setConfigBoolean("errors.skip404", true);
|
|
|
|
}
|
2014-04-23 06:16:23 +02:00
|
|
|
if (cl.hasOption('r')) {
|
|
|
|
// Re-rip all via command-line
|
|
|
|
List<String> history = Utils.getConfigList("download.history");
|
|
|
|
for (String urlString : history) {
|
|
|
|
try {
|
|
|
|
URL url = new URL(urlString.trim());
|
|
|
|
rip(url);
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("[!] Failed to rip URL " + urlString, e);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
Thread.sleep(500);
|
|
|
|
} catch (InterruptedException e) {
|
|
|
|
logger.warn("[!] Interrupted while re-ripping history");
|
|
|
|
System.exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Exit
|
|
|
|
System.exit(0);
|
|
|
|
}
|
2014-12-24 05:19:52 +01:00
|
|
|
if (cl.hasOption('d')) {
|
|
|
|
Utils.setConfigBoolean("download.save_order", true);
|
|
|
|
}
|
|
|
|
if (cl.hasOption('D')) {
|
|
|
|
Utils.setConfigBoolean("download.save_order", false);
|
|
|
|
}
|
|
|
|
if ((cl.hasOption('d'))&&(cl.hasOption('D'))) {
|
|
|
|
System.err.println("\nCannot specify '-d' and '-D' simultaneously");
|
|
|
|
System.exit(-1);
|
|
|
|
}
|
2014-04-23 06:16:23 +02:00
|
|
|
if (cl.hasOption('u')) {
|
|
|
|
// User provided URL, rip it.
|
|
|
|
try {
|
|
|
|
URL url = new URL(cl.getOptionValue('u').trim());
|
|
|
|
rip(url);
|
|
|
|
List<String> history = Utils.getConfigList("download.history");
|
|
|
|
if (!history.contains(url.toExternalForm())) {
|
|
|
|
history.add(url.toExternalForm());
|
|
|
|
Utils.setConfigList("download.history", Arrays.asList(history.toArray()));
|
|
|
|
Utils.saveConfig();
|
|
|
|
}
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
logger.error("[!] Given URL is not valid. Expected URL format is http://domain.com/...");
|
|
|
|
System.exit(-1);
|
|
|
|
} catch (Exception e) {
|
|
|
|
logger.error("[!] Error while ripping URL " + cl.getOptionValue('u'), e);
|
|
|
|
System.exit(-1);
|
|
|
|
}
|
|
|
|
}
|
2014-02-27 10:28:23 +01:00
|
|
|
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() {
|
|
|
|
Options opts = new Options();
|
|
|
|
opts.addOption("h", "help", false, "Print the help");
|
|
|
|
opts.addOption("u", "url", true, "URL of album to rip");
|
|
|
|
opts.addOption("t", "threads", true, "Number of download threads per rip");
|
|
|
|
opts.addOption("w", "overwrite", false, "Overwrite existing files");
|
2014-04-23 06:16:23 +02:00
|
|
|
opts.addOption("r", "rerip", false, "Re-rip all ripped albums");
|
2014-12-24 05:19:52 +01:00
|
|
|
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("4", "skip404", false, "Don't retry after a 404 (not found) error");
|
2014-02-27 10:28:23 +01:00
|
|
|
return opts;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static CommandLine getArgs(String[] args) {
|
|
|
|
BasicParser parser = new BasicParser();
|
|
|
|
try {
|
|
|
|
CommandLine cl = parser.parse(getOptions(), args, false);
|
|
|
|
return cl;
|
|
|
|
} catch (ParseException e) {
|
2014-02-28 04:49:28 +01:00
|
|
|
logger.error("[!] Error while parsing command-line arguments: " + args, e);
|
2014-02-27 10:28:23 +01:00
|
|
|
System.exit(-1);
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 10:28:22 +01:00
|
|
|
}
|