1.0.46 - Auto-indexing images is now a config option

Files saved with auto-indexing are numbered 001_, 002_, etc
This can now be toggled off via a config switch.
Should close #44
This commit is contained in:
4pr0n 2014-05-26 00:31:58 -07:00
parent f86a4d5a3c
commit fbcb77aa70
23 changed files with 172 additions and 32 deletions

View File

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

View File

@ -12,6 +12,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class ButttoucherRipper extends AlbumRipper {
@ -59,7 +60,11 @@ public class ButttoucherRipper extends AlbumRipper {
String smallImage = thumb.attr("src");
String image = smallImage.replace("m.", ".");
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
}
waitForThreads();
}

View File

@ -14,6 +14,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class ChanRipper extends AlbumRipper {
@ -114,7 +115,11 @@ public class ChanRipper extends AlbumRipper {
continue;
}
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
attempted.add(image);
}
}

View File

@ -52,6 +52,7 @@ public class DeviantartRipper extends AlbumRipper {
int index = 0;
String nextURL = this.url.toExternalForm();
// Iterate over every page
while (nextURL != null) {
logger.info(" Retrieving " + nextURL);
@ -60,6 +61,7 @@ public class DeviantartRipper extends AlbumRipper {
.userAgent(USER_AGENT)
.get();
// Iterate over all thumbnails
for (Element thumb : doc.select("div.zones-container a.thumb")) {
if (isStopped()) {
break;
@ -68,6 +70,7 @@ public class DeviantartRipper extends AlbumRipper {
if (img.attr("transparent").equals("false")) {
continue; // a.thumbs to other albums are invisible
}
index++;
String fullSize = null;
@ -80,6 +83,7 @@ public class DeviantartRipper extends AlbumRipper {
continue;
}
}
try {
URL fullsizeURL = new URL(fullSize);
String imageId = fullSize.substring(fullSize.lastIndexOf('-') + 1);
@ -98,6 +102,8 @@ public class DeviantartRipper extends AlbumRipper {
logger.error("[!] Interrupted while waiting for page to load", e);
break;
}
// Find the next page
nextURL = null;
for (Element nextButton : doc.select("a.away")) {
if (nextButton.attr("href").contains("offset=" + index)) {
@ -111,6 +117,11 @@ public class DeviantartRipper extends AlbumRipper {
waitForThreads();
}
/**
* Convert alpha-numeric string into a corresponding number
* @param alpha String to convert
* @return Numeric representation of 'alpha'
*/
public static long alphaToLong(String alpha) {
long result = 0;
for (int i = 0; i < alpha.length(); i++) {
@ -119,6 +130,12 @@ public class DeviantartRipper extends AlbumRipper {
return result;
}
/**
* Convert character at index in a string 'text' to numeric form (base-36)
* @param text Text to retrieve the character from
* @param index Index of the desired character
* @return Number representing character at text[index]
*/
private static int charToInt(String text, int index) {
char c = text.charAt(text.length() - index - 1);
c = Character.toLowerCase(c);
@ -127,6 +144,13 @@ public class DeviantartRipper extends AlbumRipper {
return number;
}
/**
* Tries to get full size image from thumbnail URL
* @param thumb Thumbnail URL
* @param throwException Whether or not to throw exception when full size image isn't found
* @return Full-size image URL
* @throws Exception If it can't find the full-size URL
*/
public static String thumbToFull(String thumb, boolean throwException) throws Exception {
thumb = thumb.replace("http://th", "http://fc");
List<String> fields = new ArrayList<String>(Arrays.asList(thumb.split("/")));
@ -146,6 +170,14 @@ public class DeviantartRipper extends AlbumRipper {
return result.toString();
}
/**
* If largest resolution for image at 'thumb' is found, starts downloading
* and returns null.
* If it finds a larger resolution on another page, returns the image URL.
* @param thumb Thumbnail URL
* @param page Page the thumbnail is retrieved from
* @return Highest-resolution version of the image based on thumbnail URL and the page.
*/
public String smallToFull(String thumb, String page) {
try {
Response resp = Jsoup.connect(page)
@ -159,10 +191,14 @@ public class DeviantartRipper extends AlbumRipper {
throw new IOException("no download page found");
}
String fsimage = els.get(0).attr("href");
String imageId = fsimage.substring(fsimage.lastIndexOf('-') + 1);
imageId = imageId.substring(0, imageId.indexOf('.'));
long imageIdLong = alphaToLong(imageId);
addURLToDownload(new URL(fsimage), String.format("%010d_", imageIdLong), "", page, cookies);
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
String imageId = fsimage.substring(fsimage.lastIndexOf('-') + 1);
imageId = imageId.substring(0, imageId.indexOf('.'));
prefix = String.format("%010d_", alphaToLong(imageId));
}
addURLToDownload(new URL(fsimage), prefix, "", page, cookies);
return null;
} catch (IOException ioe) {
try {

View File

@ -14,6 +14,7 @@ import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Utils;
public class DrawcrowdRipper extends AlbumRipper {
@ -76,7 +77,11 @@ public class DrawcrowdRipper extends AlbumRipper {
.replaceAll("/medium/", "/large/")
.replaceAll("/small/", "/large/");
index++;
addURLToDownload(new URL(image), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
}
Elements loadMore = albumDoc.select("a#load-more");
if (loadMore.size() == 0) {

View File

@ -14,6 +14,7 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class EHentaiRipper extends AlbumRipper {
private static final String DOMAIN = "g.e-hentai.org", HOST = "e-hentai";
@ -98,12 +99,19 @@ public class EHentaiRipper extends AlbumRipper {
if (m.matches()) {
// Manually discover filename from URL
String savePath = this.workingDir + File.separator;
savePath += String.format("%03d_%s", index + 1, m.group(1));
if (Utils.getConfigBoolean("download.save_order", true)) {
savePath += String.format("%03d_", index + 1);
}
savePath += m.group(1);
addURLToDownload(new URL(imgsrc), new File(savePath));
}
else {
// Provide prefix and let the AbstractRipper "guess" the filename
addURLToDownload(new URL(imgsrc), String.format("%03d_", index + 1));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index + 1);
}
addURLToDownload(new URL(imgsrc), prefix);
}
String href = a.attr("href");

View File

@ -13,6 +13,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class EightmusesRipper extends AlbumRipper {
@ -53,10 +54,13 @@ public class EightmusesRipper extends AlbumRipper {
if (image.startsWith("//")) {
image = "http:" + image;
}
//image = image.replace(" ", "%20");
URL imageURL = new URL(image);
index += 1;
addURLToDownload(imageURL, String.format("%03d_", index));
URL imageURL = new URL(image);
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(imageURL, prefix);
}
waitForThreads();
}

View File

@ -246,7 +246,11 @@ public class FlickrRipper extends AlbumRipper {
return;
}
else {
String prefix = String.format("%03d_%s_", index, Utils.filesystemSafe(title));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
prefix += Utils.filesystemSafe(title);
synchronized (flickrThreadPool) {
addURLToDownload(new URL(fullsizeImages.get(0).attr("src")), prefix);
}

View File

@ -12,6 +12,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class ImagearnRipper extends AlbumRipper {
@ -67,7 +68,11 @@ public class ImagearnRipper extends AlbumRipper {
String image = thumb.attr("src");
image = image.replaceAll("thumbs[0-9]*\\.imagearn\\.com/", "img.imagearn.com/imags/");
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
}
waitForThreads();
}

View File

@ -13,6 +13,7 @@ import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Utils;
public class ImagefapRipper extends AlbumRipper {
@ -110,7 +111,11 @@ public class ImagefapRipper extends AlbumRipper {
"http://x.*.fap.to/images/thumb/",
"http://fap.to/images/full/");
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
}
String nextURL = null;
for (Element a : albumDoc.select("a.link3")) {

View File

@ -129,7 +129,10 @@ public class ImgurRipper extends AlbumRipper {
subdirFile.mkdirs();
}
index += 1;
saveAs += String.format("%03d_%s", index, imgurImage.getSaveAs());
if (Utils.getConfigBoolean("download.save_order", true)) {
saveAs += String.format("%03d_", index);
}
saveAs += imgurImage.getSaveAs();
addURLToDownload(imgurImage.url, new File(saveAs));
}
}
@ -279,7 +282,11 @@ public class ImgurRipper extends AlbumRipper {
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));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", imagesFound);
}
addURLToDownload(new URL(imageUrl), prefix);
}
if (imagesFound >= imagesTotal) {
break;

View File

@ -75,7 +75,10 @@ public class IrarchivesRipper extends AlbumRipper {
int albumIndex = 0;
for (ImgurImage image : album.images) {
albumIndex++;
String saveAs = String.format("%s-%03d_", post.getString("hexid"), albumIndex);
String saveAs = String.format("%s-", post.getString("hexid"));
if (Utils.getConfigBoolean("download.save_order", true)) {
saveAs += String.format("%03d_", albumIndex);
}
addURLToDownload(image.url, saveAs);
}
}

View File

@ -12,6 +12,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class KinkyshareRipper extends AlbumRipper {
@ -68,7 +69,11 @@ public class KinkyshareRipper extends AlbumRipper {
image = "http://kinkyshare.com" + image;
}
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
}
waitForThreads();
}

View File

@ -176,7 +176,11 @@ public class MinusRipper extends AlbumRipper {
String image = "http://i.minus.com/i"
+ item.getString("id")
+ extension;
addURLToDownload(new URL(image), String.format("%03d_", i + 1), subdir);
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", i + 1);
}
addURLToDownload(new URL(image), prefix, subdir);
}
}
}

View File

@ -18,6 +18,7 @@ import org.jsoup.nodes.Document;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Utils;
public class ModelmayhemRipper extends AlbumRipper {
@ -105,7 +106,11 @@ public class ModelmayhemRipper extends AlbumRipper {
logger.info("Got empty image for " + picture.toString(2));
continue;
}
addURLToDownload(new URL(bigImage), String.format("%03d_", i + 1));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", i + 1);
}
addURLToDownload(new URL(bigImage), prefix);
}
waitForThreads();
}

View File

@ -13,6 +13,7 @@ import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ripper.DownloadThreadPool;
import com.rarchives.ripme.utils.Utils;
public class MotherlessRipper extends AlbumRipper {
@ -121,7 +122,11 @@ public class MotherlessRipper extends AlbumRipper {
Matcher m = p.matcher(doc.outerHtml());
if (m.matches()) {
String file = m.group(1);
addURLToDownload(new URL(file), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(file), prefix);
} else {
logger.warn("[!] could not find '__fileurl' at " + url);
}

View File

@ -192,7 +192,11 @@ public class RedditRipper extends AlbumRipper {
addURLToDownload(urls.get(0), id + "-");
} else if (urls.size() > 1) {
for (int i = 0; i < urls.size(); i++) {
addURLToDownload(urls.get(i), id + String.format("-%03d-", i + 1));
String prefix = id + "-";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix += String.format("%03d-", i + 1);
}
addURLToDownload(urls.get(i), prefix);
}
}
}

View File

@ -13,6 +13,7 @@ import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class TeenplanetRipper extends AlbumRipper {
@ -82,7 +83,11 @@ public class TeenplanetRipper extends AlbumRipper {
"/thumbs/",
"/");
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
}
waitForThreads();
}

View File

@ -19,6 +19,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class VkRipper extends AlbumRipper {
@ -83,7 +84,11 @@ public class VkRipper extends AlbumRipper {
int vidid = jsonVideo.getInt(1);
String videoURL = com.rarchives.ripme.ripper.rippers.video.VkRipper.getVideoURLAtPage(
"http://vk.com/video" + oid + "_" + vidid);
addURLToDownload(new URL(videoURL), String.format("%03d_", i + 1));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", i + 1);
}
addURLToDownload(new URL(videoURL), prefix);
try {
Thread.sleep(500);
} catch (InterruptedException e) {

View File

@ -12,6 +12,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.utils.Utils;
public class XhamsterRipper extends AlbumRipper {
@ -52,7 +53,11 @@ public class XhamsterRipper extends AlbumRipper {
"_160\\.",
"_1000.");
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(image), prefix);
}
nextURL = null;
for (Element element : doc.select("a.last")) {

View File

@ -105,6 +105,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
private static JTextField configRetriesText;
private static JCheckBox configAutoupdateCheckbox;
private static JCheckBox configPlaySound;
private static JCheckBox configSaveOrderCheckbox;
private static TrayIcon trayIcon;
private static MenuItem trayMenuMain;
@ -168,6 +169,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
Utils.setConfigBoolean("clipboard.autorip", ClipboardUtils.getClipboardAutoRip());
Utils.setConfigBoolean("auto.update", configAutoupdateCheckbox.isSelected());
Utils.setConfigBoolean("play.sound", configPlaySound.isSelected());
Utils.setConfigBoolean("download.save_order", configSaveOrderCheckbox.isSelected());
saveHistory();
Utils.saveConfig();
}
@ -310,6 +312,9 @@ public class MainWindow implements Runnable, RipStatusHandler {
configPlaySound = new JCheckBox("Sound when rip completes", Utils.getConfigBoolean("play.sound", false));
configPlaySound.setHorizontalAlignment(JCheckBox.RIGHT);
configPlaySound.setHorizontalTextPosition(JCheckBox.LEFT);
configSaveOrderCheckbox = new JCheckBox("Save images in order", Utils.getConfigBoolean("download.save_order", true));
configSaveOrderCheckbox.setHorizontalAlignment(JCheckBox.RIGHT);
configSaveOrderCheckbox.setHorizontalTextPosition(JCheckBox.LEFT);
configSaveDirLabel = new JLabel();
try {
String workingDir = (Utils.shortenPath(Utils.getWorkingDirectory()));
@ -329,7 +334,8 @@ public class MainWindow implements Runnable, RipStatusHandler {
gbc.gridx = 1; configurationPanel.add(configRetriesText, gbc);
gbc.gridy = 5; gbc.gridx = 0; configurationPanel.add(configOverwriteCheckbox, gbc);
gbc.gridy = 6; gbc.gridx = 0; configurationPanel.add(configPlaySound, gbc);
gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
gbc.gridy = 7; gbc.gridx = 0; configurationPanel.add(configSaveOrderCheckbox, gbc);
gbc.gridy = 8; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc);
gbc.gridy = 0; pane.add(ripPanel, gbc);
@ -487,6 +493,12 @@ public class MainWindow implements Runnable, RipStatusHandler {
Utils.setConfigBoolean("file.overwrite", configOverwriteCheckbox.isSelected());
}
});
configSaveOrderCheckbox.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
Utils.setConfigBoolean("download.save_order", configSaveOrderCheckbox.isSelected());
}
});
}
private void setupTrayIcon() {
@ -647,6 +659,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
if (!logPanel.isVisible()) {
optionLog.doClick();
}
urlString = urlString.trim();
if (urlString.toLowerCase().startsWith("gonewild:")) {
urlString = "http://gonewild.com/user/" + urlString.substring(urlString.indexOf(':') + 1);
}
@ -823,7 +836,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
}
public static void ripAlbumStatic(String url) {
ripTextfield.setText(url);
ripTextfield.setText(url.trim());
ripButton.doClick();
}
}

View File

@ -21,7 +21,7 @@ import com.rarchives.ripme.utils.Utils;
public class UpdateUtils {
private static final Logger logger = Logger.getLogger(UpdateUtils.class);
private static final String DEFAULT_VERSION = "1.0.45";
private static final String DEFAULT_VERSION = "1.0.46";
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";

View File

@ -22,3 +22,5 @@ gw.api = gonewild
twitter.max_requests = 10
clipboard.autorip = false
download.save_order = true