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:
19
src/main/java/com/rarchives/ripme/App.java
Normal file
19
src/main/java/com/rarchives/ripme/App.java
Normal 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();
|
||||
}
|
||||
}
|
24
src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java
Normal file
24
src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
33
src/test/java/com/rarchives/ripme/AppTest.java
Normal file
33
src/test/java/com/rarchives/ripme/AppTest.java
Normal 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 );
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user