Prettier console output

This commit is contained in:
4pr0n 2014-02-27 19:49:28 -08:00
parent ae2a85fa38
commit 569b7fbdc4
6 changed files with 24 additions and 19 deletions

View File

@ -29,7 +29,7 @@ public class App {
URL url = new URL(cl.getOptionValue('u')); URL url = new URL(cl.getOptionValue('u'));
rip(url); rip(url);
} 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);
} }
} }
@ -39,11 +39,11 @@ public class App {
AbstractRipper ripper = AbstractRipper.getRipper(url); AbstractRipper ripper = AbstractRipper.getRipper(url);
ripper.rip(); ripper.rip();
} catch (Exception e) { } catch (Exception e) {
logger.error("Caught exception:", e); logger.error("[!] Caught exception: " + e.getMessage(), e);
System.exit(-1); System.exit(-1);
} }
} }
public static CommandLine handleArguments(String[] args) { public static CommandLine handleArguments(String[] args) {
CommandLine cl = getArgs(args); CommandLine cl = getArgs(args);
if (cl.hasOption('h')) { if (cl.hasOption('h')) {
@ -77,7 +77,7 @@ public class App {
CommandLine cl = parser.parse(getOptions(), args, false); CommandLine cl = parser.parse(getOptions(), args, false);
return cl; return cl;
} catch (ParseException e) { } catch (ParseException e) {
logger.error("Error while parsing command-line arguments: " + args, e); logger.error("[!] Error while parsing command-line arguments: " + args, e);
System.exit(-1); System.exit(-1);
return null; return null;
} }

View File

@ -55,7 +55,7 @@ public abstract class AbstractRipper implements RipperInterface {
try { try {
saveFileAs = new File(workingDir.getCanonicalPath() + File.separator + prefix + saveAs); saveFileAs = new File(workingDir.getCanonicalPath() + File.separator + prefix + saveAs);
} catch (IOException e) { } catch (IOException e) {
logger.error("Error creating save file path for URL '" + url + "':", e); logger.error("[!] Error creating save file path for URL '" + url + "':", e);
return; return;
} }
logger.debug("Downloading " + url + " to " + saveFileAs); logger.debug("Downloading " + url + " to " + saveFileAs);
@ -84,7 +84,7 @@ public abstract class AbstractRipper implements RipperInterface {
path += getHost() + "_" + getGID(this.url) + File.separator; path += getHost() + "_" + getGID(this.url) + File.separator;
this.workingDir = new File(path); this.workingDir = new File(path);
if (!this.workingDir.exists()) { if (!this.workingDir.exists()) {
logger.info("Creating working directory(s): " + this.workingDir); logger.info("[+] Creating working directory: " + this.workingDir);
this.workingDir.mkdirs(); this.workingDir.mkdirs();
} }
logger.debug("Set working directory to: " + this.workingDir); logger.debug("Set working directory to: " + this.workingDir);

View File

@ -28,15 +28,15 @@ public class DownloadFileThread extends Thread {
// Check if file already exists // Check if file already exists
if (saveAs.exists()) { if (saveAs.exists()) {
if (Utils.getConfigBoolean("file.overwrite", false)) { if (Utils.getConfigBoolean("file.overwrite", false)) {
logger.info("File already exists and 'file.overwrite' is true, deleting: " + saveAs); logger.info("[!] File already exists and 'file.overwrite' is true, deleting: " + saveAs);
saveAs.delete(); saveAs.delete();
} else { } else {
logger.info("Not downloading " + url + " because file already exists: " + saveAs); logger.info("[!] Not downloading " + url + " because file already exists: " + saveAs);
return; return;
} }
} }
logger.info("Downloading file from: " + url); logger.info("[ ] Downloading file from: " + url);
try { try {
Response response; Response response;
response = Jsoup.connect(url.toExternalForm()) response = Jsoup.connect(url.toExternalForm())
@ -46,10 +46,10 @@ public class DownloadFileThread extends Thread {
out.write(response.bodyAsBytes()); out.write(response.bodyAsBytes());
out.close(); out.close();
} catch (IOException e) { } catch (IOException e) {
logger.error("Exception while downloading file: " + url, e); logger.error("[!] Exception while downloading file: " + url, e);
return; return;
} }
logger.info("Download completed: " + url); logger.info("[+] Download completed: " + url);
} }
} }

View File

@ -33,7 +33,6 @@ public class ImagefapRipper extends AbstractRipper {
*/ */
public URL sanitizeURL(URL url) throws MalformedURLException { public URL sanitizeURL(URL url) throws MalformedURLException {
String gid = getGID(url); String gid = getGID(url);
logger.debug("GID=" + gid);
URL newURL = new URL("http://www.imagefap.com/gallery.php?gid=" URL newURL = new URL("http://www.imagefap.com/gallery.php?gid="
+ gid + "&view=2"); + gid + "&view=2");
logger.debug("Sanitized URL from " + url + " to " + newURL); logger.debug("Sanitized URL from " + url + " to " + newURL);
@ -60,7 +59,8 @@ public class ImagefapRipper extends AbstractRipper {
@Override @Override
public void rip() throws IOException { public void rip() throws IOException {
logger.debug("Retrieving " + this.url.toExternalForm()); int index = 0;
logger.info("[ ] Retrieving " + this.url.toExternalForm());
Document doc = Jsoup.connect(this.url.toExternalForm()).get(); Document doc = Jsoup.connect(this.url.toExternalForm()).get();
for (Element thumb : doc.select("#gallery img")) { for (Element thumb : doc.select("#gallery img")) {
if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) { if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) {
@ -70,12 +70,16 @@ public class ImagefapRipper extends AbstractRipper {
image = image.replaceAll( image = image.replaceAll(
"http://x.*.fap.to/images/thumb/", "http://x.*.fap.to/images/thumb/",
"http://fap.to/images/full/"); "http://fap.to/images/full/");
processURL(new URL(image)); index += 1;
processURL(new URL(image), String.format("%03d_", index));
} }
logger.info("[ ] Waiting for threads to finish...");
threadPool.waitForThreads();
} }
public void processURL(URL url) { public void processURL(URL url, String prefix) {
logger.info("Found " + url); logger.debug("Found URL: " + url);
addURLToDownload(url, prefix);
} }
public boolean canRip(URL url) { public boolean canRip(URL url) {

View File

@ -75,12 +75,13 @@ public class ImgurRipper extends AbstractRipper {
// TODO Get all albums by user // TODO Get all albums by user
break; break;
} }
logger.info("[ ] Waiting for threads to finish...");
threadPool.waitForThreads(); threadPool.waitForThreads();
} }
private void ripAlbum(URL url) throws IOException { private void ripAlbum(URL url) throws IOException {
int index = 0; int index = 0;
logger.info("Retrieving " + url.toExternalForm()); logger.info("[ ] Retrieving " + url.toExternalForm());
Document doc = Jsoup.connect(url.toExternalForm()).get(); Document doc = Jsoup.connect(url.toExternalForm()).get();
for (Element thumb : doc.select("div.image")) { for (Element thumb : doc.select("div.image")) {
String image; String image;
@ -91,7 +92,7 @@ public class ImgurRipper extends AbstractRipper {
image = "http:" + thumb.select("img").attr("src"); image = "http:" + thumb.select("img").attr("src");
} else { } else {
// Unable to find image in this div // Unable to find image in this div
logger.error("Unable to find image in div: " + thumb.toString()); logger.error("[!] Unable to find image in div: " + thumb.toString());
continue; continue;
} }
index += 1; index += 1;

View File

@ -19,7 +19,7 @@ public class Utils {
try { try {
config = new PropertiesConfiguration(configFile); config = new PropertiesConfiguration(configFile);
} catch (ConfigurationException e) { } catch (ConfigurationException e) {
logger.error("Failed to load properties file from " + configFile, e); logger.error("[!] Failed to load properties file from " + configFile, e);
} }
} }