made it like...work
parent
20fce00161
commit
be6269fcda
|
|
@ -3,6 +3,16 @@ package imgurlibrary;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this is the root class for any and all imgur downloading requests.
|
||||||
|
* not super because some wrappers exist. anyways, it tells requests
|
||||||
|
* where to download and where to trigger event for new images being downloaded.
|
||||||
|
* as well, it stores my imgur API credentials so one can access the API.
|
||||||
|
*
|
||||||
|
* @author mgosselin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public abstract class ImgurRequest implements Runnable {
|
public abstract class ImgurRequest implements Runnable {
|
||||||
public static String LOCAL_ROOT = System.getenv("USERPROFILE") + "\\Desktop\\imgur";
|
public static String LOCAL_ROOT = System.getenv("USERPROFILE") + "\\Desktop\\imgur";
|
||||||
protected final String AuthorizationToken = "76535d44f1f94da";
|
protected final String AuthorizationToken = "76535d44f1f94da";
|
||||||
|
|
@ -10,6 +20,7 @@ public abstract class ImgurRequest implements Runnable {
|
||||||
protected boolean busy;
|
protected boolean busy;
|
||||||
private final ImageListener listener;
|
private final ImageListener listener;
|
||||||
private volatile int downloaded, discovered, failed;
|
private volatile int downloaded, discovered, failed;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (!new File(LOCAL_ROOT).exists()) {
|
if (!new File(LOCAL_ROOT).exists()) {
|
||||||
new File(LOCAL_ROOT).mkdirs();
|
new File(LOCAL_ROOT).mkdirs();
|
||||||
|
|
@ -59,11 +70,11 @@ public abstract class ImgurRequest implements Runnable {
|
||||||
return ((double)(downloaded + failed) / (discovered == 0 ? 1 : discovered));
|
return ((double)(downloaded + failed) / (discovered == 0 ? 1 : discovered));
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract double getScanProgress(); // idunno how YOU want to
|
|
||||||
// calculate this but uh
|
public abstract double getScanProgress();
|
||||||
|
|
||||||
public final boolean isBusy() { // i aint doing it for you so....
|
public final boolean isBusy() {
|
||||||
return busy; // ~All interfaces ever
|
return busy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void run();
|
public abstract void run();
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,14 @@ import org.apache.commons.io.IOUtils;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this class is a class that will simply take a subreddit, and a number of pages
|
||||||
|
* and download them to the path set out in the parents class, imgur request.
|
||||||
|
*
|
||||||
|
* @author mgosselin
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
public class SubredditRequest extends ImgurRequest {
|
public class SubredditRequest extends ImgurRequest {
|
||||||
private final int pages;
|
private final int pages;
|
||||||
private int pagesScanned;
|
private int pagesScanned;
|
||||||
|
|
@ -56,7 +64,7 @@ public class SubredditRequest extends ImgurRequest {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
String path = "https://api.imgur.com/3/gallery/r/emmawatson/time/0.json";
|
String path = "https://api.imgur.com/3/gallery/r/" + subreddit + "/time/" + page + ".json";
|
||||||
|
|
||||||
HttpURLConnection connection = (HttpURLConnection) ((new URL(path)).openConnection());
|
HttpURLConnection connection = (HttpURLConnection) ((new URL(path)).openConnection());
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue