mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-09-08 21:20:51 +02:00
Got log4j logging and apache config working (?)
This commit is contained in:
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
47
src/main/java/com/rarchives/ripme/utils/Utils.java
Normal file
47
src/main/java/com/rarchives/ripme/utils/Utils.java
Normal file
@@ -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();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user