Fixing reddit ripper for single posts
This commit is contained in:
parent
72f1864e4e
commit
8bb9a8d1c0
@ -121,24 +121,27 @@ public class RedditRipper extends AlbumRipper {
|
|||||||
|
|
||||||
int attempts = 0;
|
int attempts = 0;
|
||||||
logger.info(" Retrieving " + url);
|
logger.info(" Retrieving " + url);
|
||||||
JSONObject json = null;
|
String jsonString = null;
|
||||||
while(json == null && attempts++ < 3) {
|
while(jsonString == null && attempts++ < 3) {
|
||||||
try {
|
try {
|
||||||
json = Http.url(url).getJSON();
|
jsonString = Http.url(url)
|
||||||
|
.ignoreContentType()
|
||||||
|
.response()
|
||||||
|
.body();
|
||||||
} catch(SocketTimeoutException ex) {
|
} catch(SocketTimeoutException ex) {
|
||||||
if(attempts >= 3) throw ex;
|
if(attempts >= 3) throw ex;
|
||||||
logger.warn(String.format("[!] Connection timed out (attempt %d)", attempts));
|
logger.warn(String.format("[!] Connection timed out (attempt %d)", attempts));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object jsonObj = new JSONTokener(json.toString()).nextValue();
|
Object jsonObj = new JSONTokener(jsonString).nextValue();
|
||||||
JSONArray jsonArray = new JSONArray();
|
JSONArray jsonArray = new JSONArray();
|
||||||
if (jsonObj instanceof JSONObject) {
|
if (jsonObj instanceof JSONObject) {
|
||||||
jsonArray.put( (JSONObject) jsonObj);
|
jsonArray.put( (JSONObject) jsonObj);
|
||||||
} else if (jsonObj instanceof JSONArray){
|
} else if (jsonObj instanceof JSONArray){
|
||||||
jsonArray = (JSONArray) jsonObj;
|
jsonArray = (JSONArray) jsonObj;
|
||||||
} else {
|
} else {
|
||||||
logger.warn("[!] Unable to parse child: " + json.toString());
|
logger.warn("[!] Unable to parse JSON: " + jsonString);
|
||||||
}
|
}
|
||||||
return jsonArray;
|
return jsonArray;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user