1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-22 21:43:06 +02:00

Merge pull request #1178 from buzzlightmonth/tumblrRate

Tumblr ripper downloads highest quality available
This commit is contained in:
cyian-1756
2019-01-21 02:32:24 -05:00
committed by GitHub

View File

@@ -29,7 +29,7 @@ public class TumblrRipper extends AlbumRipper {
private static final String DOMAIN = "tumblr.com",
HOST = "tumblr",
IMAGE_PATTERN = "([^\\s]+(\\.(?i)(jpg|png|gif|bmp))$)";
IMAGE_PATTERN = "([^\\s]+(\\.(?i)(?:jpg|png|gif|bmp))$)";
private enum ALBUM_TYPE {
SUBDOMAIN,
@@ -236,8 +236,12 @@ public class TumblrRipper extends AlbumRipper {
Matcher m;
p = Pattern.compile(IMAGE_PATTERN);
String fileLocation;
URL fileURL;
Pattern qualP = Pattern.compile("_[0-9]+\\.(jpg|png|gif|bmp)$");
Matcher qualM;
if (albumType == ALBUM_TYPE.LIKED) {
posts = json.getJSONObject("response").getJSONArray("liked_posts");
} else {
@@ -256,7 +260,10 @@ public class TumblrRipper extends AlbumRipper {
for (int j = 0; j < photos.length(); j++) {
photo = photos.getJSONObject(j);
try {
fileURL = new URL(photo.getJSONObject("original_size").getString("url").replaceAll("http:", "https:"));
fileLocation = photo.getJSONObject("original_size").getString("url").replaceAll("http:", "https:");
qualM = qualP.matcher(fileLocation);
fileLocation = qualM.replaceFirst("_1280.$1");
fileURL = new URL(fileLocation);
m = p.matcher(fileURL.toString());
if (m.matches()) {
@@ -281,7 +288,12 @@ public class TumblrRipper extends AlbumRipper {
Document d = Jsoup.parse(post.getString("body"));
if (!d.select("img").attr("src").isEmpty()) {
try {
downloadURL(new URL(d.select("img").attr("src")), date);
String imgSrc = d.select("img").attr("src");
// Set maximum quality, tumblr doesn't go any further
// If the image is any smaller, it will still get the largest available size
qualM = qualP.matcher(imgSrc);
imgSrc = qualM.replaceFirst("_1280.$1");
downloadURL(new URL(imgSrc), date);
} catch (MalformedURLException e) {
LOGGER.error("[!] Error while getting embedded image at " + post, e);
return true;