Better about box

This commit is contained in:
4pr0n 2014-04-27 10:09:52 -07:00
parent 55145165f8
commit 6a45cd59e9
4 changed files with 75 additions and 11 deletions

View File

@ -255,7 +255,7 @@ public abstract class AbstractRipper
* List of constructors for all eligible Rippers. * List of constructors for all eligible Rippers.
* @throws Exception * @throws Exception
*/ */
private static List<Constructor<?>> getRipperConstructors(String pkg) throws Exception { public static List<Constructor<?>> getRipperConstructors(String pkg) throws Exception {
List<Constructor<?>> constructors = new ArrayList<Constructor<?>>(); List<Constructor<?>> constructors = new ArrayList<Constructor<?>>();
for (Class<?> clazz : Utils.getClassesForPackage(pkg)) { for (Class<?> clazz : Utils.getClassesForPackage(pkg)) {
if (AbstractRipper.class.isAssignableFrom(clazz)) { if (AbstractRipper.class.isAssignableFrom(clazz)) {

View File

@ -14,6 +14,7 @@ import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import com.rarchives.ripme.ripper.AlbumRipper; import com.rarchives.ripme.ripper.AlbumRipper;
import com.rarchives.ripme.ui.RipStatusMessage.STATUS;
public class InstagramRipper extends AlbumRipper { public class InstagramRipper extends AlbumRipper {
@ -70,6 +71,7 @@ public class InstagramRipper extends AlbumRipper {
private String getUserID(URL url) throws IOException { private String getUserID(URL url) throws IOException {
logger.info(" Retrieving " + url); logger.info(" Retrieving " + url);
this.sendUpdate(STATUS.LOADING_RESOURCE, url.toExternalForm());
Document doc = Jsoup.connect(this.url.toExternalForm()).get(); Document doc = Jsoup.connect(this.url.toExternalForm()).get();
for (Element element : doc.select("input[id=user_public]")) { for (Element element : doc.select("input[id=user_public]")) {
return element.attr("value"); return element.attr("value");
@ -85,6 +87,7 @@ public class InstagramRipper extends AlbumRipper {
String params = ""; String params = "";
while (true) { while (true) {
String url = baseURL + params; String url = baseURL + params;
this.sendUpdate(STATUS.LOADING_RESOURCE, url);
logger.info(" Retrieving " + url); logger.info(" Retrieving " + url);
String jsonString = Jsoup.connect(url) String jsonString = Jsoup.connect(url)
.ignoreContentType(true) .ignoreContentType(true)

View File

@ -23,9 +23,12 @@ import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter; import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent; import java.awt.event.WindowEvent;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.DefaultListModel; import javax.swing.DefaultListModel;
@ -493,12 +496,56 @@ public class MainWindow implements Runnable, RipStatusHandler {
trayMenuAbout.addActionListener(new ActionListener() { trayMenuAbout.addActionListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent arg0) { public void actionPerformed(ActionEvent arg0) {
String aboutBlurb = "<html><center> Download albums from various websites. <a href=\"http://rarchives.com\">rarchives.com</a>"; StringBuilder about = new StringBuilder();
JOptionPane.showMessageDialog(null, about.append("<html><h1>")
aboutBlurb, .append(mainFrame.getTitle())
.append("</h1>");
about.append("Download albums from various websites:");
try {
List<String> rippers = Utils.getListOfAlbumRippers();
about.append("<ul>");
for (String ripper : rippers) {
about.append("<li>");
ripper = ripper.substring(ripper.lastIndexOf('.') + 1);
if (ripper.contains("Ripper")) {
ripper = ripper.substring(0, ripper.indexOf("Ripper"));
}
about.append(ripper);
about.append("</li>");
}
about.append("</ul>");
} catch (Exception e) { }
about.append("<br>And download videos from video sites:");
try {
List<String> rippers = Utils.getListOfVideoRippers();
about.append("<ul>");
for (String ripper : rippers) {
about.append("<li>");
ripper = ripper.substring(ripper.lastIndexOf('.') + 1);
if (ripper.contains("Ripper")) {
ripper = ripper.substring(0, ripper.indexOf("Ripper"));
}
about.append(ripper);
about.append("</li>");
}
about.append("</ul>");
} catch (Exception e) { }
about.append("Do you want to visit the project homepage on Github?");
about.append("</html>");
int response = JOptionPane.showConfirmDialog(null,
about.toString(),
mainFrame.getTitle(), mainFrame.getTitle(),
JOptionPane.YES_NO_OPTION,
JOptionPane.PLAIN_MESSAGE, JOptionPane.PLAIN_MESSAGE,
new ImageIcon(mainIcon)); new ImageIcon(mainIcon));
if (response == JOptionPane.YES_OPTION) {
try {
Desktop.getDesktop().browse(URI.create("http://github.com/4pr0n/ripme"));
} catch (IOException e) {
logger.error("Exception while opening project home page", e);
}
}
} }
}); });
trayMenuExit = new MenuItem("Exit"); trayMenuExit = new MenuItem("Exit");
@ -626,12 +673,7 @@ public class MainWindow implements Runnable, RipStatusHandler {
ripper.setObserver((RipStatusHandler) this); ripper.setObserver((RipStatusHandler) this);
Thread t = new Thread(ripper); Thread t = new Thread(ripper);
t.start(); t.start();
if (!mainFrame.isVisible()) { if (!mainFrame.isVisible() || !mainFrame.isActive()) {
mainFrame.toFront();
mainFrame.setAlwaysOnTop(true);
trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO);
mainFrame.setAlwaysOnTop(false);
} else if (!mainFrame.isActive()) {
mainFrame.toFront(); mainFrame.toFront();
mainFrame.setAlwaysOnTop(true); mainFrame.setAlwaysOnTop(true);
trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO); trayIcon.displayMessage(mainFrame.getTitle(), "Started ripping " + ripper.getURL().toExternalForm(), MessageType.INFO);
@ -653,7 +695,8 @@ public class MainWindow implements Runnable, RipStatusHandler {
class RipButtonHandler implements ActionListener { class RipButtonHandler implements ActionListener {
public void actionPerformed(ActionEvent event) { public void actionPerformed(ActionEvent event) {
ripAlbum(ripTextfield.getText()); Thread t = ripAlbum(ripTextfield.getText());
SwingUtilities.invokeLater(t);
} }
} }

View File

@ -2,6 +2,7 @@ package com.rarchives.ripme.utils;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@ -14,6 +15,8 @@ import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import com.rarchives.ripme.ripper.AbstractRipper;
/** /**
* Common utility functions used in various places throughout the project. * Common utility functions used in various places throughout the project.
*/ */
@ -264,4 +267,19 @@ public class Utils {
} }
return String.format("%.2f%sb", fbytes, mags[magIndex]); return String.format("%.2f%sb", fbytes, mags[magIndex]);
} }
public static List<String> getListOfAlbumRippers() throws Exception {
List<String> list = new ArrayList<String>();
for (Constructor<?> ripper : AbstractRipper.getRipperConstructors("com.rarchives.ripme.ripper.rippers")) {
list.add(ripper.getName());
}
return list;
}
public static List<String> getListOfVideoRippers() throws Exception {
List<String> list = new ArrayList<String>();
for (Constructor<?> ripper : AbstractRipper.getRipperConstructors("com.rarchives.ripme.ripper.rippers.video")) {
list.add(ripper.getName());
}
return list;
}
} }