Merge pull request #957 from cyian-1756/tumblrEmbeddedImageSupport

Tumblr embedded image support
This commit is contained in:
cyian-1756 2018-09-27 08:10:21 -04:00 committed by GitHub
commit 2a71a30b4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 14 deletions

View File

@ -19,6 +19,9 @@ import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Http;
import com.rarchives.ripme.utils.Utils;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
public class TumblrRipper extends AlbumRipper {
@ -46,6 +49,10 @@ public class TumblrRipper extends AlbumRipper {
* @return Tumblr API key
*/
public static String getApiKey() {
// Use a different api ket for unit tests so we don't get 429 errors
if (isThisATest()) {
return "UHpRFx16HFIRgQjtjJKgfVIcwIeb71BYwOQXTMtiCvdSEPjV7N";
}
if (API_KEY == null) {
API_KEY = pickRandomApiKey();
}
@ -235,7 +242,6 @@ public class TumblrRipper extends AlbumRipper {
for (int j = 0; j < photos.length(); j++) {
photo = photos.getJSONObject(j);
try {
// If the url is shorter than 65 chars long we skip it because it's those images don't support grabbing them in fullsize
fileURL = new URL(photo.getJSONObject("original_size").getString("url").replaceAll("http:", "https:"));
m = p.matcher(fileURL.toString());
@ -257,6 +263,16 @@ public class TumblrRipper extends AlbumRipper {
LOGGER.error("[!] Error while parsing video in " + post, e);
return true;
}
} else if (post.has("body")) {
Document d = Jsoup.parse(post.getString("body"));
if (!d.select("img").attr("src").isEmpty()) {
try {
addURLToDownload(new URL(d.select("img").attr("src")));
} catch (MalformedURLException e) {
LOGGER.error("[!] Error while getting embedded image at " + post, e);
return true;
}
}
}
if (albumType == ALBUM_TYPE.POST) {
return false;

View File

@ -7,19 +7,21 @@ import java.net.URL;
import com.rarchives.ripme.ripper.rippers.TumblrRipper;
public class TumblrRipperTest extends RippersTest {
// https://github.com/RipMeApp/ripme/issues/250
/*
public void testTumblrFullRip() throws IOException {
TumblrRipper ripper = new TumblrRipper(new URL("http://wrouinr.tumblr.com/archive"));
// public void testTumblrFullRip() throws IOException {
// TumblrRipper ripper = new TumblrRipper(new URL("http://wrouinr.tumblr.com"));
// testRipper(ripper);
// }
// public void testTumblrTagRip() throws IOException {
// TumblrRipper ripper = new TumblrRipper(new URL("https://these-are-my-b-sides.tumblr.com/tagged/boobs"));
// testRipper(ripper);
// }
// public void testTumblrPostRip() throws IOException {
// TumblrRipper ripper = new TumblrRipper(new URL("http://sadbaffoon.tumblr.com/post/132045920789/what-a-hoe"));
// testRipper(ripper);
// }
public void testEmbeddedImage() throws IOException {
TumblrRipper ripper = new TumblrRipper(new URL("https://these-are-my-b-sides.tumblr.com/post/178225921524/this-was-fun"));
testRipper(ripper);
}
public void testTumblrTagRip() throws IOException {
TumblrRipper ripper = new TumblrRipper(new URL("http://topinstagirls.tumblr.com/tagged/berlinskaya"));
testRipper(ripper);
}
public void testTumblrPostRip() throws IOException {
TumblrRipper ripper = new TumblrRipper(new URL("http://sadbaffoon.tumblr.com/post/132045920789/what-a-hoe"));
testRipper(ripper);
}
*/
}