1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-23 05:53:02 +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", private static final String DOMAIN = "tumblr.com",
HOST = "tumblr", HOST = "tumblr",
IMAGE_PATTERN = "([^\\s]+(\\.(?i)(jpg|png|gif|bmp))$)"; IMAGE_PATTERN = "([^\\s]+(\\.(?i)(?:jpg|png|gif|bmp))$)";
private enum ALBUM_TYPE { private enum ALBUM_TYPE {
SUBDOMAIN, SUBDOMAIN,
@@ -236,8 +236,12 @@ public class TumblrRipper extends AlbumRipper {
Matcher m; Matcher m;
p = Pattern.compile(IMAGE_PATTERN); p = Pattern.compile(IMAGE_PATTERN);
String fileLocation;
URL fileURL; URL fileURL;
Pattern qualP = Pattern.compile("_[0-9]+\\.(jpg|png|gif|bmp)$");
Matcher qualM;
if (albumType == ALBUM_TYPE.LIKED) { if (albumType == ALBUM_TYPE.LIKED) {
posts = json.getJSONObject("response").getJSONArray("liked_posts"); posts = json.getJSONObject("response").getJSONArray("liked_posts");
} else { } else {
@@ -256,7 +260,10 @@ public class TumblrRipper extends AlbumRipper {
for (int j = 0; j < photos.length(); j++) { for (int j = 0; j < photos.length(); j++) {
photo = photos.getJSONObject(j); photo = photos.getJSONObject(j);
try { 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()); m = p.matcher(fileURL.toString());
if (m.matches()) { if (m.matches()) {
@@ -281,7 +288,12 @@ public class TumblrRipper extends AlbumRipper {
Document d = Jsoup.parse(post.getString("body")); Document d = Jsoup.parse(post.getString("body"));
if (!d.select("img").attr("src").isEmpty()) { if (!d.select("img").attr("src").isEmpty()) {
try { 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) { } catch (MalformedURLException e) {
LOGGER.error("[!] Error while getting embedded image at " + post, e); LOGGER.error("[!] Error while getting embedded image at " + post, e);
return true; return true;