Rip-all history works!
This commit is contained in:
parent
2d49cb2b7b
commit
8b7e471b1c
@ -24,6 +24,9 @@ public abstract class AbstractRipper
|
|||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(AbstractRipper.class);
|
private static final Logger logger = Logger.getLogger(AbstractRipper.class);
|
||||||
|
|
||||||
|
protected static final String USER_AGENT =
|
||||||
|
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:27.0) Gecko/20100101 Firefox/27.0";
|
||||||
|
|
||||||
protected URL url;
|
protected URL url;
|
||||||
protected File workingDir;
|
protected File workingDir;
|
||||||
protected DownloadThreadPool threadPool;
|
protected DownloadThreadPool threadPool;
|
||||||
@ -193,7 +196,7 @@ public abstract class AbstractRipper
|
|||||||
private void checkIfComplete() {
|
private void checkIfComplete() {
|
||||||
if (!completed && itemsPending.size() == 0) {
|
if (!completed && itemsPending.size() == 0) {
|
||||||
completed = true;
|
completed = true;
|
||||||
logger.info("Rip completed!");
|
logger.info(" Rip completed!");
|
||||||
observer.update(this,
|
observer.update(this,
|
||||||
new RipStatusMessage(
|
new RipStatusMessage(
|
||||||
STATUS.RIP_COMPLETE,
|
STATUS.RIP_COMPLETE,
|
||||||
|
@ -95,7 +95,9 @@ public class ImgurRipper extends AbstractRipper {
|
|||||||
int index = 0;
|
int index = 0;
|
||||||
logger.info(" Retrieving " + url.toExternalForm());
|
logger.info(" Retrieving " + url.toExternalForm());
|
||||||
this.sendUpdate(STATUS.LOADING_RESOURCE, url.toExternalForm());
|
this.sendUpdate(STATUS.LOADING_RESOURCE, url.toExternalForm());
|
||||||
Document doc = Jsoup.connect(url.toExternalForm()).get();
|
Document doc = Jsoup.connect(url.toExternalForm())
|
||||||
|
.userAgent(USER_AGENT)
|
||||||
|
.get();
|
||||||
|
|
||||||
// Try to use embedded JSON to retrieve images
|
// Try to use embedded JSON to retrieve images
|
||||||
Pattern p = Pattern.compile("^.*Imgur\\.Album\\.getInstance\\((.*)\\);.*$", Pattern.DOTALL);
|
Pattern p = Pattern.compile("^.*Imgur\\.Album\\.getInstance\\((.*)\\);.*$", Pattern.DOTALL);
|
||||||
|
@ -19,8 +19,6 @@ public class MotherlessRipper extends AbstractRipper {
|
|||||||
private static final String DOMAIN = "motherless.com",
|
private static final String DOMAIN = "motherless.com",
|
||||||
HOST = "motherless";
|
HOST = "motherless";
|
||||||
private static final Logger logger = Logger.getLogger(MotherlessRipper.class);
|
private static final Logger logger = Logger.getLogger(MotherlessRipper.class);
|
||||||
private static final String USER_AGENT =
|
|
||||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:27.0) Gecko/20100101 Firefox/27.0";
|
|
||||||
|
|
||||||
private DownloadThreadPool motherlessThreadPool;
|
private DownloadThreadPool motherlessThreadPool;
|
||||||
|
|
||||||
|
@ -20,8 +20,6 @@ public class SeeniveRipper extends AbstractRipper {
|
|||||||
private static final String DOMAIN = "seenive.com",
|
private static final String DOMAIN = "seenive.com",
|
||||||
HOST = "seenive";
|
HOST = "seenive";
|
||||||
private static final Logger logger = Logger.getLogger(SeeniveRipper.class);
|
private static final Logger logger = Logger.getLogger(SeeniveRipper.class);
|
||||||
private static final String USER_AGENT =
|
|
||||||
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:27.0) Gecko/20100101 Firefox/27.0";
|
|
||||||
|
|
||||||
private DownloadThreadPool seeniveThreadPool;
|
private DownloadThreadPool seeniveThreadPool;
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ import java.io.FileReader;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
@ -29,6 +30,7 @@ import javax.swing.JProgressBar;
|
|||||||
import javax.swing.JScrollPane;
|
import javax.swing.JScrollPane;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
import javax.swing.JTextPane;
|
import javax.swing.JTextPane;
|
||||||
|
import javax.swing.ListSelectionModel;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.border.EmptyBorder;
|
import javax.swing.border.EmptyBorder;
|
||||||
import javax.swing.text.BadLocationException;
|
import javax.swing.text.BadLocationException;
|
||||||
@ -68,6 +70,7 @@ public class MainWindow implements Runnable {
|
|||||||
private static JList historyList;
|
private static JList historyList;
|
||||||
private static DefaultListModel historyListModel;
|
private static DefaultListModel historyListModel;
|
||||||
private static JScrollPane historyListScroll;
|
private static JScrollPane historyListScroll;
|
||||||
|
private static JPanel historyButtonPanel;
|
||||||
private static JButton historyButtonRemove,
|
private static JButton historyButtonRemove,
|
||||||
historyButtonClear,
|
historyButtonClear,
|
||||||
historyButtonRerip;
|
historyButtonRerip;
|
||||||
@ -155,13 +158,14 @@ public class MainWindow implements Runnable {
|
|||||||
historyPanel.setPreferredSize(new Dimension(300, 300));
|
historyPanel.setPreferredSize(new Dimension(300, 300));
|
||||||
historyListModel = new DefaultListModel();
|
historyListModel = new DefaultListModel();
|
||||||
historyList = new JList(historyListModel);
|
historyList = new JList(historyListModel);
|
||||||
|
historyList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||||
historyListScroll = new JScrollPane(historyList);
|
historyListScroll = new JScrollPane(historyList);
|
||||||
historyButtonRemove = new JButton("Remove");
|
historyButtonRemove = new JButton("Remove");
|
||||||
historyButtonClear = new JButton("Clear");
|
historyButtonClear = new JButton("Clear");
|
||||||
historyButtonRerip = new JButton("Re-rip All");
|
historyButtonRerip = new JButton("Re-rip All");
|
||||||
gbc.gridx = 0;
|
gbc.gridx = 0;
|
||||||
historyPanel.add(historyListScroll, gbc);
|
historyPanel.add(historyListScroll, gbc);
|
||||||
JPanel historyButtonPanel = new JPanel(new GridBagLayout());
|
historyButtonPanel = new JPanel(new GridBagLayout());
|
||||||
historyButtonPanel.setBorder(emptyBorder);
|
historyButtonPanel.setBorder(emptyBorder);
|
||||||
gbc.gridx = 0; historyButtonPanel.add(historyButtonRemove, gbc);
|
gbc.gridx = 0; historyButtonPanel.add(historyButtonRemove, gbc);
|
||||||
gbc.gridx = 1; historyButtonPanel.add(historyButtonClear, gbc);
|
gbc.gridx = 1; historyButtonPanel.add(historyButtonClear, gbc);
|
||||||
@ -213,6 +217,55 @@ public class MainWindow implements Runnable {
|
|||||||
mainFrame.pack();
|
mainFrame.pack();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
historyButtonRemove.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
int[] indices = historyList.getSelectedIndices();
|
||||||
|
for (int i = indices.length - 1; i >= 0; i--) {
|
||||||
|
historyListModel.remove(indices[i]);
|
||||||
|
}
|
||||||
|
saveHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
historyButtonClear.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
historyListModel.clear();
|
||||||
|
saveHistory();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Re-rip all history
|
||||||
|
historyButtonRerip.addActionListener(new ActionListener() {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent event) {
|
||||||
|
Runnable ripAllThread = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
historyButtonPanel.setEnabled(false);
|
||||||
|
historyList.setEnabled(false);
|
||||||
|
for (int i = 0; i < historyListModel.size(); i++) {
|
||||||
|
historyList.clearSelection();
|
||||||
|
historyList.setSelectedIndex(i);
|
||||||
|
Thread t = ripAlbum( (String) historyListModel.get(i) );
|
||||||
|
try {
|
||||||
|
synchronized (t) {
|
||||||
|
t.wait();
|
||||||
|
}
|
||||||
|
t.join();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
logger.error("[!] Exception while waiting for ripper to finish:", e);
|
||||||
|
}
|
||||||
|
System.err.println("Ripper thread finished");
|
||||||
|
}
|
||||||
|
historyList.setEnabled(true);
|
||||||
|
historyButtonPanel.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
new Thread(ripAllThread).start();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void appendLog(final String text, final Color color) {
|
private void appendLog(final String text, final Color color) {
|
||||||
@ -244,7 +297,9 @@ public class MainWindow implements Runnable {
|
|||||||
br = new BufferedReader(fr);
|
br = new BufferedReader(fr);
|
||||||
String line;
|
String line;
|
||||||
while ( (line = br.readLine()) != null ) {
|
while ( (line = br.readLine()) != null ) {
|
||||||
historyListModel.addElement(line);
|
if (!line.trim().equals("")) {
|
||||||
|
historyListModel.addElement(line.trim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
@ -279,25 +334,37 @@ public class MainWindow implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Thread ripAlbum(String urlString) {
|
||||||
|
URL url = null;
|
||||||
|
try {
|
||||||
|
url = new URL(urlString);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
logger.error("[!] Could not generate URL for '" + urlString + "'", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
ripButton.setEnabled(false);
|
||||||
|
ripTextfield.setEnabled(false);
|
||||||
|
statusProgress.setValue(100);
|
||||||
|
openButton.setVisible(false);
|
||||||
|
statusLabel.setVisible(true);
|
||||||
|
mainFrame.pack();
|
||||||
|
try {
|
||||||
|
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
||||||
|
ripTextfield.setText(ripper.getURL().toExternalForm());
|
||||||
|
ripper.setObserver(new RipStatusHandler());
|
||||||
|
Thread t = new Thread(ripper);
|
||||||
|
t.start();
|
||||||
|
return t;
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("[!] Error while ripping: " + e.getMessage(), e);
|
||||||
|
status("Error: " + e.getMessage());
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
class RipButtonHandler implements ActionListener {
|
class RipButtonHandler implements ActionListener {
|
||||||
public void actionPerformed(ActionEvent event) {
|
public void actionPerformed(ActionEvent event) {
|
||||||
ripButton.setEnabled(false);
|
ripAlbum(ripTextfield.getText());
|
||||||
ripTextfield.setEnabled(false);
|
|
||||||
statusProgress.setValue(100);
|
|
||||||
openButton.setVisible(false);
|
|
||||||
statusLabel.setVisible(true);
|
|
||||||
mainFrame.pack();
|
|
||||||
try {
|
|
||||||
URL url = new URL(ripTextfield.getText());
|
|
||||||
AbstractRipper ripper = AbstractRipper.getRipper(url);
|
|
||||||
ripper.setObserver(new RipStatusHandler());
|
|
||||||
Thread t = new Thread(ripper);
|
|
||||||
t.start();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.error("[!] Error while ripping: " + e.getMessage(), e);
|
|
||||||
status("Error: " + e.getMessage());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,7 +393,9 @@ public class MainWindow implements Runnable {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case RIP_COMPLETE:
|
case RIP_COMPLETE:
|
||||||
historyListModel.addElement(ripTextfield.getText());
|
if (!historyListModel.contains(ripTextfield.getText())) {
|
||||||
|
historyListModel.addElement(ripTextfield.getText());
|
||||||
|
}
|
||||||
saveHistory();
|
saveHistory();
|
||||||
ripButton.setEnabled(true);
|
ripButton.setEnabled(true);
|
||||||
ripTextfield.setEnabled(true);
|
ripTextfield.setEnabled(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user