mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-13 17:34:13 +02:00
Added error logging instead of throwing away errors blindly.
This commit is contained in:
@@ -207,10 +207,10 @@ public class FlickrRipper extends AbstractHTMLRipper {
|
|||||||
@Override
|
@Override
|
||||||
public List<String> getURLsFromPage(Document doc) {
|
public List<String> getURLsFromPage(Document doc) {
|
||||||
List<String> imageURLs = new ArrayList<>();
|
List<String> imageURLs = new ArrayList<>();
|
||||||
|
String apiKey = getAPIKey(doc);
|
||||||
int x = 1;
|
int x = 1;
|
||||||
while (true) {
|
while (true) {
|
||||||
JSONObject jsonData = getJSON(String.valueOf(x), getAPIKey(doc));
|
JSONObject jsonData = getJSON(String.valueOf(x), apiKey);
|
||||||
if (jsonData.has("stat") && jsonData.getString("stat").equals("fail")) {
|
if (jsonData.has("stat") && jsonData.getString("stat").equals("fail")) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
@@ -221,8 +221,11 @@ public class FlickrRipper extends AbstractHTMLRipper {
|
|||||||
LOGGER.info(i);
|
LOGGER.info(i);
|
||||||
JSONObject data = (JSONObject) pictures.get(i);
|
JSONObject data = (JSONObject) pictures.get(i);
|
||||||
try {
|
try {
|
||||||
addURLToDownload(getLargestImageURL(data.getString("id"), getAPIKey(doc)));
|
addURLToDownload(getLargestImageURL(data.getString("id"), apiKey));
|
||||||
} catch (IOException ignore) { }
|
} catch (MalformedURLException e) {
|
||||||
|
LOGGER.error("Flickr MalformedURLException: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
if (x >= totalPages) {
|
if (x >= totalPages) {
|
||||||
// The rips done
|
// The rips done
|
||||||
@@ -242,20 +245,24 @@ public class FlickrRipper extends AbstractHTMLRipper {
|
|||||||
addURLToDownload(url, getPrefix(index));
|
addURLToDownload(url, getPrefix(index));
|
||||||
}
|
}
|
||||||
|
|
||||||
private URL getLargestImageURL(String imageID, String apiKey) throws IOException {
|
private URL getLargestImageURL(String imageID, String apiKey) throws MalformedURLException {
|
||||||
URL imageAPIURL = new URL("https://www.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=" + apiKey + "&photo_id=" + imageID + "&format=json&nojsoncallback=1");
|
|
||||||
TreeMap<Integer, String> imageURLMap = new TreeMap<>();
|
TreeMap<Integer, String> imageURLMap = new TreeMap<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
URL imageAPIURL = new URL("https://www.flickr.com/services/rest/?method=flickr.photos.getSizes&api_key=" + apiKey + "&photo_id=" + imageID + "&format=json&nojsoncallback=1");
|
||||||
JSONArray imageSizes = new JSONObject(Http.url(imageAPIURL).ignoreContentType().get().text()).getJSONObject("sizes").getJSONArray("size");
|
JSONArray imageSizes = new JSONObject(Http.url(imageAPIURL).ignoreContentType().get().text()).getJSONObject("sizes").getJSONArray("size");
|
||||||
for (int i = 0; i < imageSizes.length(); i++) {
|
for (int i = 0; i < imageSizes.length(); i++) {
|
||||||
JSONObject imageInfo = imageSizes.getJSONObject(i);
|
JSONObject imageInfo = imageSizes.getJSONObject(i);
|
||||||
imageURLMap.put(imageInfo.getInt("width") * imageInfo.getInt("height"), imageInfo.getString("source"));
|
imageURLMap.put(imageInfo.getInt("width") * imageInfo.getInt("height"), imageInfo.getString("source"));
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (org.json.JSONException ignore) {
|
} catch (org.json.JSONException e) {
|
||||||
|
LOGGER.error("Error in parsing of Flickr API: " + e.getMessage());
|
||||||
} catch (MalformedURLException e) {}
|
} catch (MalformedURLException e) {
|
||||||
|
LOGGER.error("Malformed URL returned by API");
|
||||||
|
} catch (IOException e) {
|
||||||
|
LOGGER.error("IOException while looking at image sizes: " + e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
return new URL(imageURLMap.lastEntry().getValue());
|
return new URL(imageURLMap.lastEntry().getValue());
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user