-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
123 additions
and
0 deletions.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
src/main/java/com/rarchives/ripme/ripper/rippers/HentaifoundryRipper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
package com.rarchives.ripme.ripper.rippers; | ||
|
||
import java.io.IOException; | ||
import java.net.MalformedURLException; | ||
import java.net.URL; | ||
import java.util.Map; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.jsoup.Connection.Method; | ||
import org.jsoup.Connection.Response; | ||
import org.jsoup.Jsoup; | ||
import org.jsoup.nodes.Document; | ||
import org.jsoup.nodes.Element; | ||
import org.jsoup.select.Elements; | ||
|
||
import com.rarchives.ripme.ripper.AlbumRipper; | ||
import com.rarchives.ripme.ui.RipStatusMessage.STATUS; | ||
import com.rarchives.ripme.utils.Utils; | ||
|
||
public class HentaifoundryRipper extends AlbumRipper { | ||
|
||
private static final String DOMAIN = "hentai-foundry.com", | ||
HOST = "hentai-foundry"; | ||
|
||
public HentaifoundryRipper(URL url) throws IOException { | ||
super(url); | ||
} | ||
|
||
public boolean canRip(URL url) { | ||
return url.getHost().endsWith(DOMAIN); | ||
} | ||
|
||
public URL sanitizeURL(URL url) throws MalformedURLException { | ||
return url; | ||
} | ||
|
||
@Override | ||
public void rip() throws IOException { | ||
Pattern imgRegex = Pattern.compile(".*/user/([a-zA-Z0-9\\-_]+)/(\\d+)/.*"); | ||
String nextURL = this.url.toExternalForm(); | ||
int index = 0; | ||
|
||
// Get cookies | ||
Response resp = Jsoup.connect("http://www.hentai-foundry.com/") | ||
.execute(); | ||
Map<String,String> cookies = resp.cookies(); | ||
resp = Jsoup.connect("http://www.hentai-foundry.com/?enterAgree=1&size=1500") | ||
.referrer("http://www.hentai-foundry.com/") | ||
.cookies(cookies) | ||
.method(Method.GET) | ||
.execute(); | ||
cookies = resp.cookies(); | ||
logger.info("cookies: " + cookies); | ||
|
||
// Iterate over every page | ||
while (true) { | ||
if (isStopped()) { | ||
break; | ||
} | ||
sendUpdate(STATUS.LOADING_RESOURCE, nextURL); | ||
Document doc = Jsoup.connect(nextURL) | ||
.userAgent(USER_AGENT) | ||
.timeout(5000) | ||
.cookies(cookies) | ||
.referrer(this.url.toExternalForm()) | ||
.get(); | ||
for (Element thumb : doc.select("td > a:first-child")) { | ||
if (isStopped()) { | ||
break; | ||
} | ||
Matcher imgMatcher = imgRegex.matcher(thumb.attr("href")); | ||
if (!imgMatcher.matches()) { | ||
logger.info("Couldn't find user & image ID in " + thumb.attr("href")); | ||
continue; | ||
} | ||
String user = imgMatcher.group(1), | ||
imageId = imgMatcher.group(2); | ||
String image = "http://pictures.hentai-foundry.com//"; | ||
logger.info("user: " + user + "; imageId: " + imageId + "; image: " + image); | ||
image += user.toLowerCase().charAt(0); | ||
image += "/" + user + "/" + imageId + ".jpg"; | ||
index += 1; | ||
String prefix = ""; | ||
if (Utils.getConfigBoolean("download.save_order", true)) { | ||
prefix = String.format("%03d_", index); | ||
} | ||
addURLToDownload(new URL(image), prefix); | ||
} | ||
|
||
if (doc.select("li.next.hidden").size() > 0) { | ||
// Last page | ||
break; | ||
} | ||
Elements els = doc.select("li.next > a"); | ||
logger.info("li.next > a : " + els); | ||
Element first = els.first(); | ||
logger.info("li.next > a .first() : " + first); | ||
nextURL = first.attr("href"); | ||
logger.info("first().attr(href) : " + nextURL); | ||
nextURL = "http://www.hentai-foundry.com" + nextURL; | ||
} | ||
waitForThreads(); | ||
} | ||
|
||
@Override | ||
public String getHost() { | ||
return HOST; | ||
} | ||
|
||
@Override | ||
public String getGID(URL url) throws MalformedURLException { | ||
Pattern p = Pattern.compile("^.*hentai-foundry\\.com/pictures/user/([a-zA-Z0-9\\-_]+).*$"); | ||
Matcher m = p.matcher(url.toExternalForm()); | ||
if (m.matches()) { | ||
return m.group(1); | ||
} | ||
throw new MalformedURLException( | ||
"Expected hentai-foundry.com gallery format: " | ||
+ "hentai-foundry.com/pictures/user/USERNAME" | ||
+ " Got: " + url); | ||
} | ||
} |