From a3f7df6670b29eb5652140305284c98dcead7fff Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 23 Aug 2018 16:56:32 -0400 Subject: [PATCH 1/2] Added ability to download range of urls --- .../com/rarchives/ripme/ui/MainWindow.java | 45 ++++++++++++++++--- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index 517ae7e5..bc2adbb5 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -12,7 +12,6 @@ import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.lang.reflect.Array; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -21,7 +20,6 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.*; import java.util.List; -import java.util.stream.Stream; import javax.imageio.ImageIO; import javax.swing.DefaultListModel; @@ -1238,11 +1236,48 @@ public final class MainWindow implements Runnable, RipStatusHandler { return null; } + private boolean canRip(String urlString) { + try { + String urlText = urlString.trim(); + if (urlText.equals("")) { + return false; + } + if (!urlText.startsWith("http")) { + urlText = "http://" + urlText; + } + URL url = new URL(urlText); + // Ripper is needed here to throw.not throw an Exception + AbstractRipper ripper = AbstractRipper.getRipper(url); + return true; + } catch (Exception e) { + return false; + } + } + class RipButtonHandler implements ActionListener { public void actionPerformed(ActionEvent event) { - if (!queueListModel.contains(ripTextfield.getText()) && !ripTextfield.getText().equals("")) { - queueListModel.add(queueListModel.size(), ripTextfield.getText()); - ripTextfield.setText(""); + String url = ripTextfield.getText(); + if (!queueListModel.contains(url) && !url.equals("")) { + // Check if we're ripping a range of urls + if (url.contains("{")) { + // Make sure the user hasn't forgotten the closing } + if (url.contains("}")) { + String rangeToParse = url.substring(url.indexOf("{") + 1, url.indexOf("}")); + int rangeStart = Integer.parseInt(rangeToParse.split("-")[0]); + int rangeEnd = Integer.parseInt(rangeToParse.split("-")[1]); + for (int i = rangeStart; i < rangeEnd +1; i++) { + if (canRip(url.replaceAll("\\{\\S*\\}", Integer.toString(i)))) { + queueListModel.add(queueListModel.size(), url.replaceAll("\\{\\S*\\}", Integer.toString(i))); + ripTextfield.setText(""); + } else { + LOGGER.error("Can't find ripper for " + url.replaceAll("\\{\\S*\\}", Integer.toString(i))); + } + } + } + } else { + queueListModel.add(queueListModel.size(), ripTextfield.getText()); + ripTextfield.setText(""); + } } else { if (!isRipping) { ripNextAlbum(); From 1da35a5f748e7a79659e7182ef344559423cc20c Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 23 Aug 2018 19:52:50 -0400 Subject: [PATCH 2/2] Cleaned up some code --- src/main/java/com/rarchives/ripme/ui/MainWindow.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index bc2adbb5..b64ca0ca 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -1266,11 +1266,12 @@ public final class MainWindow implements Runnable, RipStatusHandler { int rangeStart = Integer.parseInt(rangeToParse.split("-")[0]); int rangeEnd = Integer.parseInt(rangeToParse.split("-")[1]); for (int i = rangeStart; i < rangeEnd +1; i++) { - if (canRip(url.replaceAll("\\{\\S*\\}", Integer.toString(i)))) { - queueListModel.add(queueListModel.size(), url.replaceAll("\\{\\S*\\}", Integer.toString(i))); + String realURL = url.replaceAll("\\{\\S*\\}", Integer.toString(i)); + if (canRip(realURL)) { + queueListModel.add(queueListModel.size(), realURL); ripTextfield.setText(""); } else { - LOGGER.error("Can't find ripper for " + url.replaceAll("\\{\\S*\\}", Integer.toString(i))); + LOGGER.error("Can't find ripper for " +realURL); } } }