diff --git a/src/main/java/com/rarchives/ripme/App.java b/src/main/java/com/rarchives/ripme/App.java index 890883ee..2c37fdc9 100644 --- a/src/main/java/com/rarchives/ripme/App.java +++ b/src/main/java/com/rarchives/ripme/App.java @@ -24,6 +24,7 @@ import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; @@ -183,7 +184,7 @@ public class App { } for (HistoryEntry entry : HISTORY.toList()) { try { - URL url = new URL(entry.url); + URL url = new URI(entry.url).toURL(); rip(url); } catch (Exception e) { logger.error("[!] Failed to rip URL " + entry.url, e); @@ -212,7 +213,7 @@ public class App { if (entry.selected) { added++; try { - URL url = new URL(entry.url); + URL url = new URI(entry.url).toURL(); rip(url); } catch (Exception e) { logger.error("[!] Failed to rip URL " + entry.url, e); @@ -290,7 +291,7 @@ public class App { */ private static void ripURL(String targetURL, boolean saveConfig) { try { - URL url = new URL(targetURL); + URL url = new URI(targetURL).toURL(); rip(url); saveHistory(); } catch (MalformedURLException e) { diff --git a/src/main/java/com/rarchives/ripme/utils/Http.java b/src/main/java/com/rarchives/ripme/utils/Http.java index 35051846..f3b163a0 100644 --- a/src/main/java/com/rarchives/ripme/utils/Http.java +++ b/src/main/java/com/rarchives/ripme/utils/Http.java @@ -15,6 +15,8 @@ import org.jsoup.nodes.Document; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.HashMap; import java.util.Map; @@ -73,7 +75,7 @@ public class Http { String cookieDomain = ""; try { - URL parsed = new URL(u); + URL parsed = new URI(u).toURL(); String cookieStr = ""; String[] parts = parsed.getHost().split("\\."); @@ -97,7 +99,7 @@ public class Http { if (!cookieStr.equals("")) { cookiesParsed = RipUtils.getCookiesFromString(cookieStr.trim()); } - } catch (MalformedURLException e) { + } catch (MalformedURLException | URISyntaxException e) { logger.warn("Parsing url " + u + " while getting cookies", e); } diff --git a/src/main/java/com/rarchives/ripme/utils/RipUtils.java b/src/main/java/com/rarchives/ripme/utils/RipUtils.java index b001ff01..f0aa0d18 100644 --- a/src/main/java/com/rarchives/ripme/utils/RipUtils.java +++ b/src/main/java/com/rarchives/ripme/utils/RipUtils.java @@ -2,6 +2,8 @@ package com.rarchives.ripme.utils; import java.io.IOException; import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.util.*; import java.util.regex.Matcher; @@ -60,8 +62,8 @@ public class RipUtils { } else if (url.getHost().endsWith("i.imgur.com") && url.toExternalForm().contains("gifv")) { // links to imgur gifvs try { - result.add(new URL(url.toExternalForm().replaceAll(".gifv", ".mp4"))); - } catch (IOException e) { + result.add(new URI(url.toExternalForm().replaceAll(".gifv", ".mp4")).toURL()); + } catch (IOException | URISyntaxException e) { logger.info("Couldn't get gifv from " + url); } return result; @@ -72,8 +74,8 @@ public class RipUtils { logger.debug("Fetching gfycat page " + url); String videoURL = GfycatRipper.getVideoURL(url); logger.debug("Got gfycat URL: " + videoURL); - result.add(new URL(videoURL)); - } catch (IOException e) { + result.add(new URI(videoURL).toURL()); + } catch (IOException | URISyntaxException e) { // Do nothing logger.warn("Exception while retrieving gfycat page:", e); } @@ -84,8 +86,8 @@ public class RipUtils { logger.debug("Fetching redgifs page " + url); String videoURL = RedgifsRipper.getVideoURL(url); logger.debug("Got redgifs URL: " + videoURL); - result.add(new URL(videoURL)); - } catch (IOException e) { + result.add(new URI(videoURL).toURL()); + } catch (IOException | URISyntaxException e) { // Do nothing logger.warn("Exception while retrieving redgifs page:", e); } @@ -121,9 +123,9 @@ public class RipUtils { EromeRipper r = new EromeRipper(url); Document tempDoc = r.getFirstPage(); for (String u : r.getURLsFromPage(tempDoc)) { - result.add(new URL(u)); + result.add(new URI(u).toURL()); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { // Do nothing logger.warn("Exception while retrieving eroshare page:", e); } @@ -135,9 +137,9 @@ public class RipUtils { SoundgasmRipper r = new SoundgasmRipper(url); Document tempDoc = r.getFirstPage(); for (String u : r.getURLsFromPage(tempDoc)) { - result.add(new URL(u)); + result.add(new URI(u).toURL()); } - } catch (IOException e) { + } catch (IOException | URISyntaxException e) { // Do nothing logger.warn("Exception while retrieving soundgasm page:", e); } @@ -150,8 +152,8 @@ public class RipUtils { logger.info("URL: " + url.toExternalForm()); String u = url.toExternalForm().replaceAll("&", "&"); try { - result.add(new URL(u)); - } catch (MalformedURLException e) { + result.add(new URI(u).toURL()); + } catch (MalformedURLException | URISyntaxException e) { } return result; } @@ -161,11 +163,11 @@ public class RipUtils { m = p.matcher(url.toExternalForm()); if (m.matches()) { try { - URL singleURL = new URL(m.group(1)); + URL singleURL = new URI(m.group(1)).toURL(); logger.debug("Found single URL: " + singleURL); result.add(singleURL); return result; - } catch (MalformedURLException e) { + } catch (MalformedURLException | URISyntaxException e) { logger.error("[!] Not a valid URL: '" + url + "'", e); } } @@ -179,19 +181,19 @@ public class RipUtils { .get(); for (Element el : doc.select("meta")) { if (el.attr("property").equals("og:video")) { - result.add(new URL(el.attr("content"))); + result.add(new URI(el.attr("content")).toURL()); return result; } else if (el.attr("name").equals("twitter:image:src")) { - result.add(new URL(el.attr("content"))); + result.add(new URI(el.attr("content")).toURL()); return result; } else if (el.attr("name").equals("twitter:image")) { - result.add(new URL(el.attr("content"))); + result.add(new URI(el.attr("content")).toURL()); return result; } } - } catch (IOException ex) { + } catch (IOException | URISyntaxException ex) { logger.error("[!] Error", ex); }