Skip to content

Commit

Permalink
1.0.52 - Imgbox ripper, notifications are optional
Browse files Browse the repository at this point in the history
Both for #8

Popup notifications are now a config-option, defaults to false
  • Loading branch information
4pr0n committed Jun 2, 2014
1 parent f79f0cd commit 13d13b2
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>com.rarchives.ripme</groupId>
<artifactId>ripme</artifactId>
<packaging>jar</packaging>
<version>1.0.51</version>
<version>1.0.52</version>
<name>ripme</name>
<url>http://rip.rarchives.com</url>
<properties>
Expand Down
80 changes: 80 additions & 0 deletions src/main/java/com/rarchives/ripme/ripper/rippers/ImgboxRipper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.rarchives.ripme.ripper.rippers;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
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 ImgboxRipper extends AlbumRipper {

private static final String DOMAIN = "imgbox.com",
HOST = "imgbox";
private static final Logger logger = Logger.getLogger(ImgboxRipper.class);

public ImgboxRipper(URL url) throws IOException {
super(url);
}

@Override
public boolean canRip(URL url) {
return url.getHost().endsWith(DOMAIN);
}

@Override
public URL sanitizeURL(URL url) throws MalformedURLException {
return url;
}

@Override
public void rip() throws IOException {
logger.info(" Retrieving " + this.url);
sendUpdate(STATUS.LOADING_RESOURCE, url.toExternalForm());
Document doc = Jsoup.connect(this.url.toExternalForm())
.userAgent(USER_AGENT)
.get();
Elements images = doc.select("div.boxed-content > a > img");
if (images.size() == 0) {
logger.error("No images found at " + this.url);
throw new IOException("No images found at " + this.url);
}
int index = 0;
for (Element image : images) {
index++;
String imageUrl = image.attr("src").replace("s.imgbox.com", "i.imgbox.com");
String prefix = "";
if (Utils.getConfigBoolean("download.save_order", true)) {
prefix = String.format("%03d_", index);
}
addURLToDownload(new URL(imageUrl), prefix);
}

waitForThreads();
}

@Override
public String getHost() {
return HOST;
}

@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://[wm.]*imgbox\\.com/g/([a-zA-Z0-9]+).*$");
Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) {
return m.group(1);
}
throw new MalformedURLException("Expected imgbox.com URL format: " +
"imgbox.com/g/albumid - got " + url + "instead");
}
}
11 changes: 9 additions & 2 deletions src/main/java/com/rarchives/ripme/ui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
private static JCheckBox configAutoupdateCheckbox;
private static JCheckBox configPlaySound;
private static JCheckBox configSaveOrderCheckbox;
private static JCheckBox configShowPopup;

private static TrayIcon trayIcon;
private static MenuItem trayMenuMain;
Expand Down Expand Up @@ -170,6 +171,7 @@ public void shutdownCleanup() {
Utils.setConfigBoolean("auto.update", configAutoupdateCheckbox.isSelected());
Utils.setConfigBoolean("play.sound", configPlaySound.isSelected());
Utils.setConfigBoolean("download.save_order", configSaveOrderCheckbox.isSelected());
Utils.setConfigBoolean("download.show_popup", configShowPopup.isSelected());
saveHistory();
Utils.saveConfig();
}
Expand Down Expand Up @@ -316,6 +318,9 @@ private void createUI(Container pane) {
configSaveOrderCheckbox = new JCheckBox("Save images in order", Utils.getConfigBoolean("download.save_order", true));
configSaveOrderCheckbox.setHorizontalAlignment(JCheckBox.RIGHT);
configSaveOrderCheckbox.setHorizontalTextPosition(JCheckBox.LEFT);
configShowPopup = new JCheckBox("Notification when rip starts", Utils.getConfigBoolean("download.show_popup", false));
configShowPopup.setHorizontalAlignment(JCheckBox.RIGHT);
configShowPopup.setHorizontalTextPosition(JCheckBox.LEFT);
configSaveDirLabel = new JLabel();
try {
String workingDir = (Utils.shortenPath(Utils.getWorkingDirectory()));
Expand All @@ -336,7 +341,8 @@ private void createUI(Container pane) {
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(configSaveOrderCheckbox, gbc);
gbc.gridy = 8; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
gbc.gridy = 8; gbc.gridx = 0; configurationPanel.add(configShowPopup, gbc);
gbc.gridy = 9; gbc.gridx = 0; configurationPanel.add(configSaveDirLabel, gbc);
gbc.gridx = 1; configurationPanel.add(configSaveDirButton, gbc);

gbc.gridy = 0; pane.add(ripPanel, gbc);
Expand Down Expand Up @@ -699,7 +705,8 @@ private Thread ripAlbum(String urlString) {
ripper.setObserver((RipStatusHandler) this);
Thread t = new Thread(ripper);
t.start();
if (!mainFrame.isVisible() || !mainFrame.isActive()) {
if (configShowPopup.isSelected() &&
(!mainFrame.isVisible() || !mainFrame.isActive())) {
mainFrame.toFront();
mainFrame.setAlwaysOnTop(true);
trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/rarchives/ripme/ui/UpdateUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public class UpdateUtils {

private static final Logger logger = Logger.getLogger(UpdateUtils.class);
private static final String DEFAULT_VERSION = "1.0.51";
private static final String DEFAULT_VERSION = "1.0.52";
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";
Expand Down

0 comments on commit 13d13b2

Please sign in to comment.