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-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
|
|
|
|
|
|
|
public static final Logger logger = Logger.getLogger(App.class);
|
|
|
|
|
|
|
|
public static void main(String[] args) throws MalformedURLException {
|
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-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) {
|
|
|
|
CommandLine cl = handleArguments(args);
|
2014-02-27 10:28:23 +01:00
|
|
|
|
2014-03-01 11:13:32 +01:00
|
|
|
try {
|
|
|
|
URL url = new URL(cl.getOptionValue('u'));
|
|
|
|
rip(url);
|
|
|
|
} catch (MalformedURLException e) {
|
|
|
|
logger.error("[!] Given URL is not valid. Expected URL format is http://domain.com/...");
|
|
|
|
System.exit(-1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
MainWindow mw = new MainWindow();
|
|
|
|
SwingUtilities.invokeLater(mw);
|
2014-02-27 10:28:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void rip(URL url) {
|
2014-02-27 04:54:44 +01:00
|
|
|
try {
|
2014-02-27 10:28:23 +01:00
|
|
|
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
|
|
|
ripper.rip();
|
2014-02-27 04:54:44 +01:00
|
|
|
} catch (Exception e) {
|
2014-03-02 04:37:09 +01:00
|
|
|
logger.error("[!] Error while ripping: " + e.getMessage(), e);
|
2014-02-27 10:28:23 +01:00
|
|
|
System.exit(-1);
|
2014-02-27 04:54:44 +01:00
|
|
|
}
|
2014-02-26 08:44:22 +01:00
|
|
|
}
|
2014-02-28 04:49:28 +01:00
|
|
|
|
2014-02-27 10:28:23 +01:00
|
|
|
public static CommandLine handleArguments(String[] args) {
|
|
|
|
CommandLine cl = getArgs(args);
|
|
|
|
if (cl.hasOption('h')) {
|
|
|
|
HelpFormatter hf = new HelpFormatter();
|
|
|
|
hf.printHelp("asdf", getOptions());
|
|
|
|
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-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);
|
|
|
|
}
|
|
|
|
return cl;
|
|
|
|
}
|
|
|
|
|
|
|
|
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");
|
|
|
|
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
|
|
|
}
|