1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-09-01 18:03:55 +02:00

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

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