2014-05-30 14:32:04 +02:00
|
|
|
package com.rarchives.ripme.ripper.rippers;
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.net.MalformedURLException;
|
|
|
|
import java.net.URL;
|
2014-06-25 04:05:54 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2014-05-30 14:32:04 +02:00
|
|
|
import java.util.regex.Matcher;
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2014-06-25 04:05:54 +02:00
|
|
|
import com.rarchives.ripme.ripper.AbstractJSONRipper;
|
2014-06-22 02:08:42 +02:00
|
|
|
import com.rarchives.ripme.utils.Http;
|
2014-05-30 14:32:04 +02:00
|
|
|
|
2014-06-25 04:05:54 +02:00
|
|
|
public class ImagestashRipper extends AbstractJSONRipper {
|
2014-05-30 14:32:04 +02:00
|
|
|
|
2014-06-25 04:05:54 +02:00
|
|
|
private int page = 1;
|
2014-05-30 14:32:04 +02:00
|
|
|
|
|
|
|
public ImagestashRipper(URL url) throws IOException {
|
|
|
|
super(url);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-25 04:05:54 +02:00
|
|
|
public String getHost() {
|
|
|
|
return "imagestash";
|
2014-05-30 14:32:04 +02:00
|
|
|
}
|
|
|
|
@Override
|
2014-06-25 04:05:54 +02:00
|
|
|
public String getDomain() {
|
|
|
|
return "imagestash.org";
|
2014-05-30 14:32:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getGID(URL url) throws MalformedURLException {
|
|
|
|
Pattern p = Pattern.compile("^.*imagestash.org/tag/([a-zA-Z0-9\\-_]+)$");
|
|
|
|
Matcher m = p.matcher(url.toExternalForm());
|
|
|
|
if (m.matches()) {
|
|
|
|
return m.group(1);
|
|
|
|
}
|
|
|
|
throw new MalformedURLException(
|
|
|
|
"Expected imagestash.org tag formats: "
|
|
|
|
+ "imagestash.org/tag/tagname"
|
|
|
|
+ " Got: " + url);
|
|
|
|
}
|
2014-06-25 04:05:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public JSONObject getFirstPage() throws IOException {
|
|
|
|
String baseURL = "https://imagestash.org/images?tags="
|
|
|
|
+ getGID(url)
|
|
|
|
+ "&page=" + page;
|
|
|
|
return Http.url(baseURL).getJSON();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JSONObject getNextPage(JSONObject json) throws IOException {
|
|
|
|
int count = json.getInt("count"),
|
|
|
|
offset = json.getInt("offset"),
|
|
|
|
total = json.getInt("total");
|
|
|
|
if (count + offset >= total || json.getJSONArray("images").length() == 0) {
|
|
|
|
throw new IOException("No more images");
|
|
|
|
}
|
|
|
|
sleep(1000);
|
|
|
|
page++;
|
|
|
|
return getFirstPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<String> getURLsFromJSON(JSONObject json) {
|
|
|
|
List<String> imageURLs = new ArrayList<String>();
|
|
|
|
JSONArray images = json.getJSONArray("images");
|
|
|
|
for (int i = 0; i < images.length(); i++) {
|
|
|
|
JSONObject image = images.getJSONObject(i);
|
|
|
|
String imageURL = image.getString("src");
|
|
|
|
if (imageURL.startsWith("/")) {
|
2015-03-30 10:41:40 +02:00
|
|
|
imageURL = "https://imagestash.org" + imageURL;
|
2014-06-25 04:05:54 +02:00
|
|
|
}
|
|
|
|
imageURLs.add(imageURL);
|
|
|
|
}
|
|
|
|
return imageURLs;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void downloadURL(URL url, int index) {
|
|
|
|
addURLToDownload(url, getPrefix(index));
|
|
|
|
}
|
2014-05-30 14:32:04 +02:00
|
|
|
}
|