Skip to content

Commit

Permalink
new URI instead of new URL.
Browse files Browse the repository at this point in the history
  • Loading branch information
soloturn committed Mar 20, 2024
1 parent 404da9b commit 106c25a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,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.List;
Expand All @@ -34,7 +36,7 @@ public String getHost() {


@Override
public URL sanitizeURL(URL url) throws MalformedURLException {
public URL sanitizeURL(URL url) throws MalformedURLException, URISyntaxException {
String u = url.toExternalForm();
// https://nsfw.xxx/user/kelly-kat/foo -> https://nsfw.xxx/user/kelly-kat
// https://nsfw.xxx/user/kelly-kat -> https://nsfw.xxx/user/kelly-kat
Expand All @@ -44,15 +46,15 @@ public URL sanitizeURL(URL url) throws MalformedURLException {
throw new MalformedURLException("Invalid URL: " + url);
}

return new URL(u);
return new URI(u).toURL();
}

String getUser() throws MalformedURLException {
return getGID(url);
}

URL getPage(int page) throws MalformedURLException {
return new URL("https://nsfw.xxx/slide-page/" + page + "?nsfw%5B%5D=0&types%5B%5D=image&types%5B%5D=video&types%5B%5D=gallery&slider=1&jsload=1&user=" + getUser());
URL getPage(int page) throws MalformedURLException, URISyntaxException {
return new URI("https://nsfw.xxx/slide-page/" + page + "?nsfw%5B%5D=0&types%5B%5D=image&types%5B%5D=video&types%5B%5D=gallery&slider=1&jsload=1&user=" + getUser()).toURL();
}


Expand All @@ -71,18 +73,18 @@ public String getGID(URL url) throws MalformedURLException {
int currentPage = 1;

@Override
protected JSONObject getFirstPage() throws IOException {
protected JSONObject getFirstPage() throws IOException, URISyntaxException {
return Http.url(getPage(1)).getJSON();
}

List<String> descriptions = new ArrayList<>();

@Override
protected JSONObject getNextPage(JSONObject doc) throws IOException {
protected JSONObject getNextPage(JSONObject doc) throws IOException, URISyntaxException {
currentPage++;
JSONObject nextPage = Http.url(getPage(doc.getInt("page") + 1)).getJSON();
JSONArray items = nextPage.getJSONArray("items");
if (items.length() == 0) {
if (items.isEmpty()) {
throw new IOException("No more pages");
}
return nextPage;
Expand Down Expand Up @@ -120,7 +122,7 @@ protected List<String> getURLsFromJSON(JSONObject json) {

return new ApiEntry(srcUrl, o.getString("author"), o.getString("title"));
})
.collect(Collectors.toList());
.toList();

data.forEach(e -> descriptions.add(e.title));
return data.stream().map(e -> e.srcUrl).collect(Collectors.toList());
Expand Down
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.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -32,11 +34,6 @@ public boolean canRip(URL url) {
return m.matches();
}

@Override
public URL sanitizeURL(URL url) throws MalformedURLException {
return url;
}

@Override
public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://.*stickyxxx\\.com(/)(.*)/$");
Expand All @@ -52,15 +49,15 @@ public String getGID(URL url) throws MalformedURLException {
}

@Override
public void rip() throws IOException {
public void rip() throws IOException, URISyntaxException {
LOGGER.info("Retrieving " + this.url);
Document doc = Http.url(url).get();
Elements videos = doc.select(".wp-video > video > source");
if (videos.isEmpty()) {
throw new IOException("Could not find Embed code at " + url);
}
String vidUrl = videos.attr("src");
addURLToDownload(new URL(vidUrl), HOST + "_" + getGID(this.url));
addURLToDownload(new URI(vidUrl).toURL(), HOST + "_" + getGID(this.url));
waitForThreads();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import com.rarchives.ripme.ripper.rippers.video.StickyXXXRipper;
// import com.rarchives.ripme.tst.ripper.rippers.RippersTest;
import com.rarchives.ripme.utils.Utils;
import org.junit.jupiter.api.Test;

public class StickyXXXRipperTest extends RippersTest {

@Test
public void testStickyXXXVideo() throws IOException, URISyntaxException {
// This test fails on the CI - possibly due to checking for a file before it's written - so we're skipping it
if (Utils.getConfigBoolean("test.run_flaky_tests", false)) {
Expand Down

0 comments on commit 106c25a

Please sign in to comment.