Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/main/java/com/rarchives/ripme/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import java.util.List;

import javax.swing.SwingUtilities;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
Expand Down Expand Up @@ -167,6 +169,20 @@ public static void handleArguments(String[] args) {

if (cl.hasOption('u')) {
String url = cl.getOptionValue('u').trim();

// the -A option is limited to just reddit.com/r urls for the time being
// if the -A does not match a reddit.com/r regex, then ripme should fail out.
if(cl.hasOption('A')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good. I like using an option for this instead of a URL hack.

Pattern p = Pattern.compile("^https?://(www\\.)?reddit.com/r/.*$");
Matcher m = p.matcher(url);

if (!m.matches()) {
logger.error("[!] Supplied URL does not meet -A requirements");
System.exit(-1);
}
Utils.setConfigBoolean("download.rip_authors", true);
}

ripURL(url, cl.hasOption("n"));
}
}
Expand Down Expand Up @@ -207,6 +223,9 @@ public static Options getOptions() {
opts.addOption("l", "ripsdirectory", true, "Rips Directory (Default: ./rips)");
opts.addOption("n", "no-prop-file", false, "Do not create properties file.");
opts.addOption("f", "urls-file", true, "Rip URLs from a file.");

opts.addOption("A", "rip-authors", false, "REDDIT ONLY. Will rip all authors from a given subreddit.");

return opts;
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/java/com/rarchives/ripme/ripper/rippers/RedditRipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
import com.rarchives.ripme.utils.RipUtils;
import com.rarchives.ripme.utils.Utils;

import com.rarchives.ripme.ripper.AbstractRipper;


public class RedditRipper extends AlbumRipper {

public RedditRipper(URL url) throws IOException {
Expand All @@ -34,6 +37,7 @@ public RedditRipper(URL url) throws IOException {
//private static final String USER_AGENT = "ripme by /u/4_pr0n github.com/4pr0n/ripme";

private long lastRequestTime = 0;
private Boolean rip_authors = Utils.getConfigBoolean("download.rip_authors", false);

@Override
public boolean canRip(URL url) {
Expand All @@ -59,6 +63,14 @@ private URL getJsonURL(URL url) throws MalformedURLException {

@Override
public void rip() throws IOException {

// once we begin the rip process, clear download.rip_authors
// the value is preserved for this session and will not
// persist when getAndParseAndReturnNext spawns additional
// AbstractRipper processes
Utils.setConfigBoolean("download.rip_authors", false);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this configBoolean also come from the rip.properties file? Maybe we should have options that don't coordinate with the rip.properties so we don't need to hack around it and clear it, even if the user wanted to specify it in the config to always be used.



URL jsonURL = getJsonURL(this.url);
while (true) {
jsonURL = getAndParseAndReturnNext(jsonURL);
Expand Down Expand Up @@ -86,6 +98,29 @@ private URL getAndParseAndReturnNext(URL url) throws IOException {
}
children = data.getJSONArray("children");
for (int j = 0; j < children.length(); j++) {


if(rip_authors) {
JSONObject child_data = children.getJSONObject(j).getJSONObject("data");
String author = child_data.getString("author");

logger.info("[OVERRIDE]: Ripping Author: " + author);

// spawn a new AbstractRipper for the authors page
try {
URL author_url = new URL("http://reddit.com/user/" + author);

AbstractRipper ripper = AbstractRipper.getRipper(author_url);
ripper.setup();
ripper.rip();
} catch(Exception e) {
logger.error("[!] AbstractRipper failed. Cannot continue.");
System.exit(-1);
}

continue;
}

parseJsonChild(children.getJSONObject(j));
}
if (data.has("after") && !data.isNull("after")) {
Expand Down