Option to open directory after rip finishes.

This UI is so friggin ugly
This commit is contained in:
4pr0n 2014-03-01 18:08:16 -08:00
parent af9f5ce272
commit 24d53e52b1
5 changed files with 56 additions and 14 deletions

View File

@ -33,6 +33,7 @@ public abstract class AbstractRipper
protected Map<URL, File> itemsPending = new HashMap<URL, File>();
protected Map<URL, File> itemsCompleted = new HashMap<URL, File>();
protected Map<URL, String> itemsErrored = new HashMap<URL, String>();
protected boolean completed = true;
public abstract void rip() throws IOException;
public abstract String getHost();
@ -92,9 +93,11 @@ public abstract class AbstractRipper
* Path of the local file to save the content to.
*/
public void addURLToDownload(URL url, File saveAs) {
if (itemsPending.containsKey(url) || itemsCompleted.containsKey(url)) {
if (itemsPending.containsKey(url)
|| itemsCompleted.containsKey(url)
|| itemsErrored.containsKey(url)) {
// Item is already downloaded/downloading, skip it.
logger.info("Skipping duplicate URL: " + url);
logger.info("Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs));
return;
}
itemsPending.put(url, saveAs);
@ -129,6 +132,11 @@ public abstract class AbstractRipper
}
addURLToDownload(url, saveFileAs);
}
protected void waitForThreads() {
completed = false;
threadPool.waitForThreads();
}
public void retrievingSource(URL url) {
RipStatusMessage msg = new RipStatusMessage(STATUS.LOADING_RESOURCE, url);
@ -163,9 +171,11 @@ public abstract class AbstractRipper
}
private void checkIfComplete() {
if (itemsPending.size() == 0) {
System.err.println("Pending: " + itemsPending.size() + ", Completed: " + itemsCompleted.size() + ", Errored: " + itemsErrored.size());
if (!completed && itemsPending.size() == 0) {
completed = true;
logger.info("Rip completed!");
observer.update(this, new RipStatusMessage(STATUS.RIP_COMPLETE, workingDir));
observer.update(this, new RipStatusMessage(STATUS.RIP_COMPLETE, new File(Utils.removeCWD(workingDir))));
observer.notifyAll();
}
}

View File

@ -69,7 +69,7 @@ public class ImagearnRipper extends AbstractRipper {
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
}
threadPool.waitForThreads();
waitForThreads();
}
@Override

View File

@ -73,7 +73,7 @@ public class ImagefapRipper extends AbstractRipper {
index += 1;
addURLToDownload(new URL(image), String.format("%03d_", index));
}
threadPool.waitForThreads();
waitForThreads();
}
public boolean canRip(URL url) {

View File

@ -82,7 +82,7 @@ public class ImgurRipper extends AbstractRipper {
ripUserAccount(url);
break;
}
threadPool.waitForThreads();
waitForThreads();
}
private void ripAlbum(URL url) throws IOException {

View File

@ -1,6 +1,7 @@
package com.rarchives.ripme.ui;
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
@ -11,20 +12,30 @@ import java.util.Observer;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import org.apache.log4j.Logger;
import com.rarchives.ripme.ripper.AbstractRipper;
import com.rarchives.ripme.utils.Utils;
public class MainWindow implements Runnable {
private static final Logger logger = Logger.getLogger(MainWindow.class);
private static final String WINDOW_TITLE = "RipMe";
private static JFrame mainFrame;
private static JPanel ripPanel;
private static JTextField ripTextfield;
private static JButton ripButton;
private static JLabel ripStatus;
private static JPanel statusPanel;
private static JLabel statusLabel;
private static JButton statusButton;
public MainWindow() {
createUI();
@ -35,12 +46,20 @@ public class MainWindow implements Runnable {
mainFrame = new JFrame(WINDOW_TITLE);
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ripPanel = new JPanel();
ripTextfield = new JTextField("", 20);
ripButton = new JButton("rip");
ripStatus = new JLabel("inactive");
mainFrame.getContentPane().add(ripTextfield, BorderLayout.WEST);
mainFrame.getContentPane().add(ripButton, BorderLayout.EAST);
mainFrame.getContentPane().add(ripStatus, BorderLayout.SOUTH);
ripPanel.add(ripTextfield, BorderLayout.WEST);
ripPanel.add(ripButton, BorderLayout.EAST);
mainFrame.getContentPane().add(ripPanel, BorderLayout.NORTH);
statusPanel = new JPanel();
statusLabel = new JLabel("inactive", SwingConstants.LEADING);
statusButton = new JButton("open dir");
statusButton.setVisible(false);
statusPanel.add(statusLabel, BorderLayout.WEST);
statusPanel.add(statusButton, BorderLayout.EAST);
mainFrame.getContentPane().add(statusPanel, BorderLayout.SOUTH);
}
private void setupHandlers() {
@ -54,11 +73,12 @@ public class MainWindow implements Runnable {
}
public static void status(String text) {
ripStatus.setText(text);
statusLabel.setText(text);
}
class RipButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent event) {
statusButton.setVisible(false);
try {
URL url = new URL(ripTextfield.getText());
AbstractRipper ripper = AbstractRipper.getRipper(url);
@ -85,7 +105,19 @@ public class MainWindow implements Runnable {
break;
case RIP_COMPLETE:
File f = (File) msg.getObject();
status("RIP COMPLETE: " + f);
statusButton.setActionCommand(f.toString());
statusButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
try {
Desktop.getDesktop().open(new File(event.getActionCommand()));
} catch (Exception e) {
logger.error(e);
}
}
});
statusButton.setVisible(true);
status("Finished: " + Utils.removeCWD(f));
}
}
}