1.0.21 - Allow ripping images from imgur user account, closes #20

Urls like http://<imguracct>.imgur.com/all will rip images.
Previously only supported user account albums.
This commit is contained in:
4pr0n 2014-04-20 13:21:52 -07:00
parent e65f118d53
commit 09162522f0
3 changed files with 58 additions and 3 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.rarchives.ripme</groupId>
<artifactId>ripme</artifactId>
<packaging>jar</packaging>
<version>1.0.20</version>
<version>1.0.21</version>
<name>ripme</name>
<url>http://rip.rarchives.com</url>
<properties>

View File

@ -34,6 +34,7 @@ public class ImgurRipper extends AlbumRipper {
ALBUM,
USER,
USER_ALBUM,
USER_IMAGES,
SERIES_OF_IMAGES,
SUBREDDIT
};
@ -86,6 +87,9 @@ public class ImgurRipper extends AlbumRipper {
case SUBREDDIT:
ripSubreddit(url);
break;
case USER_IMAGES:
ripUserImages(url);
break;
}
waitForThreads();
}
@ -239,6 +243,44 @@ public class ImgurRipper extends AlbumRipper {
}
}
private void ripUserImages(URL url) throws IOException {
int page = 0; int imagesFound = 0; int imagesTotal = 0;
String jsonUrl = url.toExternalForm().replace("/all", "/ajax/images");
if (jsonUrl.contains("#")) {
jsonUrl = jsonUrl.substring(0, jsonUrl.indexOf("#"));
}
while (true) {
try {
page++;
String jsonUrlWithParams = jsonUrl + "?sort=0&order=1&album=0&page=" + page + "&perPage=60";
String jsonString = Jsoup.connect(jsonUrlWithParams)
.ignoreContentType(true)
.execute()
.body();
JSONObject json = new JSONObject(jsonString);
JSONObject jsonData = json.getJSONObject("data");
if (jsonData.has("count")) {
imagesTotal = jsonData.getInt("count");
}
JSONArray images = jsonData.getJSONArray("images");
for (int i = 0; i < images.length(); i++) {
imagesFound++;
JSONObject image = images.getJSONObject(i);
String imageUrl = "http://i.imgur.com/" + image.getString("hash") + image.getString("ext");
addURLToDownload(new URL(imageUrl), String.format("%03d_", imagesFound));
}
if (imagesFound >= imagesTotal) {
break;
}
Thread.sleep(1000);
} catch (Exception e) {
logger.error("Error while ripping user images: " + e.getMessage(), e);
break;
}
}
}
private void ripSubreddit(URL url) throws IOException {
int page = 0;
while (true) {
@ -304,13 +346,20 @@ public class ImgurRipper extends AlbumRipper {
albumType = ALBUM_TYPE.USER;
return gid;
}
p = Pattern.compile("^https?://([a-zA-Z0-9\\-]{3,})\\.imgur\\.com/([a-zA-Z0-9])?$");
p = Pattern.compile("^https?://([a-zA-Z0-9\\-]{3,})\\.imgur\\.com/?$");
m = p.matcher(url.toExternalForm());
if (m.matches()) {
// Imgur account album
albumType = ALBUM_TYPE.USER_ALBUM;
return m.group();
}
p = Pattern.compile("^https?://([a-zA-Z0-9\\-]{3,})\\.imgur\\.com/all.*$");
m = p.matcher(url.toExternalForm());
if (m.matches()) {
// Imgur account images
albumType = ALBUM_TYPE.USER_IMAGES;
return m.group(1) + "_images";
}
p = Pattern.compile("^https?://(www\\.)?imgur\\.com/r/([a-zA-Z0-9\\-_]{3,})(/top|/new)?(/all|/year|/month|/week)?/?$");
m = p.matcher(url.toExternalForm());
if (m.matches()) {
@ -352,6 +401,9 @@ public class ImgurRipper extends AlbumRipper {
this.url = url;
String tempUrl = url.toExternalForm();
this.extension = tempUrl.substring(tempUrl.lastIndexOf('.'));
if (this.extension.contains("?")) {
this.extension = this.extension.substring(0, this.extension.indexOf("?"));
}
}
public ImgurImage(URL url, String title) {
this(url);
@ -364,6 +416,9 @@ public class ImgurRipper extends AlbumRipper {
public String getSaveAs() {
String saveAs = this.title;
String u = url.toExternalForm();
if (u.contains("?")) {
u = u.substring(0, u.indexOf("?"));
}
String imgId = u.substring(u.lastIndexOf('/') + 1, u.lastIndexOf('.'));
if (saveAs == null || saveAs.equals("")) {
saveAs = imgId;

View File

@ -19,7 +19,7 @@ import org.jsoup.nodes.Document;
public class UpdateUtils {
private static final Logger logger = Logger.getLogger(UpdateUtils.class);
private static final String DEFAULT_VERSION = "1.0.20";
private static final String DEFAULT_VERSION = "1.0.21";
private static final String updateJsonURL = "http://rarchives.com/ripme.json";
private static final String updateJarURL = "http://rarchives.com/ripme.jar";
private static final String mainFileName = "ripme.jar";