Merge pull request #344 from JoshKastang/issue-343

NEW: Ability to load a list of URLs via commanline (-f flag)
This commit is contained in:
metaprime 2016-12-19 00:51:53 -08:00 committed by GitHub
commit 942f1645a9

View File

@ -3,6 +3,10 @@ package com.rarchives.ripme;
import java.io.File; import java.io.File;
import java.io.FilenameFilter; import java.io.FilenameFilter;
import java.io.IOException; import java.io.IOException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileNotFoundException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
@ -138,26 +142,54 @@ public class App {
// change the default rips directory // change the default rips directory
Utils.setConfigString("rips.directory", cl.getOptionValue('l')); Utils.setConfigString("rips.directory", cl.getOptionValue('l'));
} }
if (cl.hasOption('u')) {
// User provided URL, rip it. if (cl.hasOption('f')) {
String filename = cl.getOptionValue('f');
try { try {
URL url = new URL(cl.getOptionValue('u').trim());
String url;
BufferedReader br = new BufferedReader(new FileReader(filename));
while((url = br.readLine()) != null) {
// loop through each url in the file and proces each url individually.
ripURL(url.trim(), cl.hasOption("n"));
}
} catch (FileNotFoundException fne) {
logger.error("[!] File containing list of URLs not found. Cannot continue.");
} catch (IOException ioe) {
logger.error("[!] Failed reading file containing list of URLs. Cannot continue.");
}
}
if (cl.hasOption('u')) {
String url = cl.getOptionValue('u').trim();
ripURL(url, cl.hasOption("n"));
}
}
// this function will attempt to rip the provided url
public static void ripURL(String targetURL, boolean saveConfig) {
try {
URL url = new URL(targetURL);
rip(url); rip(url);
List<String> history = Utils.getConfigList("download.history"); List<String> history = Utils.getConfigList("download.history");
if (!history.contains(url.toExternalForm())) { if (!history.contains(url.toExternalForm())) {
history.add(url.toExternalForm()); history.add(url.toExternalForm());
Utils.setConfigList("download.history", Arrays.asList(history.toArray())); Utils.setConfigList("download.history", Arrays.asList(history.toArray()));
if(!cl.hasOption("n")) { if(saveConfig) {
Utils.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);
} catch (Exception e) { } catch (Exception e) {
logger.error("[!] Error while ripping URL " + cl.getOptionValue('u'), e); logger.error("[!] Error while ripping URL " + targetURL, e);
System.exit(-1); // System.exit(-1);
}
} }
} }
@ -174,6 +206,7 @@ public class App {
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");
opts.addOption("l", "ripsdirectory", true, "Rips Directory (Default: ./rips)"); opts.addOption("l", "ripsdirectory", true, "Rips Directory (Default: ./rips)");
opts.addOption("n", "no-prop-file", false, "Do not create properties file."); opts.addOption("n", "no-prop-file", false, "Do not create properties file.");
opts.addOption("f", "urls-file", true, "Rip URLs from a file.");
return opts; return opts;
} }