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:
parent
e65f118d53
commit
09162522f0
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
<groupId>com.rarchives.ripme</groupId>
|
<groupId>com.rarchives.ripme</groupId>
|
||||||
<artifactId>ripme</artifactId>
|
<artifactId>ripme</artifactId>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<version>1.0.20</version>
|
<version>1.0.21</version>
|
||||||
<name>ripme</name>
|
<name>ripme</name>
|
||||||
<url>http://rip.rarchives.com</url>
|
<url>http://rip.rarchives.com</url>
|
||||||
<properties>
|
<properties>
|
||||||
|
@ -34,6 +34,7 @@ public class ImgurRipper extends AlbumRipper {
|
|||||||
ALBUM,
|
ALBUM,
|
||||||
USER,
|
USER,
|
||||||
USER_ALBUM,
|
USER_ALBUM,
|
||||||
|
USER_IMAGES,
|
||||||
SERIES_OF_IMAGES,
|
SERIES_OF_IMAGES,
|
||||||
SUBREDDIT
|
SUBREDDIT
|
||||||
};
|
};
|
||||||
@ -86,6 +87,9 @@ public class ImgurRipper extends AlbumRipper {
|
|||||||
case SUBREDDIT:
|
case SUBREDDIT:
|
||||||
ripSubreddit(url);
|
ripSubreddit(url);
|
||||||
break;
|
break;
|
||||||
|
case USER_IMAGES:
|
||||||
|
ripUserImages(url);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
waitForThreads();
|
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 {
|
private void ripSubreddit(URL url) throws IOException {
|
||||||
int page = 0;
|
int page = 0;
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -304,13 +346,20 @@ public class ImgurRipper extends AlbumRipper {
|
|||||||
albumType = ALBUM_TYPE.USER;
|
albumType = ALBUM_TYPE.USER;
|
||||||
return gid;
|
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());
|
m = p.matcher(url.toExternalForm());
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
// Imgur account album
|
// Imgur account album
|
||||||
albumType = ALBUM_TYPE.USER_ALBUM;
|
albumType = ALBUM_TYPE.USER_ALBUM;
|
||||||
return m.group();
|
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)?/?$");
|
p = Pattern.compile("^https?://(www\\.)?imgur\\.com/r/([a-zA-Z0-9\\-_]{3,})(/top|/new)?(/all|/year|/month|/week)?/?$");
|
||||||
m = p.matcher(url.toExternalForm());
|
m = p.matcher(url.toExternalForm());
|
||||||
if (m.matches()) {
|
if (m.matches()) {
|
||||||
@ -352,6 +401,9 @@ public class ImgurRipper extends AlbumRipper {
|
|||||||
this.url = url;
|
this.url = url;
|
||||||
String tempUrl = url.toExternalForm();
|
String tempUrl = url.toExternalForm();
|
||||||
this.extension = tempUrl.substring(tempUrl.lastIndexOf('.'));
|
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) {
|
public ImgurImage(URL url, String title) {
|
||||||
this(url);
|
this(url);
|
||||||
@ -364,6 +416,9 @@ public class ImgurRipper extends AlbumRipper {
|
|||||||
public String getSaveAs() {
|
public String getSaveAs() {
|
||||||
String saveAs = this.title;
|
String saveAs = this.title;
|
||||||
String u = url.toExternalForm();
|
String u = url.toExternalForm();
|
||||||
|
if (u.contains("?")) {
|
||||||
|
u = u.substring(0, u.indexOf("?"));
|
||||||
|
}
|
||||||
String imgId = u.substring(u.lastIndexOf('/') + 1, u.lastIndexOf('.'));
|
String imgId = u.substring(u.lastIndexOf('/') + 1, u.lastIndexOf('.'));
|
||||||
if (saveAs == null || saveAs.equals("")) {
|
if (saveAs == null || saveAs.equals("")) {
|
||||||
saveAs = imgId;
|
saveAs = imgId;
|
||||||
|
@ -19,7 +19,7 @@ import org.jsoup.nodes.Document;
|
|||||||
public class UpdateUtils {
|
public class UpdateUtils {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(UpdateUtils.class);
|
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 updateJsonURL = "http://rarchives.com/ripme.json";
|
||||||
private static final String updateJarURL = "http://rarchives.com/ripme.jar";
|
private static final String updateJarURL = "http://rarchives.com/ripme.jar";
|
||||||
private static final String mainFileName = "ripme.jar";
|
private static final String mainFileName = "ripme.jar";
|
||||||
|
Loading…
Reference in New Issue
Block a user