ImageBam album fixed, more Documentation
Slightly fixed it, but don't know CSS so it's kinda a bootleg approach, but it works extremely well. Added bits of documentation here and there, and changed <arraylist>.size() == 0 to <arraylist>.isEmpty() for more readability.
This commit is contained in:
parent
43cff6f802
commit
1c38a86d3d
@ -1,5 +1,9 @@
|
|||||||
package com.rarchives.ripme.ripper.rippers;
|
package com.rarchives.ripme.ripper.rippers;
|
||||||
|
|
||||||
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
||||||
|
import com.rarchives.ripme.ripper.DownloadThreadPool;
|
||||||
|
import com.rarchives.ripme.utils.Http;
|
||||||
|
import com.rarchives.ripme.utils.Utils;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
@ -7,16 +11,10 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.jsoup.nodes.Document;
|
import org.jsoup.nodes.Document;
|
||||||
import org.jsoup.nodes.Element;
|
import org.jsoup.nodes.Element;
|
||||||
import org.jsoup.select.Elements;
|
import org.jsoup.select.Elements;
|
||||||
|
|
||||||
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
|
||||||
import com.rarchives.ripme.ripper.DownloadThreadPool;
|
|
||||||
import com.rarchives.ripme.utils.Http;
|
|
||||||
import com.rarchives.ripme.utils.Utils;
|
|
||||||
|
|
||||||
public class ImagebamRipper extends AbstractHTMLRipper {
|
public class ImagebamRipper extends AbstractHTMLRipper {
|
||||||
|
|
||||||
// Current HTML document
|
// Current HTML document
|
||||||
@ -71,7 +69,7 @@ public class ImagebamRipper extends AbstractHTMLRipper {
|
|||||||
public Document getNextPage(Document doc) throws IOException {
|
public Document getNextPage(Document doc) throws IOException {
|
||||||
// Find next page
|
// Find next page
|
||||||
Elements hrefs = doc.select("a.pagination_current + a.pagination_link");
|
Elements hrefs = doc.select("a.pagination_current + a.pagination_link");
|
||||||
if (hrefs.size() == 0) {
|
if (hrefs.isEmpty()) {
|
||||||
throw new IOException("No more pages");
|
throw new IOException("No more pages");
|
||||||
}
|
}
|
||||||
String nextUrl = "http://www.imagebam.com" + hrefs.first().attr("href");
|
String nextUrl = "http://www.imagebam.com" + hrefs.first().attr("href");
|
||||||
@ -121,8 +119,8 @@ public class ImagebamRipper extends AbstractHTMLRipper {
|
|||||||
* Handles case when site has IP-banned the user.
|
* Handles case when site has IP-banned the user.
|
||||||
*/
|
*/
|
||||||
private class ImagebamImageThread extends Thread {
|
private class ImagebamImageThread extends Thread {
|
||||||
private URL url;
|
private URL url; //link to "image page"
|
||||||
private int index;
|
private int index; //index in album
|
||||||
|
|
||||||
ImagebamImageThread(URL url, int index) {
|
ImagebamImageThread(URL url, int index) {
|
||||||
super();
|
super();
|
||||||
@ -135,23 +133,38 @@ public class ImagebamRipper extends AbstractHTMLRipper {
|
|||||||
fetchImage();
|
fetchImage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rips useful image from "image page"
|
||||||
|
*/
|
||||||
private void fetchImage() {
|
private void fetchImage() {
|
||||||
try {
|
try {
|
||||||
Document doc = Http.url(url).get();
|
Document doc = Http.url(url).get();
|
||||||
// Find image
|
// Find image
|
||||||
Elements images = doc.select(".image-container img");
|
Elements metaTags = doc.getElementsByTag("meta");
|
||||||
if (images.size() == 0) {
|
|
||||||
|
String imgsrc = "";//initialize, so no NullPointerExceptions should ever happen.
|
||||||
|
|
||||||
|
for (Element metaTag: metaTags) {
|
||||||
|
//the direct link to the image seems to always be linked in the <meta> part of the html.
|
||||||
|
if(metaTag.attr("property").equals("og:image")) {
|
||||||
|
imgsrc = metaTag.attr("content");
|
||||||
|
logger.info("Found URL " + imgsrc);
|
||||||
|
break;//only one (useful) image possible for an "image page".
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//for debug, or something goes wrong.
|
||||||
|
if (imgsrc.isEmpty()) {
|
||||||
logger.warn("Image not found at " + this.url);
|
logger.warn("Image not found at " + this.url);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Element image = images.first();
|
|
||||||
String imgsrc = image.attr("src");
|
|
||||||
logger.info("Found URL " + imgsrc);
|
|
||||||
// Provide prefix and let the AbstractRipper "guess" the filename
|
// Provide prefix and let the AbstractRipper "guess" the filename
|
||||||
String prefix = "";
|
String prefix = "";
|
||||||
if (Utils.getConfigBoolean("download.save_order", true)) {
|
if (Utils.getConfigBoolean("download.save_order", true)) {
|
||||||
prefix = String.format("%03d_", index);
|
prefix = String.format("%03d_", index);
|
||||||
}
|
}
|
||||||
|
|
||||||
addURLToDownload(new URL(imgsrc), prefix);
|
addURLToDownload(new URL(imgsrc), prefix);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
logger.error("[!] Exception while loading/parsing " + this.url, e);
|
logger.error("[!] Exception while loading/parsing " + this.url, e);
|
||||||
|
Loading…
Reference in New Issue
Block a user