mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-24 06:23:52 +02:00
Merge branch 'master-ripme'
This commit is contained in:
@@ -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 allporncomic URL format: " +
|
||||
"allporncomic.com/TITLE/CHAPTER - 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<String> getURLsFromPage(Document doc) {
|
||||
List<String> 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));
|
||||
}
|
||||
}
|
@@ -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,
|
||||
"<html><font color=\"red\">Error while fetching update: " + e.getMessage() + "</font></html>",
|
||||
"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,
|
||||
"<html><font color=\"red\">Error while fetching update: " + e.getMessage() + "</font></html>",
|
||||
"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(
|
||||
"<html><font color=\"green\">New version (%s) is available!</font>" + "<br><br>Recent changes: %s"
|
||||
+ "<br><br>Do you want to download and run the newest version?</html>",
|
||||
latestVersion, changeList.replaceAll("\\n", "<br><br>")));
|
||||
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);
|
||||
"<html><font color=\"green\">New version (%s) is available!</font>" + "<br><br>Recent changes: %s"
|
||||
+ "<br><br>Do you want to download and run the newest version?</html>",
|
||||
latestVersion, changeList.replaceAll("\\n", "<br><br>")));
|
||||
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("<html>Current Version: " + getThisJarVersion()
|
||||
+ "<br><font color=\"green\">Latest version: " + latestVersion + "</font></html>");
|
||||
@@ -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("<html><font color=\"green\">v" + UpdateUtils.getThisJarVersion() + " is the latest version</font></html>");
|
||||
logger.debug("This version (" + UpdateUtils.getThisJarVersion()
|
||||
+ ") is the same or newer than the website's version (" + latestVersion + ")");
|
||||
configUpdateLabel.setText("<html><font color=\"green\">v" + UpdateUtils.getThisJarVersion()
|
||||
+ " is the latest version</font></html>");
|
||||
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();
|
||||
|
@@ -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,19 @@ 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() {
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,7 +237,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 +254,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 +286,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 +319,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 +361,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 +381,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 +405,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<JarEntry> 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 +454,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 +469,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 +492,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 +518,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 +528,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<String> of all album rippers present.
|
||||
*/
|
||||
@@ -529,7 +542,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<String> of all the video rippers.
|
||||
*/
|
||||
@@ -568,7 +582,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 +640,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 +709,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 +740,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 +766,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 +783,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 +797,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 +813,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);
|
||||
|
@@ -0,0 +1,16 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user