diff --git a/src/main/java/com/rarchives/ripme/ui/MainWindow.java b/src/main/java/com/rarchives/ripme/ui/MainWindow.java index a20203e1..26b3fcaa 100644 --- a/src/main/java/com/rarchives/ripme/ui/MainWindow.java +++ b/src/main/java/com/rarchives/ripme/ui/MainWindow.java @@ -97,6 +97,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { private static JLabel configSaveDirLabel; private static JButton configSaveDirButton; private static JTextField configRetriesText; + private JTextField configRetrySleepText; private static JCheckBox configAutoupdateCheckbox; private static JComboBox configLogLevelCombobox; private static JCheckBox configURLHistoryCheckbox; @@ -114,6 +115,7 @@ public final class MainWindow implements Runnable, RipStatusHandler { private static JLabel configThreadsLabel; private static JLabel configTimeoutLabel; private static JLabel configRetriesLabel; + private static JLabel configRetrySleepLabel; // This doesn't really belong here but I have no idea where else to put it private static JButton configUrlFileChooserButton; @@ -502,9 +504,12 @@ public final class MainWindow implements Runnable, RipStatusHandler { configThreadsLabel = new JLabel(Utils.getLocalizedString("max.download.threads") + ":", JLabel.RIGHT); configTimeoutLabel = new JLabel(Utils.getLocalizedString("timeout.mill"), JLabel.RIGHT); configRetriesLabel = new JLabel(Utils.getLocalizedString("retry.download.count"), JLabel.RIGHT); + configRetrySleepLabel = new JLabel(Utils.getLocalizedString("retry.sleep.mill"), JLabel.RIGHT); configThreadsText = configField("threads.size", 3); configTimeoutText = configField("download.timeout", 60000); configRetriesText = configField("download.retries", 3); + configRetrySleepText = configField("download.retry.sleep", 5000); + configOverwriteCheckbox = addNewCheckbox(Utils.getLocalizedString("overwrite.existing.files"), "file.overwrite", false); configAutoupdateCheckbox = addNewCheckbox(Utils.getLocalizedString("auto.update"), "auto.update", true); @@ -547,19 +552,21 @@ public final class MainWindow implements Runnable, RipStatusHandler { configSaveDirLabel.setHorizontalAlignment(JLabel.RIGHT); configSaveDirButton = new JButton(Utils.getLocalizedString("select.save.dir") + "..."); - addItemToConfigGridBagConstraints(gbc, 0, configUpdateLabel, configUpdateButton); - addItemToConfigGridBagConstraints(gbc, 1, configAutoupdateCheckbox, configLogLevelCombobox); - addItemToConfigGridBagConstraints(gbc, 2, configThreadsLabel, configThreadsText); - addItemToConfigGridBagConstraints(gbc, 3, configTimeoutLabel, configTimeoutText); - addItemToConfigGridBagConstraints(gbc, 4, configRetriesLabel, configRetriesText); - addItemToConfigGridBagConstraints(gbc, 5, configOverwriteCheckbox, configSaveOrderCheckbox); - addItemToConfigGridBagConstraints(gbc, 6, configPlaySound, configSaveLogs); - addItemToConfigGridBagConstraints(gbc, 7, configShowPopup, configSaveURLsOnly); - addItemToConfigGridBagConstraints(gbc, 8, configClipboardAutorip, configSaveAlbumTitles); - addItemToConfigGridBagConstraints(gbc, 9, configSaveDescriptions, configPreferMp4); - addItemToConfigGridBagConstraints(gbc, 10, configWindowPosition, configURLHistoryCheckbox); - addItemToConfigGridBagConstraints(gbc, 11, configSelectLangComboBox, configUrlFileChooserButton); - addItemToConfigGridBagConstraints(gbc, 12, configSaveDirLabel, configSaveDirButton); + var idx = 0; + addItemToConfigGridBagConstraints(gbc, idx++, configUpdateLabel, configUpdateButton); + addItemToConfigGridBagConstraints(gbc, idx++, configAutoupdateCheckbox, configLogLevelCombobox); + addItemToConfigGridBagConstraints(gbc, idx++, configThreadsLabel, configThreadsText); + addItemToConfigGridBagConstraints(gbc, idx++, configTimeoutLabel, configTimeoutText); + addItemToConfigGridBagConstraints(gbc, idx++, configRetriesLabel, configRetriesText); + addItemToConfigGridBagConstraints(gbc, idx++, configRetrySleepLabel, configRetrySleepText); + addItemToConfigGridBagConstraints(gbc, idx++, configOverwriteCheckbox, configSaveOrderCheckbox); + addItemToConfigGridBagConstraints(gbc, idx++, configPlaySound, configSaveLogs); + addItemToConfigGridBagConstraints(gbc, idx++, configShowPopup, configSaveURLsOnly); + addItemToConfigGridBagConstraints(gbc, idx++, configClipboardAutorip, configSaveAlbumTitles); + addItemToConfigGridBagConstraints(gbc, idx++, configSaveDescriptions, configPreferMp4); + addItemToConfigGridBagConstraints(gbc, idx++, configWindowPosition, configURLHistoryCheckbox); + addItemToConfigGridBagConstraints(gbc, idx++, configSelectLangComboBox, configUrlFileChooserButton); + addItemToConfigGridBagConstraints(gbc, idx++, configSaveDirLabel, configSaveDirButton); emptyPanel = new JPanel(); emptyPanel.setPreferredSize(new Dimension(0, 0)); diff --git a/src/main/java/com/rarchives/ripme/utils/Http.java b/src/main/java/com/rarchives/ripme/utils/Http.java index 0c76a768..200d4e3d 100644 --- a/src/main/java/com/rarchives/ripme/utils/Http.java +++ b/src/main/java/com/rarchives/ripme/utils/Http.java @@ -30,6 +30,7 @@ public class Http { private static final Logger logger = LogManager.getLogger(Http.class); private int retries; + private int retrySleep = 0; private final String url; private Connection connection; @@ -54,6 +55,7 @@ public class Http { private void defaultSettings() { this.retries = Utils.getConfigInteger("download.retries", 1); + this.retrySleep = Utils.getConfigInteger("download.retry.sleep", 5000); connection = Jsoup.connect(this.url); connection.userAgent(AbstractRipper.USER_AGENT); connection.method(Method.GET); @@ -210,9 +212,21 @@ public class Http { if (status == 401 || status == 403) { throw new IOException("Failed to load " + url + ": Status Code " + status + ". You might be able to circumvent this error by setting cookies for this domain", e); } + if (status == 404) { + throw new IOException("File not found " + url + ": Status Code " + status + ". ", e); + } } - logger.warn("Error while loading " + url, e); + if (retrySleep > 0 && retries >= 0) { + try { + logger.warn("Error while loading " + url + " waiting "+ retrySleep + " ms before retrying.", e); + Thread.sleep(retrySleep); + } catch (final InterruptedException e1) { + e1.printStackTrace(); + } + } else { + logger.warn("Error while loading " + url, e); + } lastException = e; } } diff --git a/src/main/resources/LabelsBundle.properties b/src/main/resources/LabelsBundle.properties index 575f4f8e..63bca351 100644 --- a/src/main/resources/LabelsBundle.properties +++ b/src/main/resources/LabelsBundle.properties @@ -13,6 +13,7 @@ auto.update = Auto-update? max.download.threads = Maximum download threads: timeout.mill = Timeout (in milliseconds): retry.download.count = Retry download count +retry.sleep.mill = Wait between retries (in milliseconds): overwrite.existing.files = Overwrite existing files? sound.when.rip.completes = Sound when rip completes preserve.order = Preserve order