Merge pull request #102 from CodeDestroyer/master
Fixed tumblr url redirect
This commit is contained in:
commit
fb7ec2076f
@ -5,11 +5,9 @@ import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.rarchives.ripme.ripper.AlbumRipper;
|
||||
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
|
||||
import com.rarchives.ripme.utils.Http;
|
||||
@ -18,7 +16,8 @@ import com.rarchives.ripme.utils.Utils;
|
||||
public class TumblrRipper extends AlbumRipper {
|
||||
|
||||
private static final String DOMAIN = "tumblr.com",
|
||||
HOST = "tumblr";
|
||||
HOST = "tumblr",
|
||||
IMAGE_PATTERN = "([^\\s]+(\\.(?i)(jpg|png|gif|bmp))$)";
|
||||
|
||||
private enum ALBUM_TYPE {
|
||||
SUBDOMAIN,
|
||||
@ -120,6 +119,10 @@ public class TumblrRipper extends AlbumRipper {
|
||||
private boolean handleJSON(JSONObject json) {
|
||||
JSONArray posts, photos;
|
||||
JSONObject post, photo;
|
||||
Pattern p;
|
||||
Matcher m;
|
||||
p = Pattern.compile(IMAGE_PATTERN);
|
||||
|
||||
URL fileURL;
|
||||
|
||||
posts = json.getJSONObject("response").getJSONArray("posts");
|
||||
@ -136,7 +139,13 @@ public class TumblrRipper extends AlbumRipper {
|
||||
photo = photos.getJSONObject(j);
|
||||
try {
|
||||
fileURL = new URL(photo.getJSONObject("original_size").getString("url"));
|
||||
m = p.matcher(fileURL.toString());
|
||||
if(m.matches()) {
|
||||
addURLToDownload(fileURL);
|
||||
} else{
|
||||
URL redirectedURL = Http.url(fileURL).ignoreContentType().response().url();
|
||||
addURLToDownload(redirectedURL);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("[!] Error while parsing photo in " + photo, e);
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user