Merge pull request #102 from CodeDestroyer/master

Fixed tumblr url redirect
This commit is contained in:
4_pr0n 2014-08-01 09:55:08 -07:00
commit fb7ec2076f

View File

@ -5,11 +5,9 @@ import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import com.rarchives.ripme.ripper.AlbumRipper; import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS; import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
@ -18,7 +16,8 @@ import com.rarchives.ripme.utils.Utils;
public class TumblrRipper extends AlbumRipper { 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))$)";
private enum ALBUM_TYPE { private enum ALBUM_TYPE {
SUBDOMAIN, SUBDOMAIN,
@ -120,6 +119,10 @@ public class TumblrRipper extends AlbumRipper {
private boolean handleJSON(JSONObject json) { private boolean handleJSON(JSONObject json) {
JSONArray posts, photos; JSONArray posts, photos;
JSONObject post, photo; JSONObject post, photo;
Pattern p;
Matcher m;
p = Pattern.compile(IMAGE_PATTERN);
URL fileURL; URL fileURL;
posts = json.getJSONObject("response").getJSONArray("posts"); posts = json.getJSONObject("response").getJSONArray("posts");
@ -136,7 +139,13 @@ public class TumblrRipper extends AlbumRipper {
photo = photos.getJSONObject(j); photo = photos.getJSONObject(j);
try { try {
fileURL = new URL(photo.getJSONObject("original_size").getString("url")); fileURL = new URL(photo.getJSONObject("original_size").getString("url"));
addURLToDownload(fileURL); m = p.matcher(fileURL.toString());
if(m.matches()) {
addURLToDownload(fileURL);
} else{
URL redirectedURL = Http.url(fileURL).ignoreContentType().response().url();
addURLToDownload(redirectedURL);
}
} catch (Exception e) { } catch (Exception e) {
logger.error("[!] Error while parsing photo in " + photo, e); logger.error("[!] Error while parsing photo in " + photo, e);
continue; continue;