From c2e42f260ed482045cc13832e8550896ab8e6c8a Mon Sep 17 00:00:00 2001 From: Isaaku Date: Wed, 24 Jul 2019 11:29:26 -0500 Subject: [PATCH 1/7] Network fix --- .../com/rarchives/ripme/ui/UpdateUtils.java | 84 +++++----- .../java/com/rarchives/ripme/utils/Utils.java | 152 ++++++++++-------- 2 files changed, 117 insertions(+), 119 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java index 3e1ea3b6..b9181ad9 100644 --- a/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java +++ b/src/main/java/com/rarchives/ripme/ui/UpdateUtils.java @@ -31,7 +31,7 @@ public class UpdateUtils { static { try { mainFileName = new File(UpdateUtils.class.getProtectionDomain().getCodeSource().getLocation().toURI()).getAbsolutePath(); - } catch (URISyntaxException e) { + } catch (URISyntaxException | IllegalArgumentException e) { mainFileName = "ripme.jar"; logger.error("Unable to get path of jar"); e.printStackTrace(); @@ -73,16 +73,12 @@ public class UpdateUtils { Document doc = null; try { logger.debug("Retrieving " + UpdateUtils.updateJsonURL); - doc = Jsoup.connect(UpdateUtils.updateJsonURL) - .timeout(10 * 1000) - .ignoreContentType(true) - .get(); + doc = Jsoup.connect(UpdateUtils.updateJsonURL).timeout(10 * 1000).ignoreContentType(true).get(); } catch (IOException e) { logger.error("Error while fetching update: ", e); JOptionPane.showMessageDialog(null, "Error while fetching update: " + e.getMessage() + "", - "RipMe Updater", - JOptionPane.ERROR_MESSAGE); + "RipMe Updater", JOptionPane.ERROR_MESSAGE); return; } finally { logger.info("Current version: " + getThisJarVersion()); @@ -105,8 +101,8 @@ public class UpdateUtils { logger.error("Error while updating: ", e); } } else { - logger.debug("This version (" + UpdateUtils.getThisJarVersion() + - ") is the same or newer than the website's version (" + latestVersion + ")"); + logger.debug("This version (" + UpdateUtils.getThisJarVersion() + + ") is the same or newer than the website's version (" + latestVersion + ")"); logger.info("v" + UpdateUtils.getThisJarVersion() + " is the latest version"); logger.debug("Running latest version: " + UpdateUtils.getThisJarVersion()); } @@ -118,16 +114,12 @@ public class UpdateUtils { Document doc = null; try { logger.debug("Retrieving " + UpdateUtils.updateJsonURL); - doc = Jsoup.connect(UpdateUtils.updateJsonURL) - .timeout(10 * 1000) - .ignoreContentType(true) - .get(); + doc = Jsoup.connect(UpdateUtils.updateJsonURL).timeout(10 * 1000).ignoreContentType(true).get(); } catch (IOException e) { logger.error("Error while fetching update: ", e); JOptionPane.showMessageDialog(null, "Error while fetching update: " + e.getMessage() + "", - "RipMe Updater", - JOptionPane.ERROR_MESSAGE); + "RipMe Updater", JOptionPane.ERROR_MESSAGE); return; } finally { configUpdateLabel.setText("Current version: " + getThisJarVersion()); @@ -141,14 +133,14 @@ public class UpdateUtils { if (UpdateUtils.isNewerVersion(latestVersion)) { logger.info("Found newer version: " + latestVersion); JEditorPane changeListPane = new JEditorPane("text/html", String.format( - "New version (%s) is available!" + "

Recent changes: %s" - + "

Do you want to download and run the newest version?", - latestVersion, changeList.replaceAll("\\n", "

"))); - changeListPane.setEditable(false); - JScrollPane changeListScrollPane = new JScrollPane(changeListPane); - changeListScrollPane.setPreferredSize(new Dimension(300, 300)); - int result = JOptionPane.showConfirmDialog(null, changeListScrollPane, "RipMe Updater", - JOptionPane.YES_NO_OPTION); + "New version (%s) is available!" + "

Recent changes: %s" + + "

Do you want to download and run the newest version?", + latestVersion, changeList.replaceAll("\\n", "

"))); + changeListPane.setEditable(false); + JScrollPane changeListScrollPane = new JScrollPane(changeListPane); + changeListScrollPane.setPreferredSize(new Dimension(300, 300)); + int result = JOptionPane.showConfirmDialog(null, changeListScrollPane, "RipMe Updater", + JOptionPane.YES_NO_OPTION); if (result != JOptionPane.YES_OPTION) { configUpdateLabel.setText("Current Version: " + getThisJarVersion() + "
Latest version: " + latestVersion + ""); @@ -159,17 +151,16 @@ public class UpdateUtils { try { UpdateUtils.downloadJarAndLaunch(getUpdateJarURL(latestVersion), true); } catch (IOException e) { - JOptionPane.showMessageDialog(null, - "Error while updating: " + e.getMessage(), - "RipMe Updater", - JOptionPane.ERROR_MESSAGE); - configUpdateLabel.setText(""); + JOptionPane.showMessageDialog(null, "Error while updating: " + e.getMessage(), "RipMe Updater", + JOptionPane.ERROR_MESSAGE); + configUpdateLabel.setText(""); logger.error("Error while updating: ", e); } } else { - logger.debug("This version (" + UpdateUtils.getThisJarVersion() + - ") is the same or newer than the website's version (" + latestVersion + ")"); - configUpdateLabel.setText("v" + UpdateUtils.getThisJarVersion() + " is the latest version"); + logger.debug("This version (" + UpdateUtils.getThisJarVersion() + + ") is the same or newer than the website's version (" + latestVersion + ")"); + configUpdateLabel.setText("v" + UpdateUtils.getThisJarVersion() + + " is the latest version"); logger.debug("Running latest version: " + UpdateUtils.getThisJarVersion()); } } @@ -191,8 +182,7 @@ public class UpdateUtils { if (newVersions[i] > oldVersions[i]) { logger.debug("oldVersion " + getThisJarVersion() + " < latestVersion" + latestVersion); return true; - } - else if (newVersions[i] < oldVersions[i]) { + } else if (newVersions[i] < oldVersions[i]) { logger.debug("oldVersion " + getThisJarVersion() + " > latestVersion " + latestVersion); return false; } @@ -214,7 +204,7 @@ public class UpdateUtils { } // Code take from https://stackoverflow.com/a/30925550 - public static String createSha256(File file) { + public static String createSha256(File file) { try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); InputStream fis = new FileInputStream(file); @@ -232,7 +222,8 @@ public class UpdateUtils { sb.append("0123456789ABCDEF".charAt((b & 0xF0) >> 4)); sb.append("0123456789ABCDEF".charAt((b & 0x0F))); } - // As patch.py writes the hash in lowercase this must return the has in lowercase + // As patch.py writes the hash in lowercase this must return the has in + // lowercase return sb.toString().toLowerCase(); } catch (NoSuchAlgorithmException e) { logger.error("Got error getting file hash " + e.getMessage()); @@ -244,13 +235,10 @@ public class UpdateUtils { return null; } - private static void downloadJarAndLaunch(String updateJarURL, Boolean shouldLaunch) - throws IOException { + private static void downloadJarAndLaunch(String updateJarURL, Boolean shouldLaunch) throws IOException { Response response; - response = Jsoup.connect(updateJarURL) - .ignoreContentType(true) - .timeout(Utils.getConfigInteger("download.timeout", 60 * 1000)) - .maxBodySize(1024 * 1024 * 100) + response = Jsoup.connect(updateJarURL).ignoreContentType(true) + .timeout(Utils.getConfigInteger("download.timeout", 60 * 1000)).maxBodySize(1024 * 1024 * 100) .execute(); try (FileOutputStream out = new FileOutputStream(updateFileName)) { @@ -276,15 +264,13 @@ public class UpdateUtils { // Windows final String batchFile = "update_ripme.bat"; final String batchPath = new File(batchFile).getAbsolutePath(); - String script = "@echo off\r\n" - + "timeout 1\r\n" - + "copy " + updateFileName + " " + mainFileName + "\r\n" - + "del " + updateFileName + "\r\n"; + String script = "@echo off\r\n" + "timeout 1\r\n" + "copy " + updateFileName + " " + mainFileName + "\r\n" + + "del " + updateFileName + "\r\n"; if (shouldLaunch) { script += mainFileName + "\r\n"; } script += "del " + batchPath + "\r\n"; - final String[] batchExec = new String[]{batchPath}; + final String[] batchExec = new String[] { batchPath }; // Create updater script try (BufferedWriter bw = new BufferedWriter(new FileWriter(batchFile))) { bw.write(script); @@ -298,7 +284,8 @@ public class UpdateUtils { logger.info("Executing: " + batchFile); Runtime.getRuntime().exec(batchExec); } catch (IOException e) { - //TODO implement proper stack trace handling this is really just intented as a placeholder until you implement proper error handling + // TODO implement proper stack trace handling this is really just intented as a + // placeholder until you implement proper error handling e.printStackTrace(); } })); @@ -306,7 +293,8 @@ public class UpdateUtils { System.exit(0); } else { // Mac / Linux - // Modifying file and launching it: *nix distributions don't have any issues with modifying/deleting files + // Modifying file and launching it: *nix distributions don't have any issues + // with modifying/deleting files // while they are being run File mainFile = new File(mainFileName); String mainFilePath = mainFile.getAbsolutePath(); diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index a15503d2..880e24e8 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -1,18 +1,10 @@ package com.rarchives.ripme.utils; -import com.rarchives.ripme.ripper.AbstractRipper; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.commons.configuration.PropertiesConfiguration; -import org.apache.log4j.LogManager; -import org.apache.log4j.Logger; -import org.apache.log4j.PropertyConfigurator; - -import javax.sound.sampled.AudioSystem; -import javax.sound.sampled.Clip; -import javax.sound.sampled.Line; -import javax.sound.sampled.LineEvent; -import java.io.*; -import java.lang.reflect.Array; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; import java.lang.reflect.Constructor; import java.net.URISyntaxException; import java.net.URL; @@ -30,7 +22,18 @@ import java.util.ResourceBundle; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import static java.lang.Math.toIntExact; +import javax.sound.sampled.AudioSystem; +import javax.sound.sampled.Clip; +import javax.sound.sampled.Line; +import javax.sound.sampled.LineEvent; + +import com.rarchives.ripme.ripper.AbstractRipper; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.log4j.LogManager; +import org.apache.log4j.Logger; +import org.apache.log4j.PropertyConfigurator; /** * Common utility functions used in various places throughout the project. @@ -88,9 +91,9 @@ public class Utils { * @return Root directory to save rips to. */ public static File getWorkingDirectory() { - String currentDir = "."; + String currentDir = ""; try { - currentDir = new File(".").getCanonicalPath() + File.separator + RIP_DIRECTORY + File.separator; + currentDir = getJarDirectory().getCanonicalPath() + File.separator + RIP_DIRECTORY + File.separator; } catch (IOException e) { LOGGER.error("Error while finding working dir: ", e); } @@ -214,8 +217,12 @@ public class Utils { * Gets the directory of where the config file is stored on a Mac machine. */ private static String getMacOSConfigDir() { - return System.getProperty("user.home") - + File.separator + "Library" + File.separator + "Application Support" + File.separator + "ripme"; + return System.getProperty("user.home") + File.separator + "Library" + File.separator + "Application Support" + + File.separator + "ripme"; + } + + private static File getJarDirectory() { + return new File(System.getProperty("java.class.path")).getParentFile(); } /** @@ -223,7 +230,7 @@ public class Utils { */ private static boolean portableMode() { try { - File file = new File(new File(".").getCanonicalPath() + File.separator + CONFIG_FILE); + File file = new File(getJarDirectory().getCanonicalPath() + File.separator + CONFIG_FILE); if (file.exists() && !file.isDirectory()) { return true; } @@ -240,18 +247,21 @@ public class Utils { public static String getConfigDir() { if (portableMode()) { try { - return new File(".").getCanonicalPath(); + return getJarDirectory().getCanonicalPath(); } catch (Exception e) { return "."; } } - if (isWindows()) return getWindowsConfigDir(); - if (isMacOS()) return getMacOSConfigDir(); - if (isUnix()) return getUnixConfigDir(); + if (isWindows()) + return getWindowsConfigDir(); + if (isMacOS()) + return getMacOSConfigDir(); + if (isUnix()) + return getUnixConfigDir(); try { - return new File(".").getCanonicalPath(); + return getJarDirectory().getCanonicalPath(); } catch (Exception e) { return "."; } @@ -269,9 +279,9 @@ public class Utils { * Return the path of the url history file */ public static String getURLHistoryFile() { - if(getConfigString("history.location", "").length()==0) { + if (getConfigString("history.location", "").length() == 0) { return getConfigDir() + File.separator + "url_history.txt"; - }else{ + } else { return getConfigString("history.location", ""); } } @@ -302,8 +312,8 @@ public class Utils { } /** - * Strips away URL parameters, which usually appear at the end of URLs. - * E.g. the ?query on PHP + * Strips away URL parameters, which usually appear at the end of URLs. E.g. the + * ?query on PHP * * @param url The URL to filter/strip * @param parameter The parameter to strip @@ -344,9 +354,8 @@ public class Utils { } /** - * Get a list of all Classes within a package. - * Works with file system projects and jar files! - * Borrowed from StackOverflow, but I don't have a link :[ + * Get a list of all Classes within a package. Works with file system projects + * and jar files! Borrowed from StackOverflow, but I don't have a link :[ * * @param pkgname The name of the package * @return List of classes within the package @@ -365,7 +374,10 @@ public class Utils { try { directory = new File(resource.toURI()); } catch (URISyntaxException e) { - throw new RuntimeException(pkgname + " (" + resource + ") does not appear to be a valid URL / URI. Strange, since we got it from the system...", e); + throw new RuntimeException( + pkgname + " (" + resource + + ") does not appear to be a valid URL / URI. Strange, since we got it from the system...", + e); } catch (IllegalArgumentException e) { directory = null; } @@ -386,17 +398,14 @@ public class Utils { } else { // Load from JAR try { - String jarPath = fullPath - .replaceFirst("[.]jar[!].*", ".jar") - .replaceFirst("file:", ""); + String jarPath = fullPath.replaceFirst("[.]jar[!].*", ".jar").replaceFirst("file:", ""); jarPath = URLDecoder.decode(jarPath, "UTF-8"); JarFile jarFile = new JarFile(jarPath); Enumeration entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry nextElement = entries.nextElement(); String entryName = nextElement.getName(); - if (entryName.startsWith(relPath) - && entryName.length() > (relPath.length() + "/".length()) + if (entryName.startsWith(relPath) && entryName.length() > (relPath.length() + "/".length()) && !nextElement.isDirectory()) { String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", ""); try { @@ -438,9 +447,7 @@ public class Utils { if (path.length() < SHORTENED_PATH_LENGTH * 2) { return path; } - return path.substring(0, SHORTENED_PATH_LENGTH) - + "..." - + path.substring(path.length() - SHORTENED_PATH_LENGTH); + return path.substring(0, SHORTENED_PATH_LENGTH) + "..." + path.substring(path.length() - SHORTENED_PATH_LENGTH); } /** @@ -455,9 +462,7 @@ public class Utils { } public static String filesystemSafe(String text) { - text = text.replaceAll("[^a-zA-Z0-9.-]", "_") - .replaceAll("__", "_") - .replaceAll("_+$", ""); + text = text.replaceAll("[^a-zA-Z0-9.-]", "_").replaceAll("__", "_").replaceAll("_+$", ""); if (text.length() > 100) { text = text.substring(0, 99); } @@ -480,8 +485,8 @@ public class Utils { return path; } - String original = path; // needs to be checked if lowercase exists - String lastPart = original.substring(index + 1).toLowerCase(); // setting lowercase to check if it exists + String original = path; // needs to be checked if lowercase exists + String lastPart = original.substring(index + 1).toLowerCase(); // setting lowercase to check if it exists // Get a List of all Directories and check its lowercase // if file exists return it @@ -506,7 +511,7 @@ public class Utils { */ public static String bytesToHumanReadable(int bytes) { float fbytes = (float) bytes; - String[] mags = new String[]{"", "K", "M", "G", "T"}; + String[] mags = new String[] { "", "K", "M", "G", "T" }; int magIndex = 0; while (fbytes >= 1024) { fbytes /= 1024; @@ -516,7 +521,8 @@ public class Utils { } /** - * Gets and returns a list of all the album rippers present in the "com.rarchives.ripme.ripper.rippers" package. + * Gets and returns a list of all the album rippers present in the + * "com.rarchives.ripme.ripper.rippers" package. * * @return List of all album rippers present. */ @@ -529,7 +535,8 @@ public class Utils { } /** - * Gets and returns a list of all video rippers present in the "com.rarchives.rime.rippers.video" package + * Gets and returns a list of all video rippers present in the + * "com.rarchives.rime.rippers.video" package * * @return List of all the video rippers. */ @@ -568,7 +575,6 @@ public class Utils { public static void configureLogger() { LogManager.shutdown(); String logFile = getConfigBoolean("log.save", false) ? "log4j.file.properties" : "log4j.properties"; - try (InputStream stream = Utils.class.getClassLoader().getResourceAsStream(logFile)) { if (stream == null) { PropertyConfigurator.configure("src/main/resources/" + logFile); @@ -627,7 +633,8 @@ public class Utils { try { for (String part : parts) { if ((pos = part.indexOf('=')) >= 0) { - res.put(URLDecoder.decode(part.substring(0, pos), "UTF-8"), URLDecoder.decode(part.substring(pos + 1), "UTF-8")); + res.put(URLDecoder.decode(part.substring(0, pos), "UTF-8"), + URLDecoder.decode(part.substring(pos + 1), "UTF-8")); } else { res.put(URLDecoder.decode(part, "UTF-8"), ""); } @@ -695,17 +702,19 @@ public class Utils { } /** - * Gets the ResourceBundle AKA language package. - * Used for choosing the language of the UI. + * Gets the ResourceBundle AKA language package. Used for choosing the language + * of the UI. * - * @return Returns the default resource bundle using the language specified in the config file. + * @return Returns the default resource bundle using the language specified in + * the config file. */ public static ResourceBundle getResourceBundle(String langSelect) { if (langSelect == null) { if (!getConfigString("lang", "").equals("")) { String[] langCode = getConfigString("lang", "").split("_"); LOGGER.info("Setting locale to " + getConfigString("lang", "")); - return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), new UTF8Control()); + return ResourceBundle.getBundle("LabelsBundle", new Locale(langCode[0], langCode[1]), + new UTF8Control()); } } else { String[] langCode = langSelect.split("_"); @@ -724,17 +733,17 @@ public class Utils { /** * Formats and reuturns the status text for rippers using the byte progress bar * - * @param completionPercentage An int between 0 and 100 which repersents how close the download is to complete - * @param bytesCompleted How many bytes have been downloaded - * @param bytesTotal The total size of the file that is being downloaded - * @return Returns the formatted status text for rippers using the byte progress bar + * @param completionPercentage An int between 0 and 100 which repersents how + * close the download is to complete + * @param bytesCompleted How many bytes have been downloaded + * @param bytesTotal The total size of the file that is being + * downloaded + * @return Returns the formatted status text for rippers using the byte progress + * bar */ public static String getByteStatusText(int completionPercentage, int bytesCompleted, int bytesTotal) { - return String.valueOf(completionPercentage) + - "% - " + - Utils.bytesToHumanReadable(bytesCompleted) + - " / " + - Utils.bytesToHumanReadable(bytesTotal); + return String.valueOf(completionPercentage) + "% - " + Utils.bytesToHumanReadable(bytesCompleted) + " / " + + Utils.bytesToHumanReadable(bytesTotal); } public static String getEXTFromMagic(ByteBuffer magic) { @@ -750,8 +759,8 @@ public class Utils { } private static void initialiseMagicHashMap() { - magicHash.put(ByteBuffer.wrap(new byte[]{-1, -40, -1, -37, 0, 0, 0, 0}), "jpeg"); - magicHash.put(ByteBuffer.wrap(new byte[]{-119, 80, 78, 71, 13, 0, 0, 0}), "png"); + magicHash.put(ByteBuffer.wrap(new byte[] { -1, -40, -1, -37, 0, 0, 0, 0 }), "jpeg"); + magicHash.put(ByteBuffer.wrap(new byte[] { -119, 80, 78, 71, 13, 0, 0, 0 }), "png"); } // Checks if a file exists ignoring it's extension. @@ -767,8 +776,8 @@ public class Utils { for (File file : listOfFiles) { if (file.isFile()) { - String[] filename = file.getName().split("\\.(?=[^\\.]+$)"); //split filename from it's extension - if(filename[0].equalsIgnoreCase(fileName)) { + String[] filename = file.getName().split("\\.(?=[^\\.]+$)"); // split filename from it's extension + if (filename[0].equalsIgnoreCase(fileName)) { return true; } } @@ -781,9 +790,9 @@ public class Utils { } public static File shortenSaveAsWindows(String ripsDirPath, String fileName) throws FileNotFoundException { -// int ripDirLength = ripsDirPath.length(); -// int maxFileNameLength = 260 - ripDirLength; -// LOGGER.info(maxFileNameLength); + // int ripDirLength = ripsDirPath.length(); + // int maxFileNameLength = 260 - ripDirLength; + // LOGGER.info(maxFileNameLength); LOGGER.error("The filename " + fileName + " is to long to be saved on this file system."); LOGGER.info("Shortening filename"); String fullPath = ripsDirPath + File.separator + fileName; @@ -797,7 +806,8 @@ public class Utils { throw new FileNotFoundException("File path is too long for this OS"); } String[] saveAsSplit = fileName.split("\\."); - // Get the file extension so when we shorten the file name we don't cut off the file extension + // Get the file extension so when we shorten the file name we don't cut off the + // file extension String fileExt = saveAsSplit[saveAsSplit.length - 1]; // The max limit for paths on Windows is 260 chars LOGGER.info(fullPath.substring(0, 260 - pathLength - fileExt.length() + 1) + "." + fileExt); From 187fd3c5c6a1ad65841eef2ba39710ef62137177 Mon Sep 17 00:00:00 2001 From: Isaaku Date: Wed, 24 Jul 2019 13:08:57 -0500 Subject: [PATCH 2/7] Network fix --- src/main/java/com/rarchives/ripme/utils/Utils.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 880e24e8..7cf4625b 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -222,7 +222,8 @@ public class Utils { } private static File getJarDirectory() { - return new File(System.getProperty("java.class.path")).getParentFile(); + String[] classPath = System.getProperty("java.class.path").split(";"); + return classPath.length > 1 ? new File(System.getProperty("user.dir")) : new File(classPath[0]).getParentFile(); } /** From ea3ee9ef0a110909e853fa1a30004f10866a9864 Mon Sep 17 00:00:00 2001 From: Isaaku Date: Wed, 24 Jul 2019 18:04:31 -0500 Subject: [PATCH 3/7] Fix execution in Ubuntu --- src/main/java/com/rarchives/ripme/utils/Utils.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index 7cf4625b..c5edd86d 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -222,8 +222,7 @@ public class Utils { } private static File getJarDirectory() { - String[] classPath = System.getProperty("java.class.path").split(";"); - return classPath.length > 1 ? new File(System.getProperty("user.dir")) : new File(classPath[0]).getParentFile(); + return Utils.class.getResource("/rip.properties").toString().contains("jar:") ? new File(System.getProperty("java.class.path")).getParentFile() : new File(System.getProperty("user.dir")); } /** From 00575e446ea18fc44a063d576d46c74a5eced2ed Mon Sep 17 00:00:00 2001 From: Isaaku Date: Wed, 24 Jul 2019 18:50:16 -0500 Subject: [PATCH 4/7] Fix network execution in Ubuntu --- src/main/java/com/rarchives/ripme/utils/Utils.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/rarchives/ripme/utils/Utils.java b/src/main/java/com/rarchives/ripme/utils/Utils.java index c5edd86d..8a8699a3 100644 --- a/src/main/java/com/rarchives/ripme/utils/Utils.java +++ b/src/main/java/com/rarchives/ripme/utils/Utils.java @@ -222,7 +222,14 @@ public class Utils { } private static File getJarDirectory() { - return Utils.class.getResource("/rip.properties").toString().contains("jar:") ? new File(System.getProperty("java.class.path")).getParentFile() : new File(System.getProperty("user.dir")); + File jarDirectory = Utils.class.getResource("/rip.properties").toString().contains("jar:") + ? new File(System.getProperty("java.class.path")).getParentFile() + : new File(System.getProperty("user.dir")); + + if (jarDirectory == null) + jarDirectory = new File("."); + + return jarDirectory; } /** From 6753451cf65094fc23953c0f36f7c39c43387b80 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 4 Aug 2019 11:56:29 -0400 Subject: [PATCH 5/7] Added ripper for allporncomic.com --- .../ripper/rippers/AllporncomicRipper.java | 63 +++++++++++++++++++ .../rippers/AllporncomicRipperTest.java | 22 +++++++ 2 files changed, 85 insertions(+) create mode 100644 src/main/java/com/rarchives/ripme/ripper/rippers/AllporncomicRipper.java create mode 100644 src/test/java/com/rarchives/ripme/tst/ripper/rippers/AllporncomicRipperTest.java diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/AllporncomicRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/AllporncomicRipper.java new file mode 100644 index 00000000..6e1329e4 --- /dev/null +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/AllporncomicRipper.java @@ -0,0 +1,63 @@ +package com.rarchives.ripme.ripper.rippers; + +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; + +import com.rarchives.ripme.ripper.AbstractHTMLRipper; +import com.rarchives.ripme.utils.Http; + +public class AllporncomicRipper extends AbstractHTMLRipper { + + public AllporncomicRipper(URL url) throws IOException { + super(url); + } + + @Override + public String getHost() { + return "allporncomic"; + } + + @Override + public String getDomain() { + return "allporncomic.com"; + } + + @Override + public String getGID(URL url) throws MalformedURLException { + Pattern p = Pattern.compile("https?://allporncomic.com/porncomic/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)"); + Matcher m = p.matcher(url.toExternalForm()); + if (m.matches()) { + return m.group(1) + "_" + m.group(2); + } + throw new MalformedURLException("Expected cfake URL format: " + + "cfake.com/picture/MODEL/ID - got " + url + " instead"); + } + + @Override + public Document getFirstPage() throws IOException { + // "url" is an instance field of the superclass + return Http.url(url).get(); + } + + @Override + public List getURLsFromPage(Document doc) { + List result = new ArrayList<>(); + for (Element el : doc.select(".wp-manga-chapter-img")) { + result.add(el.attr("src")); + } + return result; + } + + @Override + public void downloadURL(URL url, int index) { + addURLToDownload(url, getPrefix(index)); + } +} diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/AllporncomicRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/AllporncomicRipperTest.java new file mode 100644 index 00000000..1f32726d --- /dev/null +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/AllporncomicRipperTest.java @@ -0,0 +1,22 @@ +package com.rarchives.ripme.tst.ripper.rippers; + +import com.rarchives.ripme.ripper.rippers.AllporncomicRipper; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.net.URL; + +public class AllporncomicRipperTest extends RippersTest { + @Test + public void testAlbum() throws IOException { + AllporncomicRipper ripper = new AllporncomicRipper(new URL("https://allporncomic.com/porncomic/dnd-pvp-dungeons-dragons-fred-perry/1-dnd-pvp")); + testRipper(ripper); + } + + @Test + public void testGetGID() throws IOException { + URL url = new URL("https://allporncomic.com/porncomic/dnd-pvp-dungeons-dragons-fred-perry/1-dnd-pvp"); + AllporncomicRipper ripper = new AllporncomicRipper(url); + assertEquals("5230", ripper.getGID(url)); + } +} From d0379e9b750ed2f5388412344633b7110de7f9d9 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Sun, 4 Aug 2019 11:57:02 -0400 Subject: [PATCH 6/7] Removed copied paste test --- .../ripme/tst/ripper/rippers/AllporncomicRipperTest.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/AllporncomicRipperTest.java b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/AllporncomicRipperTest.java index 1f32726d..f8466072 100644 --- a/src/test/java/com/rarchives/ripme/tst/ripper/rippers/AllporncomicRipperTest.java +++ b/src/test/java/com/rarchives/ripme/tst/ripper/rippers/AllporncomicRipperTest.java @@ -13,10 +13,4 @@ public class AllporncomicRipperTest extends RippersTest { testRipper(ripper); } - @Test - public void testGetGID() throws IOException { - URL url = new URL("https://allporncomic.com/porncomic/dnd-pvp-dungeons-dragons-fred-perry/1-dnd-pvp"); - AllporncomicRipper ripper = new AllporncomicRipper(url); - assertEquals("5230", ripper.getGID(url)); - } } From 6b49e19cd9f2e0b8ce5b176a04e80dddd3398090 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Mon, 12 Aug 2019 18:37:50 -0400 Subject: [PATCH 7/7] Removed copy-paste error --- .../rarchives/ripme/ripper/rippers/AllporncomicRipper.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/AllporncomicRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/AllporncomicRipper.java index 6e1329e4..56f4153a 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/AllporncomicRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/AllporncomicRipper.java @@ -37,8 +37,8 @@ public class AllporncomicRipper extends AbstractHTMLRipper { if (m.matches()) { return m.group(1) + "_" + m.group(2); } - throw new MalformedURLException("Expected cfake URL format: " + - "cfake.com/picture/MODEL/ID - got " + url + " instead"); + throw new MalformedURLException("Expected allporncomic URL format: " + + "allporncomic.com/TITLE/CHAPTER - got " + url + " instead"); } @Override