From add3c043b283f13ad04c459e6579e2322004e041 Mon Sep 17 00:00:00 2001 From: 4pr0n Date: Sat, 7 Jun 2014 19:54:36 -0700 Subject: [PATCH] 1.0.59 - Detect when an album can be ripped instantly #60 --- pom.xml | 2 +- .../ripme/ripper/AbstractRipper.java | 18 +++++---- .../com/rarchives/ripme/ui/MainWindow.java | 37 +++++++++++++++++++ .../com/rarchives/ripme/ui/UpdateUtils.java | 2 +- 4 files changed, 50 insertions(+), 9 deletions(-) diff --git a/pom.xml b/pom.xml index 0b5715a9..5cfc17b3 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.rarchives.ripme ripme jar - 1.0.58 + 1.0.59 ripme http://rip.rarchives.com diff --git a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java index 0027576e..dc7080d2 100644 --- a/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/AbstractRipper.java @@ -303,13 +303,17 @@ public abstract class AbstractRipper waitForThreads(); sendUpdate(STATUS.RIP_ERRORED, e.getMessage()); } finally { - if (this.workingDir.list().length == 0) { - // No files, delete the dir - logger.info("Deleting empty directory " + this.workingDir); - boolean deleteResult = this.workingDir.delete(); - if (!deleteResult) { - logger.error("Unable to delete empty directory " + this.workingDir); - } + cleanup(); + } + } + + public void cleanup() { + if (this.workingDir.list().length == 0) { + // No files, delete the dir + logger.info("Deleting empty directory " + this.workingDir); + boolean deleteResult = this.workingDir.delete(); + if (!deleteResult) { + logger.error("Unable to delete empty directory " + this.workingDir); } } } diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 77c792d0..1f51f1ac 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -49,6 +49,8 @@ import javax.swing.ListSelectionModel; import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.border.EmptyBorder; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.text.BadLocationException; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; @@ -357,6 +359,41 @@ public class MainWindow implements Runnable, RipStatusHandler { private void setupHandlers() { ripButton.addActionListener(new RipButtonHandler()); ripTextfield.addActionListener(new RipButtonHandler()); + ripTextfield.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void removeUpdate(DocumentEvent e) { + update(); + } + @Override + public void insertUpdate(DocumentEvent e) { + update(); + } + @Override + public void changedUpdate(DocumentEvent e) { + update(); + } + private void update() { + if (!ripTextfield.isEnabled()) { + return; + } + try { + String urlText = ripTextfield.getText(); + if (!urlText.startsWith("http:")) { + urlText = "http://" + urlText; + } + URL url = new URL(urlText); + AbstractRipper ripper = AbstractRipper.getRipper(url); + statusWithColor(ripper.getHost() + " album detected", Color.GREEN); + File dir = ripper.getWorkingDir(); + if (dir.list().length == 1) { + new File(dir.getAbsolutePath() + File.separator + "log.txt").delete(); + } + ripper.cleanup(); + } catch (Exception e) { + statusWithColor("Can't rip this URL", Color.RED); + } + } + }); stopButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent event) { diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 8fa32ded..1b402d84 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -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.58"; + private static final String DEFAULT_VERSION = "1.0.59"; 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";