diff --git a/.classpath b/.classpath
index 0a1daddd..eed68dfa 100644
--- a/.classpath
+++ b/.classpath
@@ -12,12 +12,13 @@
-
+
+
-
+
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 00000000..abec6ca3
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,5 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.5
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 00000000..f897a7f1
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/pom.xml b/pom.xml
index 29728d21..cb1935b5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,6 +25,16 @@
json
20140107
+
+ commons-configuration
+ commons-configuration
+ 1.7
+
+
+ log4j
+ log4j
+ 1.2.17
+
diff --git a/src/main/java/com/rarchives/ripme/App.java b/src/main/java/com/rarchives/ripme/App.java
index acc8e396..b3db5720 100644
--- a/src/main/java/com/rarchives/ripme/App.java
+++ b/src/main/java/com/rarchives/ripme/App.java
@@ -3,6 +3,9 @@ package com.rarchives.ripme;
import java.io.IOException;
import java.net.URL;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
import com.rarchives.ripme.ripper.rippers.ImagefapRipper;
/**
@@ -10,10 +13,17 @@ import com.rarchives.ripme.ripper.rippers.ImagefapRipper;
*/
public class App {
public static void main( String[] args ) throws IOException {
+ Logger logger = Logger.getLogger(App.class);
+ PropertyConfigurator.configure("config/log4j.properties");
+ logger.debug("Testing");
URL url = new URL("http://www.imagefap.com/pictures/4117023/Mirror-flat-stomach-small-firm-tits");
System.out.println("URL: " + url.toExternalForm());
ImagefapRipper ir = new ImagefapRipper(url);
System.out.println("Ripping");
ir.rip();
}
+
+ public static void initialize() {
+
+ }
}
diff --git a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java
index 59848d9a..f45e93ce 100644
--- a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java
+++ b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java
@@ -1,24 +1,38 @@
package com.rarchives.ripme.ripper;
+import java.io.File;
+import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
+import com.rarchives.ripme.utils.Utils;
+
public abstract class AbstractRipper implements RipperInterface {
protected URL url;
+ protected File workingDir = null;
- public AbstractRipper(URL url) throws MalformedURLException {
- // Ensure that the inheriting class can rip this URL.
+ public abstract void rip() throws IOException;
+ public abstract void setWorkingDir() throws IOException;
+
+ /**
+ * Ensures inheriting ripper can rip this URL.
+ * @param url
+ * URL to rip.
+ * @throws IOException
+ * If anything goes wrong.
+ */
+ public AbstractRipper(URL url) throws IOException {
if (!canRip(url)) {
throw new MalformedURLException("Unable to rip url: " + url);
}
this.url = url;
- sanitizeURL();
+ setWorkingDir();
+ workingDir = Utils.getWorkingDirectory();
}
public URL getURL() {
return url;
}
-}
-
+}
\ No newline at end of file
diff --git a/src/main/java/com/rarchives/ripme/ripper/RipperInterface.java b/src/main/java/com/rarchives/ripme/ripper/RipperInterface.java
index 3f8f3318..9c0a7e76 100644
--- a/src/main/java/com/rarchives/ripme/ripper/RipperInterface.java
+++ b/src/main/java/com/rarchives/ripme/ripper/RipperInterface.java
@@ -1,11 +1,11 @@
package com.rarchives.ripme.ripper;
import java.io.IOException;
-import java.net.MalformedURLException;
import java.net.URL;
public interface RipperInterface {
public void rip() throws IOException;
+ public void processURL(String url);
public boolean canRip(URL url);
- public void sanitizeURL() throws MalformedURLException;
+ public void setWorkingDir() throws IOException;
}
diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/ImagefapRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/ImagefapRipper.java
index 4d205870..051e0bfe 100644
--- a/src/main/java/com/rarchives/ripme/ripper/rippers/ImagefapRipper.java
+++ b/src/main/java/com/rarchives/ripme/ripper/rippers/ImagefapRipper.java
@@ -1,5 +1,6 @@
package com.rarchives.ripme.ripper.rippers;
+import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
@@ -11,40 +12,58 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AbstractRipper;
+import com.rarchives.ripme.utils.Utils;
public class ImagefapRipper extends AbstractRipper {
- private static final String HOST = "imagefap.com";
+ private static final String HOST = "imagefap.com";
- public ImagefapRipper(URL url) throws MalformedURLException {
- super(url);
- }
-
- /**
- * Reformat given URL into the desired format (all images on single page)
- */
- public void sanitizeURL() throws MalformedURLException {
- String gid = null;
- Pattern p = Pattern.compile("^.*imagefap.com/gallery.php?gid=([0-9]{1,}).*$");
- Matcher m = p.matcher(this.url.toExternalForm());
- if (m.matches()) {
- gid = m.group(1);
- } else {
- p = Pattern.compile("^.*imagefap.com/pictures/([0-9]{1,}).*$");
- m = p.matcher(this.url.toExternalForm());
+ private String gid;
+
+ public ImagefapRipper(URL url) throws IOException {
+ super(url);
+ this.gid = getGID(url);
+ }
+
+ /**
+ * Reformat given URL into the desired format (all images on single page)
+ */
+ public void sanitizeURL() throws MalformedURLException {
+ this.url = new URL("http://www.imagefap.com/gallery.php?gid="
+ + this.gid + "&view=2");
+ }
+
+ private static String getGID(URL url) throws MalformedURLException {
+ String gid = null;
+ Pattern p = Pattern.compile("^.*imagefap.com/gallery.php?gid=([0-9]{1,}).*$");
+ Matcher m = p.matcher(url.toExternalForm());
+ if (m.matches()) {
+ gid = m.group(1);
+ } else {
+ p = Pattern.compile("^.*imagefap.com/pictures/([0-9]{1,}).*$");
+ m = p.matcher(url.toExternalForm());
if (m.matches()) {
gid = m.group(1);
}
- }
- if (gid == null) {
- throw new MalformedURLException("Expected imagefap.com gallery formats:"
- + "imagefap.com/gallery.php?gid=####... or"
- + "imagefap.com/pictures/####...");
- }
- this.url = new URL("http://www.imagefap.com/gallery.php?gid=" + gid + "&view=2");
- }
+ }
+ if (gid == null) {
+ throw new MalformedURLException(
+ "Expected imagefap.com gallery formats:"
+ + "imagefap.com/gallery.php?gid=####... or"
+ + "imagefap.com/pictures/####...");
+ }
+ return gid;
+ }
- public void rip() throws IOException {
+ @Override
+ public void setWorkingDir() throws IOException {
+ String path = Utils.getWorkingDirectory().getCanonicalPath();
+ path += this.gid + File.separator;
+ this.workingDir = new File(path);
+ }
+
+ @Override
+ public void rip() throws IOException {
System.err.println("Connecting to " + this.url.toExternalForm());
Document doc = Jsoup.connect(this.url.toExternalForm()).get();
for (Element thumb : doc.select("#gallery img")) {
@@ -52,17 +71,22 @@ public class ImagefapRipper extends AbstractRipper {
continue;
}
String image = thumb.attr("src");
- image = image.replaceAll("http://x.*.fap.to/images/thumb/", "http://fap.to/images/full/");
+ image = image.replaceAll("http://x.*.fap.to/images/thumb/",
+ "http://fap.to/images/full/");
+ processURL(image);
System.err.println(image);
}
- }
+ }
- public boolean canRip(URL url) {
- if (!url.getHost().endsWith(HOST)) {
- return false;
- }
- return true;
- }
+ public void processURL(String url) {
+
+ }
+
+ public boolean canRip(URL url) {
+ if (!url.getHost().endsWith(HOST)) {
+ return false;
+ }
+ return true;
+ }
}
-
diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java
new file mode 100644
index 00000000..79692d9e
--- /dev/null
+++ b/src/main/java/com/rarchives/ripme/utils/Utils.java
@@ -0,0 +1,47 @@
+package com.rarchives.ripme.utils;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
+import org.jsoup.Connection.Response;
+import org.jsoup.Jsoup;
+
+public class Utils {
+
+ public static final String RIP_DIRECTORY = "rips";
+
+ public static File getWorkingDirectory() throws IOException {
+ String path = new File(".").getCanonicalPath() + File.separator;
+ path += RIP_DIRECTORY + File.separator;
+ File workingDir = new File(path);
+ if (!workingDir.exists()) {
+ workingDir.mkdirs();
+ }
+ return workingDir;
+ }
+
+ public static String getConfigString(String key) {
+ Configuration config = null;
+ try {
+ config = new PropertiesConfiguration("rip.properties");
+ } catch (ConfigurationException e) {
+ System.err.println(e);
+ return null;
+ }
+ return config.getString(key);
+ }
+
+ public static void downloadFile(String url, File saveAs) throws IOException {
+ Response response = Jsoup.connect(url)
+ .ignoreContentType(true)
+ .execute();
+
+ FileOutputStream out = (new FileOutputStream(saveAs));
+ out.write(response.bodyAsBytes());
+ out.close();
+ }
+}
\ No newline at end of file