Beispiel #1
0
 public static void handleArguments(String[] args) {
   CommandLine cl = getArgs(args);
   if (cl.hasOption('h')) {
     HelpFormatter hf = new HelpFormatter();
     hf.printHelp("java -jar ripme.jar [OPTIONS]", getOptions());
     System.exit(0);
   }
   if (cl.hasOption('w')) {
     Utils.setConfigBoolean("file.overwrite", true);
   }
   if (cl.hasOption('t')) {
     Utils.setConfigInteger("threads.size", Integer.parseInt(cl.getOptionValue('t')));
   }
   if (cl.hasOption('4')) {
     Utils.setConfigBoolean("errors.skip404", true);
   }
   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);
   }
   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);
     }
   }
   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);
   }
 }