Got log4j logging and apache config working (?)
This commit is contained in:
parent
db9a87595e
commit
582ecd8ae8
@ -12,12 +12,13 @@
|
|||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
|
<classpathentry kind="src" path="config"/>
|
||||||
|
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry exported="true" kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
</attributes>
|
</attributes>
|
||||||
|
5
.settings/org.eclipse.jdt.core.prefs
Normal file
5
.settings/org.eclipse.jdt.core.prefs
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
eclipse.preferences.version=1
|
||||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||||
|
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
|
||||||
|
org.eclipse.jdt.core.compiler.source=1.5
|
4
.settings/org.eclipse.m2e.core.prefs
Normal file
4
.settings/org.eclipse.m2e.core.prefs
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
activeProfiles=
|
||||||
|
eclipse.preferences.version=1
|
||||||
|
resolveWorkspaceProjects=true
|
||||||
|
version=1
|
10
pom.xml
10
pom.xml
@ -25,6 +25,16 @@
|
|||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
<version>20140107</version>
|
<version>20140107</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-configuration</groupId>
|
||||||
|
<artifactId>commons-configuration</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>log4j</groupId>
|
||||||
|
<artifactId>log4j</artifactId>
|
||||||
|
<version>1.2.17</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
@ -3,6 +3,9 @@ package com.rarchives.ripme;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.apache.log4j.PropertyConfigurator;
|
||||||
|
|
||||||
import com.rarchives.ripme.ripper.rippers.ImagefapRipper;
|
import com.rarchives.ripme.ripper.rippers.ImagefapRipper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -10,10 +13,17 @@ import com.rarchives.ripme.ripper.rippers.ImagefapRipper;
|
|||||||
*/
|
*/
|
||||||
public class App {
|
public class App {
|
||||||
public static void main( String[] args ) throws IOException {
|
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");
|
URL url = new URL("http://www.imagefap.com/pictures/4117023/Mirror-flat-stomach-small-firm-tits");
|
||||||
System.out.println("URL: " + url.toExternalForm());
|
System.out.println("URL: " + url.toExternalForm());
|
||||||
ImagefapRipper ir = new ImagefapRipper(url);
|
ImagefapRipper ir = new ImagefapRipper(url);
|
||||||
System.out.println("Ripping");
|
System.out.println("Ripping");
|
||||||
ir.rip();
|
ir.rip();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void initialize() {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,34 @@
|
|||||||
package com.rarchives.ripme.ripper;
|
package com.rarchives.ripme.ripper;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
|
import com.rarchives.ripme.utils.Utils;
|
||||||
|
|
||||||
public abstract class AbstractRipper implements RipperInterface {
|
public abstract class AbstractRipper implements RipperInterface {
|
||||||
|
|
||||||
protected URL url;
|
protected URL url;
|
||||||
|
protected File workingDir = null;
|
||||||
|
|
||||||
public AbstractRipper(URL url) throws MalformedURLException {
|
public abstract void rip() throws IOException;
|
||||||
// Ensure that the inheriting class can rip this URL.
|
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)) {
|
if (!canRip(url)) {
|
||||||
throw new MalformedURLException("Unable to rip url: " + url);
|
throw new MalformedURLException("Unable to rip url: " + url);
|
||||||
}
|
}
|
||||||
this.url = url;
|
this.url = url;
|
||||||
sanitizeURL();
|
setWorkingDir();
|
||||||
|
workingDir = Utils.getWorkingDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getURL() {
|
public URL getURL() {
|
||||||
@ -21,4 +36,3 @@ public abstract class AbstractRipper implements RipperInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package com.rarchives.ripme.ripper;
|
package com.rarchives.ripme.ripper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
|
||||||
public interface RipperInterface {
|
public interface RipperInterface {
|
||||||
public void rip() throws IOException;
|
public void rip() throws IOException;
|
||||||
|
public void processURL(String url);
|
||||||
public boolean canRip(URL 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;
|
package com.rarchives.ripme.ripper.rippers;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -11,40 +12,58 @@ import org.jsoup.nodes.Document;
|
|||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
|
|
||||||
import com.rarchives.ripme.ripper.AbstractRipper;
|
import com.rarchives.ripme.ripper.AbstractRipper;
|
||||||
|
import com.rarchives.ripme.utils.Utils;
|
||||||
|
|
||||||
public class ImagefapRipper extends AbstractRipper {
|
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 {
|
private String gid;
|
||||||
super(url);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
public ImagefapRipper(URL url) throws IOException {
|
||||||
* Reformat given URL into the desired format (all images on single page)
|
super(url);
|
||||||
*/
|
this.gid = getGID(url);
|
||||||
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());
|
* Reformat given URL into the desired format (all images on single page)
|
||||||
if (m.matches()) {
|
*/
|
||||||
gid = m.group(1);
|
public void sanitizeURL() throws MalformedURLException {
|
||||||
} else {
|
this.url = new URL("http://www.imagefap.com/gallery.php?gid="
|
||||||
p = Pattern.compile("^.*imagefap.com/pictures/([0-9]{1,}).*$");
|
+ this.gid + "&view=2");
|
||||||
m = p.matcher(this.url.toExternalForm());
|
}
|
||||||
|
|
||||||
|
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()) {
|
if (m.matches()) {
|
||||||
gid = m.group(1);
|
gid = m.group(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (gid == null) {
|
if (gid == null) {
|
||||||
throw new MalformedURLException("Expected imagefap.com gallery formats:"
|
throw new MalformedURLException(
|
||||||
+ "imagefap.com/gallery.php?gid=####... or"
|
"Expected imagefap.com gallery formats:"
|
||||||
+ "imagefap.com/pictures/####...");
|
+ "imagefap.com/gallery.php?gid=####... or"
|
||||||
}
|
+ "imagefap.com/pictures/####...");
|
||||||
this.url = new URL("http://www.imagefap.com/gallery.php?gid=" + gid + "&view=2");
|
}
|
||||||
}
|
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());
|
System.err.println("Connecting to " + this.url.toExternalForm());
|
||||||
Document doc = Jsoup.connect(this.url.toExternalForm()).get();
|
Document doc = Jsoup.connect(this.url.toExternalForm()).get();
|
||||||
for (Element thumb : doc.select("#gallery img")) {
|
for (Element thumb : doc.select("#gallery img")) {
|
||||||
@ -52,17 +71,22 @@ public class ImagefapRipper extends AbstractRipper {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String image = thumb.attr("src");
|
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);
|
System.err.println(image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canRip(URL url) {
|
public void processURL(String url) {
|
||||||
if (!url.getHost().endsWith(HOST)) {
|
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
return true;
|
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();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user