Imagefap rips are stored in directory named after album #17

Fall-back uses original directory-naming scheme (host_galleryid)
This commit is contained in:
4pr0n 2014-04-10 23:42:14 -07:00
parent 7f28f7a6a6
commit 4207a4f186
3 changed files with 81 additions and 5 deletions

View File

@ -264,7 +264,7 @@ public abstract class AbstractRipper
if (!path.endsWith(File.separator)) { if (!path.endsWith(File.separator)) {
path += File.separator; path += File.separator;
} }
path += getHost() + "_" + getGID(this.url) + File.separator; path += getAlbumTitle(this.url) + File.separator;
this.workingDir = new File(path); this.workingDir = new File(path);
if (!this.workingDir.exists()) { if (!this.workingDir.exists()) {
logger.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir)); logger.info("[+] Creating directory: " + Utils.removeCWD(this.workingDir));
@ -272,6 +272,10 @@ public abstract class AbstractRipper
} }
logger.debug("Set working directory to: " + this.workingDir); logger.debug("Set working directory to: " + this.workingDir);
} }
public String getAlbumTitle(URL url) throws MalformedURLException {
return getHost() + "_" + getGID(url);
}
/** /**
* Finds, instantiates, and returns a compatible ripper for given URL. * Finds, instantiates, and returns a compatible ripper for given URL.

View File

@ -19,6 +19,8 @@ public class ImagefapRipper extends AbstractRipper {
HOST = "imagefap"; HOST = "imagefap";
private static final Logger logger = Logger.getLogger(ImagefapRipper.class); private static final Logger logger = Logger.getLogger(ImagefapRipper.class);
private Document albumDoc = null;
public ImagefapRipper(URL url) throws IOException { public ImagefapRipper(URL url) throws IOException {
super(url); super(url);
} }
@ -38,18 +40,41 @@ public class ImagefapRipper extends AbstractRipper {
logger.debug("Sanitized URL from " + url + " to " + newURL); logger.debug("Sanitized URL from " + url + " to " + newURL);
return newURL; return newURL;
} }
public String getAlbumTitle(URL url) throws MalformedURLException {
try {
// Attempt to use album title as GID
if (albumDoc == null) {
albumDoc = Jsoup.connect(url.toExternalForm()).get();
}
String title = albumDoc.title();
Pattern p = Pattern.compile("^Porn pics of (.*) \\(Page 1\\)$");
Matcher m = p.matcher(title);
if (m.matches()) {
return m.group(1);
}
} catch (IOException e) {
// Fall back to default album naming convention
}
return super.getAlbumTitle(url);
}
@Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^.*imagefap.com/gallery.php\\?gid=([0-9]{1,}).*$"); Pattern p; Matcher m;
Matcher m = p.matcher(url.toExternalForm());
p = Pattern.compile("^.*imagefap.com/gallery.php\\?gid=([0-9]{1,}).*$");
m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);
} }
p = Pattern.compile("^.*imagefap.com/pictures/([0-9]{1,}).*$"); p = Pattern.compile("^.*imagefap.com/pictures/([0-9]{1,}).*$");
m = p.matcher(url.toExternalForm()); m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
return m.group(1); return m.group(1);
} }
throw new MalformedURLException( throw new MalformedURLException(
"Expected imagefap.com gallery formats: " "Expected imagefap.com gallery formats: "
+ "imagefap.com/gallery.php?gid=####... or " + "imagefap.com/gallery.php?gid=####... or "
@ -61,8 +86,10 @@ public class ImagefapRipper extends AbstractRipper {
public void rip() throws IOException { public void rip() throws IOException {
int index = 0; int index = 0;
logger.info(" Retrieving " + this.url.toExternalForm()); logger.info(" Retrieving " + this.url.toExternalForm());
Document doc = Jsoup.connect(this.url.toExternalForm()).get(); if (albumDoc == null) {
for (Element thumb : doc.select("#gallery img")) { albumDoc = Jsoup.connect(this.url.toExternalForm()).get();
}
for (Element thumb : albumDoc.select("#gallery img")) {
if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) { if (!thumb.hasAttr("src") || !thumb.hasAttr("width")) {
continue; continue;
} }

View File

@ -0,0 +1,45 @@
package com.rarchives.ripme.tst.ripper.rippers;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.rarchives.ripme.ripper.rippers.ImagefapRipper;
public class ImagefapRipperTest extends RippersTest {
public void testImagefapGID() throws IOException {
if (!DOWNLOAD_CONTENT) {
return;
}
Map<URL, String> testURLs = new HashMap<URL, String>();
testURLs.put(new URL("http://www.imagefap.com/pictures/4649440/Frozen-%28Elsa-and-Anna%29?view=2"), "Frozen (Elsa and Anna)");
for (URL url : testURLs.keySet()) {
ImagefapRipper ripper = new ImagefapRipper(url);
assertEquals(testURLs.get(url), ripper.getAlbumTitle(ripper.getURL()));
deleteDir(ripper.getWorkingDir());
}
}
public void testImagefapAlbums() throws IOException {
if (!DOWNLOAD_CONTENT) {
return;
}
List<URL> contentURLs = new ArrayList<URL>();
contentURLs.add(new URL("http://www.imagefap.com/pictures/4649440/Frozen-%28Elsa-and-Anna%29?view=2"));
for (URL url : contentURLs) {
try {
ImagefapRipper ripper = new ImagefapRipper(url);
ripper.rip();
assert(ripper.getWorkingDir().listFiles().length > 1);
deleteDir(ripper.getWorkingDir());
} catch (Exception e) {
fail("Error while ripping URL " + url + ": " + e.getMessage());
}
}
}
}