mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-30 09:10:44 +02:00
Merge pull request #1207 from Gamerick/master
Closes #1143 Added support for score filtering when ripping from reddit
This commit is contained in:
@@ -118,6 +118,12 @@ public class RedditRipper extends AlbumRipper {
|
|||||||
return nextURL;
|
return nextURL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets a representation of the specified reddit page as a JSONArray using the reddit API
|
||||||
|
* @param url The url of the desired page
|
||||||
|
* @return A JSONArray object representation of the desired page
|
||||||
|
* @throws IOException If no response is received from the url
|
||||||
|
*/
|
||||||
private JSONArray getJsonArrayFromURL(URL url) throws IOException {
|
private JSONArray getJsonArrayFromURL(URL url) throws IOException {
|
||||||
// Wait 2 seconds before the next request
|
// Wait 2 seconds before the next request
|
||||||
long timeDiff = System.currentTimeMillis() - lastRequestTime;
|
long timeDiff = System.currentTimeMillis() - lastRequestTime;
|
||||||
@@ -149,9 +155,30 @@ public class RedditRipper extends AlbumRipper {
|
|||||||
return jsonArray;
|
return jsonArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Turns child JSONObject's into usable URLs and hands them off for further processing
|
||||||
|
* Performs filtering checks based on the reddit.
|
||||||
|
* Only called from getAndParseAndReturnNext() while parsing the JSONArray returned from reddit's API
|
||||||
|
* @param child The child to process
|
||||||
|
*/
|
||||||
private void parseJsonChild(JSONObject child) {
|
private void parseJsonChild(JSONObject child) {
|
||||||
String kind = child.getString("kind");
|
String kind = child.getString("kind");
|
||||||
JSONObject data = child.getJSONObject("data");
|
JSONObject data = child.getJSONObject("data");
|
||||||
|
|
||||||
|
//Upvote filtering
|
||||||
|
if (Utils.getConfigBoolean("reddit.rip_by_upvote", false)){
|
||||||
|
int score = data.getInt("score");
|
||||||
|
int maxScore = Utils.getConfigInteger("reddit.max_upvotes", Integer.MAX_VALUE);
|
||||||
|
int minScore = Utils.getConfigInteger("reddit.min_upvotes", Integer.MIN_VALUE);
|
||||||
|
|
||||||
|
if (score > maxScore || score < minScore) {
|
||||||
|
|
||||||
|
String message = "Skipping post with score outside specified range of " + minScore + " to " + maxScore;
|
||||||
|
LOGGER.debug(message);
|
||||||
|
return; //Outside specified range, do not download
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (kind.equals("t1")) {
|
if (kind.equals("t1")) {
|
||||||
// Comment
|
// Comment
|
||||||
handleBody(data.getString("body"), data.getString("id"), "");
|
handleBody(data.getString("body"), data.getString("id"), "");
|
||||||
|
@@ -30,3 +30,17 @@ twitter.max_requests = 10
|
|||||||
clipboard.autorip = false
|
clipboard.autorip = false
|
||||||
|
|
||||||
download.save_order = true
|
download.save_order = true
|
||||||
|
|
||||||
|
## Reddit ripper configs
|
||||||
|
# Determines whether or not to filter reddit ripping by upvote
|
||||||
|
# Enables the reddit.min_upvotes and reddit.max_upvotes properties when true
|
||||||
|
reddit.rip_by_upvote = false
|
||||||
|
|
||||||
|
# Only rips file if the number of upvotes is equal to or greater than this value
|
||||||
|
# Requires reddit.rip_by_upvote = true
|
||||||
|
reddit.min_upvotes = 0
|
||||||
|
|
||||||
|
# Only rips files if the number of upvotes is less than this value
|
||||||
|
# Requires reddit.rip_by_upvote = true
|
||||||
|
reddit.max_upvotes = 10000
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user