1
0
mirror of https://github.com/RipMeApp/ripme.git synced 2025-08-13 01:14:14 +02:00

Fix usage of deprecated URL constructors

This commit is contained in:
MetaPrime
2025-01-02 00:00:25 -08:00
parent 3b9352fb14
commit 4e3619ad13
4 changed files with 43 additions and 28 deletions

View File

@@ -28,7 +28,7 @@ import com.rarchives.ripme.utils.Http;
* Simplified ripper, designed for ripping from sites by parsing HTML. * Simplified ripper, designed for ripping from sites by parsing HTML.
*/ */
public abstract class AbstractHTMLRipper extends AbstractRipper { public abstract class AbstractHTMLRipper extends AbstractRipper {
private final Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<>()); private final Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<>());
private final Map<URL, Path> itemsCompleted = Collections.synchronizedMap(new HashMap<>()); private final Map<URL, Path> itemsCompleted = Collections.synchronizedMap(new HashMap<>());
private final Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<>()); private final Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<>());
@@ -60,11 +60,15 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
public Document getNextPage(Document doc) throws IOException, URISyntaxException { public Document getNextPage(Document doc) throws IOException, URISyntaxException {
return null; return null;
} }
protected abstract List<String> getURLsFromPage(Document page) throws UnsupportedEncodingException;
protected abstract List<String> getURLsFromPage(Document page) throws UnsupportedEncodingException, URISyntaxException;
protected List<String> getDescriptionsFromPage(Document doc) throws IOException { protected List<String> getDescriptionsFromPage(Document doc) throws IOException {
throw new IOException("getDescriptionsFromPage not implemented"); // Do I do this or make an abstract function? throw new IOException("getDescriptionsFromPage not implemented"); // Do I do this or make an abstract function?
} }
protected abstract void downloadURL(URL url, int index); protected abstract void downloadURL(URL url, int index);
protected DownloadThreadPool getThreadPool() { protected DownloadThreadPool getThreadPool() {
return null; return null;
} }
@@ -130,7 +134,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
List<String> doclocation = new ArrayList<>(); List<String> doclocation = new ArrayList<>();
LOGGER.info("Got doc location " + doc.location()); LOGGER.info("Got doc location " + doc.location());
while (doc != null) { while (doc != null) {
LOGGER.info("Processing a doc..."); LOGGER.info("Processing a doc...");
@@ -167,7 +171,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
for (String imageURL : imageURLs) { for (String imageURL : imageURLs) {
index += 1; index += 1;
LOGGER.debug("Found image url #" + index + ": '" + imageURL + "'"); LOGGER.debug("Found image url #" + index + ": '" + imageURL + "'");
downloadURL(new URL(imageURL), index); downloadURL(new URI(imageURL).toURL(), index);
if (isStopped() || isThisATest()) { if (isStopped() || isThisATest()) {
break; break;
} }
@@ -182,19 +186,26 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
if (isStopped() || isThisATest()) { if (isStopped() || isThisATest()) {
break; break;
} }
textindex += 1; textindex += 1;
LOGGER.debug("Getting description from " + textURL); LOGGER.debug("Getting description from " + textURL);
String[] tempDesc = getDescription(textURL,doc); String[] tempDesc = getDescription(textURL,doc);
if (tempDesc != null) { if (tempDesc != null) {
if (Utils.getConfigBoolean("file.overwrite", false) || !(new File( URL url = new URI(textURL).toURL();
workingDir.getCanonicalPath() String filename = fileNameFromURL(url);
+ ""
+ File.separator boolean fileExists = new File(
+ getPrefix(index) workingDir.getCanonicalPath()
+ (tempDesc.length > 1 ? tempDesc[1] : fileNameFromURL(new URL(textURL))) + ""
+ ".txt").exists())) { + File.separator
+ getPrefix(index)
+ (tempDesc.length > 1 ? tempDesc[1] : filename)
+ ".txt").exists();
if (Utils.getConfigBoolean("file.overwrite", false) || !fileExists) {
LOGGER.debug("Got description from " + textURL); LOGGER.debug("Got description from " + textURL);
saveText(new URL(textURL), "", tempDesc[0], textindex, (tempDesc.length > 1 ? tempDesc[1] : fileNameFromURL(new URL(textURL)))); saveText(url, "", tempDesc[0], textindex, (tempDesc.length > 1 ? tempDesc[1] : filename));
sleep(descSleepTime()); sleep(descSleepTime());
} else { } else {
LOGGER.debug("Description from " + textURL + " already exists."); LOGGER.debug("Description from " + textURL + " already exists.");
@@ -225,12 +236,12 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
} }
waitForThreads(); waitForThreads();
} }
/** /**
* Gets the file name from the URL * Gets the file name from the URL
* @param url * @param url
* URL that you want to get the filename from * URL that you want to get the filename from
* @return * @return
* Filename of the URL * Filename of the URL
*/ */
private String fileNameFromURL(URL url) { private String fileNameFromURL(URL url) {
@@ -244,7 +255,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
return saveAs; return saveAs;
} }
/** /**
* *
* @param url * @param url
* Target URL * Target URL
* @param subdirectory * @param subdirectory
@@ -253,7 +264,7 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
* Text you want to save * Text you want to save
* @param index * @param index
* Index in something like an album * Index in something like an album
* @return * @return
* True if ripped successfully * True if ripped successfully
* False if failed * False if failed
*/ */
@@ -295,12 +306,12 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
} }
return true; return true;
} }
/** /**
* Gets prefix based on where in the index it is * Gets prefix based on where in the index it is
* @param index * @param index
* The index in question * The index in question
* @return * @return
* Returns prefix for a file. (?) * Returns prefix for a file. (?)
*/ */
protected String getPrefix(int index) { protected String getPrefix(int index) {
@@ -313,9 +324,9 @@ public abstract class AbstractHTMLRipper extends AbstractRipper {
/* /*
* ------ Methods copied from AlbumRipper. ------ * ------ Methods copied from AlbumRipper. ------
* This removes AlbumnRipper's usage from this class. * This removes AlbumnRipper's usage from this class.
*/ */
protected boolean allowDuplicates() { protected boolean allowDuplicates() {
return false; return false;
} }

View File

@@ -8,6 +8,7 @@ import org.json.JSONObject;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
@@ -94,7 +95,7 @@ public abstract class AbstractJSONRipper extends AbstractRipper {
index += 1; index += 1;
LOGGER.debug("Found image url #" + index+ ": " + imageURL); LOGGER.debug("Found image url #" + index+ ": " + imageURL);
downloadURL(new URL(imageURL), index); downloadURL(new URI(imageURL).toURL(), index);
} }
if (isStopped() || isThisATest()) { if (isStopped() || isThisATest()) {

View File

@@ -6,6 +6,7 @@ import com.rarchives.ripme.utils.Utils;
import com.rarchives.ripme.utils.RipUtils; import com.rarchives.ripme.utils.RipUtils;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
@@ -208,7 +209,7 @@ public class ChanRipper extends AbstractHTMLRipper {
return false; return false;
} }
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) throws URISyntaxException {
List<String> imageURLs = new ArrayList<>(); List<String> imageURLs = new ArrayList<>();
Pattern p; Matcher m; Pattern p; Matcher m;
for (Element link : page.select("a")) { for (Element link : page.select("a")) {
@@ -254,7 +255,7 @@ public class ChanRipper extends AbstractHTMLRipper {
//Copied code from RedditRipper, getFilesFromURL should also implement stuff like flickr albums //Copied code from RedditRipper, getFilesFromURL should also implement stuff like flickr albums
URL originalURL; URL originalURL;
try { try {
originalURL = new URL(href); originalURL = new URI(href).toURL();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
continue; continue;
} }

View File

@@ -2,6 +2,8 @@ package com.rarchives.ripme.ripper.rippers.video;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.List; import java.util.List;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@@ -51,7 +53,7 @@ public class MotherlessVideoRipper extends VideoRipper {
} }
@Override @Override
public void rip() throws IOException { public void rip() throws IOException, URISyntaxException {
LOGGER.info(" Retrieving " + this.url); LOGGER.info(" Retrieving " + this.url);
String html = Http.url(this.url).get().toString(); String html = Http.url(this.url).get().toString();
if (html.contains("__fileurl = '")) { if (html.contains("__fileurl = '")) {
@@ -62,7 +64,7 @@ public class MotherlessVideoRipper extends VideoRipper {
throw new IOException("Could not find video URL at " + url); throw new IOException("Could not find video URL at " + url);
} }
String vidUrl = vidUrls.get(0); String vidUrl = vidUrls.get(0);
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url)); addURLToDownload(new URI(vidUrl).toURL(), HOST + "_" + getGID(this.url));
waitForThreads(); waitForThreads();
} }
} }