Skip to content

Commit 08143a6

Browse files
committed
Fix usage of deprecated URL constructors
1 parent d6b8bf2 commit 08143a6

File tree

4 files changed

+43
-28
lines changed

4 files changed

+43
-28
lines changed

src/main/java/com/rarchives/ripme/ripper/AbstractHTMLRipper.java

Lines changed: 33 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
* Simplified ripper, designed for ripping from sites by parsing HTML.
2929
*/
3030
public abstract class AbstractHTMLRipper extends AbstractRipper {
31-
31+
3232
private final Map<URL, File> itemsPending = Collections.synchronizedMap(new HashMap<>());
3333
private final Map<URL, Path> itemsCompleted = Collections.synchronizedMap(new HashMap<>());
3434
private final Map<URL, String> itemsErrored = Collections.synchronizedMap(new HashMap<>());
@@ -60,11 +60,15 @@ protected Document getCachedFirstPage() throws IOException, URISyntaxException {
6060
public Document getNextPage(Document doc) throws IOException, URISyntaxException {
6161
return null;
6262
}
63-
protected abstract List<String> getURLsFromPage(Document page) throws UnsupportedEncodingException;
63+
64+
protected abstract List<String> getURLsFromPage(Document page) throws UnsupportedEncodingException, URISyntaxException;
65+
6466
protected List<String> getDescriptionsFromPage(Document doc) throws IOException {
6567
throw new IOException("getDescriptionsFromPage not implemented"); // Do I do this or make an abstract function?
6668
}
69+
6770
protected abstract void downloadURL(URL url, int index);
71+
6872
protected DownloadThreadPool getThreadPool() {
6973
return null;
7074
}
@@ -130,7 +134,7 @@ public void rip() throws IOException, URISyntaxException {
130134
List<String> doclocation = new ArrayList<>();
131135

132136
LOGGER.info("Got doc location " + doc.location());
133-
137+
134138
while (doc != null) {
135139

136140
LOGGER.info("Processing a doc...");
@@ -167,7 +171,7 @@ public void rip() throws IOException, URISyntaxException {
167171
for (String imageURL : imageURLs) {
168172
index += 1;
169173
LOGGER.debug("Found image url #" + index + ": '" + imageURL + "'");
170-
downloadURL(new URL(imageURL), index);
174+
downloadURL(new URI(imageURL).toURL(), index);
171175
if (isStopped() || isThisATest()) {
172176
break;
173177
}
@@ -182,19 +186,26 @@ public void rip() throws IOException, URISyntaxException {
182186
if (isStopped() || isThisATest()) {
183187
break;
184188
}
189+
185190
textindex += 1;
186191
LOGGER.debug("Getting description from " + textURL);
187192
String[] tempDesc = getDescription(textURL,doc);
193+
188194
if (tempDesc != null) {
189-
if (Utils.getConfigBoolean("file.overwrite", false) || !(new File(
190-
workingDir.getCanonicalPath()
191-
+ ""
192-
+ File.separator
193-
+ getPrefix(index)
194-
+ (tempDesc.length > 1 ? tempDesc[1] : fileNameFromURL(new URL(textURL)))
195-
+ ".txt").exists())) {
195+
URL url = new URI(textURL).toURL();
196+
String filename = fileNameFromURL(url);
197+
198+
boolean fileExists = new File(
199+
workingDir.getCanonicalPath()
200+
+ ""
201+
+ File.separator
202+
+ getPrefix(index)
203+
+ (tempDesc.length > 1 ? tempDesc[1] : filename)
204+
+ ".txt").exists();
205+
206+
if (Utils.getConfigBoolean("file.overwrite", false) || !fileExists) {
196207
LOGGER.debug("Got description from " + textURL);
197-
saveText(new URL(textURL), "", tempDesc[0], textindex, (tempDesc.length > 1 ? tempDesc[1] : fileNameFromURL(new URL(textURL))));
208+
saveText(url, "", tempDesc[0], textindex, (tempDesc.length > 1 ? tempDesc[1] : filename));
198209
sleep(descSleepTime());
199210
} else {
200211
LOGGER.debug("Description from " + textURL + " already exists.");
@@ -225,12 +236,12 @@ public void rip() throws IOException, URISyntaxException {
225236
}
226237
waitForThreads();
227238
}
228-
239+
229240
/**
230241
* Gets the file name from the URL
231-
* @param url
242+
* @param url
232243
* URL that you want to get the filename from
233-
* @return
244+
* @return
234245
* Filename of the URL
235246
*/
236247
private String fileNameFromURL(URL url) {
@@ -244,7 +255,7 @@ private String fileNameFromURL(URL url) {
244255
return saveAs;
245256
}
246257
/**
247-
*
258+
*
248259
* @param url
249260
* Target URL
250261
* @param subdirectory
@@ -253,7 +264,7 @@ private String fileNameFromURL(URL url) {
253264
* Text you want to save
254265
* @param index
255266
* Index in something like an album
256-
* @return
267+
* @return
257268
* True if ripped successfully
258269
* False if failed
259270
*/
@@ -295,12 +306,12 @@ private boolean saveText(URL url, String subdirectory, String text, int index, S
295306
}
296307
return true;
297308
}
298-
309+
299310
/**
300311
* Gets prefix based on where in the index it is
301-
* @param index
312+
* @param index
302313
* The index in question
303-
* @return
314+
* @return
304315
* Returns prefix for a file. (?)
305316
*/
306317
protected String getPrefix(int index) {
@@ -313,9 +324,9 @@ protected String getPrefix(int index) {
313324

314325
/*
315326
* ------ Methods copied from AlbumRipper. ------
316-
* This removes AlbumnRipper's usage from this class.
327+
* This removes AlbumnRipper's usage from this class.
317328
*/
318-
329+
319330
protected boolean allowDuplicates() {
320331
return false;
321332
}

src/main/java/com/rarchives/ripme/ripper/AbstractJSONRipper.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.io.File;
99
import java.io.IOException;
1010
import java.net.MalformedURLException;
11+
import java.net.URI;
1112
import java.net.URISyntaxException;
1213
import java.net.URL;
1314
import java.nio.charset.StandardCharsets;
@@ -94,7 +95,7 @@ public void rip() throws IOException, URISyntaxException {
9495

9596
index += 1;
9697
LOGGER.debug("Found image url #" + index+ ": " + imageURL);
97-
downloadURL(new URL(imageURL), index);
98+
downloadURL(new URI(imageURL).toURL(), index);
9899
}
99100

100101
if (isStopped() || isThisATest()) {

src/main/java/com/rarchives/ripme/ripper/rippers/ChanRipper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.rarchives.ripme.utils.RipUtils;
77
import java.io.IOException;
88
import java.net.MalformedURLException;
9+
import java.net.URI;
910
import java.net.URISyntaxException;
1011
import java.net.URL;
1112
import java.util.ArrayList;
@@ -208,7 +209,7 @@ private boolean isURLBlacklisted(String url) {
208209
return false;
209210
}
210211
@Override
211-
public List<String> getURLsFromPage(Document page) {
212+
public List<String> getURLsFromPage(Document page) throws URISyntaxException {
212213
List<String> imageURLs = new ArrayList<>();
213214
Pattern p; Matcher m;
214215
for (Element link : page.select("a")) {
@@ -254,7 +255,7 @@ public List<String> getURLsFromPage(Document page) {
254255
//Copied code from RedditRipper, getFilesFromURL should also implement stuff like flickr albums
255256
URL originalURL;
256257
try {
257-
originalURL = new URL(href);
258+
originalURL = new URI(href).toURL();
258259
} catch (MalformedURLException e) {
259260
continue;
260261
}

src/main/java/com/rarchives/ripme/ripper/rippers/video/MotherlessVideoRipper.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.io.IOException;
44
import java.net.MalformedURLException;
5+
import java.net.URI;
6+
import java.net.URISyntaxException;
57
import java.net.URL;
68
import java.util.List;
79
import java.util.regex.Matcher;
@@ -51,7 +53,7 @@ public String getGID(URL url) throws MalformedURLException {
5153
}
5254

5355
@Override
54-
public void rip() throws IOException {
56+
public void rip() throws IOException, URISyntaxException {
5557
LOGGER.info(" Retrieving " + this.url);
5658
String html = Http.url(this.url).get().toString();
5759
if (html.contains("__fileurl = '")) {
@@ -62,7 +64,7 @@ public void rip() throws IOException {
6264
throw new IOException("Could not find video URL at " + url);
6365
}
6466
String vidUrl = vidUrls.get(0);
65-
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
67+
addURLToDownload(new URI(vidUrl).toURL(), HOST + "_" + getGID(this.url));
6668
waitForThreads();
6769
}
68-
}
70+
}

0 commit comments

Comments
 (0)