Skip to content

Commit

Permalink
new URI instead of new URL, pornhub, sta.
Browse files Browse the repository at this point in the history
  • Loading branch information
soloturn committed Dec 9, 2023
1 parent 8b9e4b9 commit 43ebb8d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -47,12 +49,12 @@ protected Document getFirstPage() throws IOException {
}

@Override
public Document getNextPage(Document page) throws IOException {
public Document getNextPage(Document page) throws IOException, URISyntaxException {
Elements nextPageLink = page.select("li.page_next > a");
if (nextPageLink.isEmpty()){
throw new IOException("No more pages");
} else {
URL nextURL = new URL(this.url, nextPageLink.first().attr("href"));
URL nextURL = this.url.toURI().resolve(nextPageLink.first().attr("href")).toURL();
return Http.url(nextURL).get();
}
}
Expand Down Expand Up @@ -83,13 +85,13 @@ protected void downloadURL(URL url, int index) {
}
}

public URL sanitizeURL(URL url) throws MalformedURLException {
public URL sanitizeURL(URL url) throws MalformedURLException, URISyntaxException {
// always start on the first page of an album
// (strip the options after the '?')
String u = url.toExternalForm();
if (u.contains("?")) {
u = u.substring(0, u.indexOf("?"));
return new URL(u);
return new URI(u).toURL();
} else {
return url;
}
Expand Down Expand Up @@ -159,10 +161,10 @@ private void fetchImage() {
prefix = String.format("%03d_", index);
}

URL imgurl = new URL(url, imgsrc);
URL imgurl = url.toURI().resolve(imgsrc).toURL();
addURLToDownload(imgurl, prefix);

} catch (IOException e) {
} catch (IOException | URISyntaxException e) {
LOGGER.error("[!] Exception while loading/parsing " + this.url, e);
}
}
Expand Down
10 changes: 6 additions & 4 deletions src/main/java/com/rarchives/ripme/ripper/rippers/StaRipper.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -55,10 +57,10 @@ public List<String> getURLsFromPage(Document doc) {
Document thumbPage = null;
if (checkURL(thumbPageURL)) {
try {
Connection.Response resp = Http.url(new URL(thumbPageURL)).response();
Connection.Response resp = Http.url(new URI(thumbPageURL).toURL()).response();
cookies.putAll(resp.cookies());
thumbPage = resp.parse();
} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
LOGGER.info(thumbPageURL + " is a malformed URL");
} catch (IOException e) {
LOGGER.info(e.getMessage());
Expand All @@ -75,9 +77,9 @@ public List<String> getURLsFromPage(Document doc) {

private boolean checkURL(String url) {
try {
new URL(url);
new URI(url).toURL();
return true;
} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
return false;
}
}
Expand Down

0 comments on commit 43ebb8d

Please sign in to comment.