mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-26 15:24:51 +02:00
Fixed E621 ripper not ripping.
This commit is contained in:
@@ -6,8 +6,6 @@ import com.rarchives.ripme.utils.Http;
|
||||
import com.rarchives.ripme.utils.Utils;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -54,27 +52,6 @@ public class E621Ripper extends AbstractHTMLRipper{
|
||||
return Http.url("https://e621.net/post/index/1/" + getTerm(url)).get();
|
||||
}
|
||||
|
||||
private String getFullSizedImage(String url) {
|
||||
try {
|
||||
Document page = Http.url("https://e621.net" + url).get();
|
||||
Elements video = page.select("video > source");
|
||||
Elements flash = page.select("embed");
|
||||
Elements image = page.select("a#highres");
|
||||
if (video.size() > 0) {
|
||||
return video.attr("src");
|
||||
} else if (flash.size() > 0) {
|
||||
return flash.attr("src");
|
||||
} else if (image.size() > 0) {
|
||||
return image.attr("href");
|
||||
} else {
|
||||
throw new IOException();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Unable to get full sized image from " + url);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getURLsFromPage(Document page) {
|
||||
Elements elements = page.select("div > span.thumb > a");
|
||||
@@ -82,10 +59,7 @@ public class E621Ripper extends AbstractHTMLRipper{
|
||||
|
||||
for (Element e : elements) {
|
||||
if (!e.attr("href").isEmpty()) {
|
||||
String fullSizedImage = getFullSizedImage(e.attr("href"));
|
||||
if (fullSizedImage != null && !fullSizedImage.equals("")) {
|
||||
res.add(getFullSizedImage(e.attr("href")));
|
||||
}
|
||||
res.add(e.attr("abs:href"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,23 +68,26 @@ public class E621Ripper extends AbstractHTMLRipper{
|
||||
|
||||
@Override
|
||||
public Document getNextPage(Document page) throws IOException {
|
||||
if (page.select("a.next_page") != null) {
|
||||
return Http.url("https://e621.net" + page.select("a.next_page").attr("href")).get();
|
||||
if (!page.select("a.next_page").isEmpty()) {
|
||||
return Http.url(page.select("a.next_page").attr("abs:href")).get();
|
||||
} else {
|
||||
throw new IOException("No more pages");
|
||||
throw new IOException("No more pages.");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadURL(final URL url, int index) {
|
||||
addURLToDownload(url, getPrefix(index));
|
||||
// addURLToDownload(url, getPrefix(index));
|
||||
e621ThreadPool.addThread(new E621FileThread(url, getPrefix(index)));
|
||||
}
|
||||
|
||||
private String getTerm(URL url) throws MalformedURLException {
|
||||
if (gidPattern == null)
|
||||
gidPattern=Pattern.compile("^https?://(www\\.)?e621\\.net/post/index/[^/]+/([a-zA-Z0-9$_.+!*'():,%\\-]+)(/.*)?(#.*)?$");
|
||||
gidPattern = Pattern.compile(
|
||||
"^https?://(www\\.)?e621\\.net/post/index/[^/]+/([a-zA-Z0-9$_.+!*'():,%\\-]+)(/.*)?(#.*)?$");
|
||||
if (gidPatternPool == null)
|
||||
gidPatternPool=Pattern.compile("^https?://(www\\.)?e621\\.net/pool/show/([a-zA-Z0-9$_.+!*'(),%:\\-]+)(\\?.*)?(/.*)?(#.*)?$");
|
||||
gidPatternPool = Pattern.compile(
|
||||
"^https?://(www\\.)?e621\\.net/pool/show/([a-zA-Z0-9$_.+!*'(),%:\\-]+)(\\?.*)?(/.*)?(#.*)?$");
|
||||
|
||||
Matcher m = gidPattern.matcher(url.toExternalForm());
|
||||
if (m.matches()) {
|
||||
@@ -123,25 +100,24 @@ public class E621Ripper extends AbstractHTMLRipper{
|
||||
return m.group(2);
|
||||
}
|
||||
|
||||
throw new MalformedURLException("Expected e621.net URL format: e621.net/post/index/1/searchterm - got "+url+" instead");
|
||||
throw new MalformedURLException(
|
||||
"Expected e621.net URL format: e621.net/post/index/1/searchterm - got " + url + " instead");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getGID(URL url) throws MalformedURLException {
|
||||
|
||||
String prefix = "";
|
||||
if (url.getPath().startsWith("/pool/show/")) {
|
||||
prefix = "pool_";
|
||||
}
|
||||
|
||||
return Utils.filesystemSafe(prefix + getTerm(url));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public URL sanitizeURL(URL url) throws MalformedURLException {
|
||||
if (gidPattern2 == null)
|
||||
gidPattern2=Pattern.compile("^https?://(www\\.)?e621\\.net/post/search\\?tags=([a-zA-Z0-9$_.+!*'():,%-]+)(/.*)?(#.*)?$");
|
||||
gidPattern2 = Pattern.compile(
|
||||
"^https?://(www\\.)?e621\\.net/post/search\\?tags=([a-zA-Z0-9$_.+!*'():,%-]+)(/.*)?(#.*)?$");
|
||||
|
||||
Matcher m = gidPattern2.matcher(url.toExternalForm());
|
||||
if (m.matches())
|
||||
@@ -150,4 +126,44 @@ public class E621Ripper extends AbstractHTMLRipper{
|
||||
return url;
|
||||
}
|
||||
|
||||
public class E621FileThread extends Thread {
|
||||
|
||||
private URL url;
|
||||
private String index;
|
||||
|
||||
public E621FileThread(URL url, String index) {
|
||||
this.url = url;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String fullSizedImage = getFullSizedImage(url);
|
||||
if (fullSizedImage != null && !fullSizedImage.equals("")) {
|
||||
addURLToDownload(new URL(fullSizedImage), index);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
logger.error("Unable to get full sized image from " + url);
|
||||
}
|
||||
}
|
||||
|
||||
private String getFullSizedImage(URL imageURL) throws IOException {
|
||||
Document page = Http.url(imageURL).retries(3).get();
|
||||
Elements video = page.select("video > source");
|
||||
Elements flash = page.select("embed");
|
||||
Elements image = page.select("a#highres");
|
||||
if (video.size() > 0) {
|
||||
return video.attr("src");
|
||||
} else if (flash.size() > 0) {
|
||||
return flash.attr("src");
|
||||
} else if (image.size() > 0) {
|
||||
return image.attr("href");
|
||||
} else {
|
||||
throw new IOException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -10,4 +10,26 @@ public class E621RipperTest extends RippersTest {
|
||||
E621Ripper ripper = new E621Ripper(new URL("https://e621.net/post/index/1/beach"));
|
||||
testRipper(ripper);
|
||||
}
|
||||
|
||||
public void testFlashOrWebm() throws IOException {
|
||||
E621Ripper ripper = new E621Ripper(new URL("https://e621.net/post/index/1/gif"));
|
||||
testRipper(ripper);
|
||||
}
|
||||
|
||||
public void testGetNextPage() throws IOException {
|
||||
E621Ripper nextPageRipper = new E621Ripper(new URL("https://e621.net/post/index/1/cosmicminerals"));
|
||||
try {
|
||||
nextPageRipper.getNextPage(nextPageRipper.getFirstPage());
|
||||
assert (true);
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
|
||||
E621Ripper noNextPageRipper = new E621Ripper(new URL("https://e621.net/post/index/1/cosmicminerals"));
|
||||
try {
|
||||
noNextPageRipper.getNextPage(noNextPageRipper.getFirstPage());
|
||||
} catch (IOException e) {
|
||||
assertEquals(e.getMessage(), "No more pages.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user