commit db9a87595eea6528e07f79997868f430b2217933 Author: 4pr0n Date: Tue Feb 25 01:28:22 2014 -0800 initial commit. basic ripper skeleton. long ways to go diff --git a/.classpath b/.classpath new file mode 100644 index 00000000..0a1daddd --- /dev/null +++ b/.classpath @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 00000000..89407457 --- /dev/null +++ b/.project @@ -0,0 +1,23 @@ + + + ripme + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..29728d21 --- /dev/null +++ b/pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + com.rarchives.ripme + ripme + jar + 1.0-SNAPSHOT + ripme + http://maven.apache.org + + + junit + junit + 3.8.1 + test + + + + org.jsoup + jsoup + 1.7.3 + + + org.json + json + 20140107 + + + + + + maven-assembly-plugin + + + + fully.qualified.MainClass + + + + jar-with-dependencies + + + + + + diff --git a/src/main/java/com/rarchives/ripme/App.java b/src/main/java/com/rarchives/ripme/App.java new file mode 100644 index 00000000..acc8e396 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/App.java @@ -0,0 +1,19 @@ +package com.rarchives.ripme; + +import java.io.IOException; +import java.net.URL; + +import com.rarchives.ripme.ripper.rippers.ImagefapRipper; + +/** + * + */ +public class App { + public static void main( String[] args ) throws IOException { + 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(); + } +} diff --git a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java new file mode 100644 index 00000000..59848d9a --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java @@ -0,0 +1,24 @@ +package com.rarchives.ripme.ripper; + +import java.net.MalformedURLException; +import java.net.URL; + +public abstract class AbstractRipper implements RipperInterface { + + protected URL url; + + public AbstractRipper(URL url) throws MalformedURLException { + // Ensure that the inheriting class can rip this URL. + if (!canRip(url)) { + throw new MalformedURLException("Unable to rip url: " + url); + } + this.url = url; + sanitizeURL(); + } + + public URL getURL() { + return url; + } + +} + diff --git a/src/main/java/com/rarchives/ripme/ripper/RipperInterface.java b/src/main/java/com/rarchives/ripme/ripper/RipperInterface.java new file mode 100644 index 00000000..3f8f3318 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/RipperInterface.java @@ -0,0 +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 boolean canRip(URL url); + public void sanitizeURL() throws MalformedURLException; +} diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/ImagefapRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/ImagefapRipper.java new file mode 100644 index 00000000..4d205870 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/ImagefapRipper.java @@ -0,0 +1,68 @@ +package com.rarchives.ripme.ripper.rippers; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.rarchives.ripme.ripper.AbstractRipper; + +public class ImagefapRipper extends AbstractRipper { + + 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()); + 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"); + } + + 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")) { + if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) { + continue; + } + String image = thumb.attr("src"); + image = image.replaceAll("http://x.*.fap.to/images/thumb/", "http://fap.to/images/full/"); + System.err.println(image); + } + } + + public boolean canRip(URL url) { + if (!url.getHost().endsWith(HOST)) { + return false; + } + return true; + } + +} + diff --git a/src/test/java/com/rarchives/ripme/AppTest.java b/src/test/java/com/rarchives/ripme/AppTest.java new file mode 100644 index 00000000..a6ad444f --- /dev/null +++ b/src/test/java/com/rarchives/ripme/AppTest.java @@ -0,0 +1,33 @@ +package com.rarchives.ripme; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest extends TestCase { + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() { + assertTrue( true ); + } +}