Skip to content

Commit

Permalink
new URI instead of new URL, mangadex, vk.
Browse files Browse the repository at this point in the history
  • Loading branch information
soloturn committed Dec 9, 2023
1 parent 879c322 commit 8f279a6
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected AbstractJSONRipper(URL url) throws IOException {
@Override
public abstract String getHost();

protected abstract JSONObject getFirstPage() throws IOException;
protected abstract JSONObject getFirstPage() throws IOException, URISyntaxException;
protected JSONObject getNextPage(JSONObject doc) throws IOException, URISyntaxException {
throw new IOException("getNextPage not implemented");
}
Expand All @@ -62,7 +62,7 @@ public URL sanitizeURL(URL url) throws MalformedURLException, URISyntaxException
}

@Override
public void rip() throws IOException {
public void rip() throws IOException, URISyntaxException {
int index = 0;
LOGGER.info("Retrieving " + this.url);
sendUpdate(STATUS.LOADING_RESOURCE, this.url.toExternalForm());
Expand Down
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.HashMap;
Expand Down Expand Up @@ -79,14 +81,14 @@ private String getMangaID(String url) {


@Override
public JSONObject getFirstPage() throws IOException {
public JSONObject getFirstPage() throws IOException, URISyntaxException {
// Get the chapter ID
String chapterID = getChapterID(url.toExternalForm());
String mangaID = getMangaID(url.toExternalForm());
if (mangaID != null) {
return Http.url(new URL(mangaApiEndPoint + mangaID)).getJSON();
return Http.url(new URI(mangaApiEndPoint + mangaID).toURL()).getJSON();
} else
return Http.url(new URL(chapterApiEndPoint + chapterID)).getJSON();
return Http.url(new URI(chapterApiEndPoint + chapterID).toURL()).getJSON();
}

@Override
Expand Down Expand Up @@ -129,8 +131,8 @@ protected List<String> getURLsFromJSON(JSONObject json) {
for (Double aDouble : treeMap.keySet()) {
double key = (double) aDouble;
try {
chapterJSON = Http.url(new URL(chapterApiEndPoint + treeMap.get(key))).getJSON();
} catch (IOException e) {
chapterJSON = Http.url(new URI(chapterApiEndPoint + treeMap.get(key)).toURL()).getJSON();
} catch (IOException | URISyntaxException e) {
e.printStackTrace();
}
sendUpdate(RipStatusMessage.STATUS.LOADING_RESOURCE, "chapter " + key);
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.*;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -137,13 +139,13 @@ public URL sanitizeURL(URL url) throws MalformedURLException {
}

@Override
public void rip() throws IOException {
public void rip() throws IOException, URISyntaxException {
if (this.url.toExternalForm().contains("/videos")) {
RIP_TYPE = RipType.VIDEO;
JSONObject json = getFirstPage();
List<String> URLs = getURLsFromJSON(json);
for (int index = 0; index < URLs.size(); index ++) {
downloadURL(new URL(URLs.get(index)), index);
downloadURL(new URI(URLs.get(index)).toURL(), index);
}
waitForThreads();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@


import com.rarchives.ripme.ripper.rippers.MangadexRipper;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class MangadexRipperTest extends RippersTest{
public class MangadexRipperTest extends RippersTest {
@Test
@Tag("flaky")
public void testRip() throws IOException, URISyntaxException {
MangadexRipper ripper = new MangadexRipper(new URI("https://mangadex.org/chapter/467904/").toURL());
testRipper(ripper);
}
public class testMangaRip extends RippersTest{

public void testRip() throws IOException, URISyntaxException {
MangadexRipper ripper = new MangadexRipper(new URI("https://mangadex.org/title/44625/this-croc-will-die-in-100-days").toURL());
testRipper(ripper);
}
@Test
@Tag("flaky")
public void test2() throws IOException, URISyntaxException {
MangadexRipper ripper = new MangadexRipper(new URI("https://mangadex.org/title/44625/this-croc-will-die-in-100-days").toURL());
testRipper(ripper);
}

}

0 comments on commit 8f279a6

Please sign in to comment.