Option to open directory after rip finishes.
This UI is so friggin ugly
This commit is contained in:
parent
af9f5ce272
commit
24d53e52b1
@ -33,6 +33,7 @@ public abstract class AbstractRipper
|
|||||||
protected Map<URL, File> itemsPending = new HashMap<URL, File>();
|
protected Map<URL, File> itemsPending = new HashMap<URL, File>();
|
||||||
protected Map<URL, File> itemsCompleted = new HashMap<URL, File>();
|
protected Map<URL, File> itemsCompleted = new HashMap<URL, File>();
|
||||||
protected Map<URL, String> itemsErrored = new HashMap<URL, String>();
|
protected Map<URL, String> itemsErrored = new HashMap<URL, String>();
|
||||||
|
protected boolean completed = true;
|
||||||
|
|
||||||
public abstract void rip() throws IOException;
|
public abstract void rip() throws IOException;
|
||||||
public abstract String getHost();
|
public abstract String getHost();
|
||||||
@ -92,9 +93,11 @@ public abstract class AbstractRipper
|
|||||||
* Path of the local file to save the content to.
|
* Path of the local file to save the content to.
|
||||||
*/
|
*/
|
||||||
public void addURLToDownload(URL url, File saveAs) {
|
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.
|
// Item is already downloaded/downloading, skip it.
|
||||||
logger.info("Skipping duplicate URL: " + url);
|
logger.info("Skipping " + url + " -- already attempted: " + Utils.removeCWD(saveAs));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
itemsPending.put(url, saveAs);
|
itemsPending.put(url, saveAs);
|
||||||
@ -129,6 +132,11 @@ public abstract class AbstractRipper
|
|||||||
}
|
}
|
||||||
addURLToDownload(url, saveFileAs);
|
addURLToDownload(url, saveFileAs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void waitForThreads() {
|
||||||
|
completed = false;
|
||||||
|
threadPool.waitForThreads();
|
||||||
|
}
|
||||||
|
|
||||||
public void retrievingSource(URL url) {
|
public void retrievingSource(URL url) {
|
||||||
RipStatusMessage msg = new RipStatusMessage(STATUS.LOADING_RESOURCE, url);
|
RipStatusMessage msg = new RipStatusMessage(STATUS.LOADING_RESOURCE, url);
|
||||||
@ -163,9 +171,11 @@ public abstract class AbstractRipper
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkIfComplete() {
|
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!");
|
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();
|
observer.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,7 @@ public class ImagearnRipper extends AbstractRipper {
|
|||||||
index += 1;
|
index += 1;
|
||||||
addURLToDownload(new URL(image), String.format("%03d_", index));
|
addURLToDownload(new URL(image), String.format("%03d_", index));
|
||||||
}
|
}
|
||||||
threadPool.waitForThreads();
|
waitForThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,7 +73,7 @@ public class ImagefapRipper extends AbstractRipper {
|
|||||||
index += 1;
|
index += 1;
|
||||||
addURLToDownload(new URL(image), String.format("%03d_", index));
|
addURLToDownload(new URL(image), String.format("%03d_", index));
|
||||||
}
|
}
|
||||||
threadPool.waitForThreads();
|
waitForThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canRip(URL url) {
|
public boolean canRip(URL url) {
|
||||||
|
@ -82,7 +82,7 @@ public class ImgurRipper extends AbstractRipper {
|
|||||||
ripUserAccount(url);
|
ripUserAccount(url);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
threadPool.waitForThreads();
|
waitForThreads();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ripAlbum(URL url) throws IOException {
|
private void ripAlbum(URL url) throws IOException {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package com.rarchives.ripme.ui;
|
package com.rarchives.ripme.ui;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Desktop;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -11,20 +12,30 @@ import java.util.Observer;
|
|||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
import javax.swing.SwingConstants;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import com.rarchives.ripme.ripper.AbstractRipper;
|
import com.rarchives.ripme.ripper.AbstractRipper;
|
||||||
|
import com.rarchives.ripme.utils.Utils;
|
||||||
|
|
||||||
|
|
||||||
public class MainWindow implements Runnable {
|
public class MainWindow implements Runnable {
|
||||||
|
|
||||||
|
private static final Logger logger = Logger.getLogger(MainWindow.class);
|
||||||
|
|
||||||
private static final String WINDOW_TITLE = "RipMe";
|
private static final String WINDOW_TITLE = "RipMe";
|
||||||
|
|
||||||
private static JFrame mainFrame;
|
private static JFrame mainFrame;
|
||||||
|
private static JPanel ripPanel;
|
||||||
private static JTextField ripTextfield;
|
private static JTextField ripTextfield;
|
||||||
private static JButton ripButton;
|
private static JButton ripButton;
|
||||||
|
|
||||||
private static JLabel ripStatus;
|
private static JPanel statusPanel;
|
||||||
|
private static JLabel statusLabel;
|
||||||
|
private static JButton statusButton;
|
||||||
|
|
||||||
public MainWindow() {
|
public MainWindow() {
|
||||||
createUI();
|
createUI();
|
||||||
@ -35,12 +46,20 @@ public class MainWindow implements Runnable {
|
|||||||
mainFrame = new JFrame(WINDOW_TITLE);
|
mainFrame = new JFrame(WINDOW_TITLE);
|
||||||
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
|
ripPanel = new JPanel();
|
||||||
ripTextfield = new JTextField("", 20);
|
ripTextfield = new JTextField("", 20);
|
||||||
ripButton = new JButton("rip");
|
ripButton = new JButton("rip");
|
||||||
ripStatus = new JLabel("inactive");
|
ripPanel.add(ripTextfield, BorderLayout.WEST);
|
||||||
mainFrame.getContentPane().add(ripTextfield, BorderLayout.WEST);
|
ripPanel.add(ripButton, BorderLayout.EAST);
|
||||||
mainFrame.getContentPane().add(ripButton, BorderLayout.EAST);
|
mainFrame.getContentPane().add(ripPanel, BorderLayout.NORTH);
|
||||||
mainFrame.getContentPane().add(ripStatus, BorderLayout.SOUTH);
|
|
||||||
|
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() {
|
private void setupHandlers() {
|
||||||
@ -54,11 +73,12 @@ public class MainWindow implements Runnable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void status(String text) {
|
public static void status(String text) {
|
||||||
ripStatus.setText(text);
|
statusLabel.setText(text);
|
||||||
}
|
}
|
||||||
|
|
||||||
class RipButtonHandler implements ActionListener {
|
class RipButtonHandler implements ActionListener {
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
statusButton.setVisible(false);
|
||||||
try {
|
try {
|
||||||
URL url = new URL(ripTextfield.getText());
|
URL url = new URL(ripTextfield.getText());
|
||||||
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
||||||
@ -85,7 +105,19 @@ public class MainWindow implements Runnable {
|
|||||||
break;
|
break;
|
||||||
case RIP_COMPLETE:
|
case RIP_COMPLETE:
|
||||||
File f = (File) msg.getObject();
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user