v1.2.6: Fix 500px ripper to fetch higher-res, non-watermarked images.

Closes #260
This commit is contained in:
4pr0n 2015-12-22 07:47:58 -08:00
parent 61d86e5b7e
commit d4d6e4f57b
4 changed files with 42 additions and 17 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.rarchives.ripme</groupId> <groupId>com.rarchives.ripme</groupId>
<artifactId>ripme</artifactId> <artifactId>ripme</artifactId>
<packaging>jar</packaging> <packaging>jar</packaging>
<version>1.2.5</version> <version>1.2.6</version>
<name>ripme</name> <name>ripme</name>
<url>http://rip.rarchives.com</url> <url>http://rip.rarchives.com</url>
<properties> <properties>

View File

@ -176,7 +176,7 @@ public abstract class AbstractRipper
* @param url * @param url
* URL being retrieved * URL being retrieved
*/ */
public void retrievingSource(URL url) { public void retrievingSource(String url) {
RipStatusMessage msg = new RipStatusMessage(STATUS.LOADING_RESOURCE, url); RipStatusMessage msg = new RipStatusMessage(STATUS.LOADING_RESOURCE, url);
observer.update(this, msg); observer.update(this, msg);
} }

View File

@ -12,6 +12,8 @@ import java.util.regex.Pattern;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AbstractJSONRipper; import com.rarchives.ripme.ripper.AbstractJSONRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS; import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
@ -184,21 +186,44 @@ public class FivehundredpxRipper extends AbstractJSONRipper {
JSONArray photos = json.getJSONArray("photos"); JSONArray photos = json.getJSONArray("photos");
for (int i = 0; i < photos.length(); i++) { for (int i = 0; i < photos.length(); i++) {
JSONObject photo = photos.getJSONObject(i); JSONObject photo = photos.getJSONObject(i);
String imageURL = photo.getString("image_url"); String imageURL = null;
imageURL = imageURL.replaceAll("/4\\.", "/5."); String rawUrl = "https://500px.com" + photo.getString("url");
// See if there's larger images Document doc;
for (String imageSize : new String[] { "2048" } ) { Elements metas = new Elements();
String fsURL = imageURL.replaceAll("/5\\.", "/" + imageSize + "."); try {
sleep(10); logger.debug("Loading " + rawUrl);
if (urlExists(fsURL)) { super.retrievingSource(rawUrl);
logger.info("Found larger image at " + fsURL); doc = Http.url(rawUrl).get();
imageURL = fsURL; metas = doc.select("meta[property=\"twitter:image:src\"]");
break;
}
} }
imageURLs.add(imageURL); catch (IOException e) {
if (isThisATest()) { logger.error("Error fetching full-size image from " + rawUrl, e);
break; }
if (metas.size() > 0) {
imageURL = metas.first().attr("content");
}
else {
imageURL = photo.getString("image_url");
imageURL = imageURL.replaceAll("/4\\.", "/5.");
// See if there's larger images
for (String imageSize : new String[] { "2048" } ) {
String fsURL = imageURL.replaceAll("/5\\.", "/" + imageSize + ".");
sleep(10);
if (urlExists(fsURL)) {
logger.info("Found larger image at " + fsURL);
imageURL = fsURL;
break;
}
}
}
if (imageURL == null) {
logger.error("Failed to find image for photo " + photo.toString());
}
else {
imageURLs.add(imageURL);
if (isThisATest()) {
break;
}
} }
} }
return imageURLs; return imageURLs;

View File

@ -21,7 +21,7 @@ import com.rarchives.ripme.utils.Utils;
public class UpdateUtils { public class UpdateUtils {
private static final Logger logger = Logger.getLogger(UpdateUtils.class); private static final Logger logger = Logger.getLogger(UpdateUtils.class);
private static final String DEFAULT_VERSION = "1.2.5"; private static final String DEFAULT_VERSION = "1.2.6";
private static final String updateJsonURL = "http://rarchives.com/ripme.json"; private static final String updateJsonURL = "http://rarchives.com/ripme.json";
private static final String updateJarURL = "http://rarchives.com/ripme.jar"; private static final String updateJarURL = "http://rarchives.com/ripme.jar";
private static final String mainFileName = "ripme.jar"; private static final String mainFileName = "ripme.jar";