initial commit. basic ripper skeleton. long ways to go

This commit is contained in:
4pr0n 2014-02-25 01:28:22 -08:00
commit db9a87595e
8 changed files with 250 additions and 0 deletions

26
.classpath Normal file
View File

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

23
.project Normal file
View File

@ -0,0 +1,23 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ripme</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>

46
pom.xml Normal file
View File

@ -0,0 +1,46 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.rarchives.ripme</groupId>
<artifactId>ripme</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>ripme</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<!-- jsoup HTML parser library @ http://jsoup.org/ -->
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.7.3</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20140107</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -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();
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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 );
}
}