mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-09-02 10:23:47 +02:00
reformat mangadex
This commit is contained in:
@@ -1,39 +1,40 @@
|
|||||||
package com.rarchives.ripme.ripper.rippers;
|
package com.rarchives.ripme.ripper.rippers;
|
||||||
|
|
||||||
import com.rarchives.ripme.ripper.AbstractJSONRipper;
|
import com.rarchives.ripme.ripper.AbstractJSONRipper;
|
||||||
import com.rarchives.ripme.ui.History;
|
|
||||||
import com.rarchives.ripme.ui.RipStatusMessage;
|
import com.rarchives.ripme.ui.RipStatusMessage;
|
||||||
import com.rarchives.ripme.utils.Http;
|
import com.rarchives.ripme.utils.Http;
|
||||||
import com.rarchives.ripme.utils.Utils;
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.jsoup.Connection;
|
|
||||||
import org.jsoup.nodes.Document;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.TreeMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class MangadexRipper extends AbstractJSONRipper {
|
public class MangadexRipper extends AbstractJSONRipper {
|
||||||
private String chapterApiEndPoint = "https://mangadex.org/api/chapter/";
|
private final String chapterApiEndPoint = "https://mangadex.org/api/chapter/";
|
||||||
private String mangaApiEndPoint = "https://mangadex.org/api/manga/";
|
private final String mangaApiEndPoint = "https://mangadex.org/api/manga/";
|
||||||
private boolean isSingleChapter;
|
private boolean isSingleChapter;
|
||||||
private String getImageUrl(String chapterHash, String imageName, String server) {
|
|
||||||
return server + chapterHash + "/" + imageName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MangadexRipper(URL url) throws IOException {
|
public MangadexRipper(URL url) throws IOException {
|
||||||
super(url);
|
super(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getImageUrl(String chapterHash, String imageName, String server) {
|
||||||
|
return server + chapterHash + "/" + imageName;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getHost() {
|
public String getHost() {
|
||||||
return "mangadex";
|
return "mangadex";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDomain() {
|
public String getDomain() {
|
||||||
return "mangadex.org";
|
return "mangadex.org";
|
||||||
@@ -51,9 +52,7 @@ public class MangadexRipper extends AbstractJSONRipper {
|
|||||||
if (capID != null) {
|
if (capID != null) {
|
||||||
isSingleChapter = true;
|
isSingleChapter = true;
|
||||||
return capID;
|
return capID;
|
||||||
}
|
} else if (mangaID != null) {
|
||||||
else
|
|
||||||
if(mangaID!=null){
|
|
||||||
isSingleChapter = false;
|
isSingleChapter = false;
|
||||||
return mangaID;
|
return mangaID;
|
||||||
}
|
}
|
||||||
@@ -68,6 +67,7 @@ public class MangadexRipper extends AbstractJSONRipper {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMangaID(String url) {
|
private String getMangaID(String url) {
|
||||||
Pattern p = Pattern.compile("https://mangadex.org/title/([\\d]+)/(.+)");
|
Pattern p = Pattern.compile("https://mangadex.org/title/([\\d]+)/(.+)");
|
||||||
Matcher m = p.matcher(url);
|
Matcher m = p.matcher(url);
|
||||||
@@ -85,8 +85,7 @@ public class MangadexRipper extends AbstractJSONRipper {
|
|||||||
String mangaID = getMangaID(url.toExternalForm());
|
String mangaID = getMangaID(url.toExternalForm());
|
||||||
if (mangaID != null) {
|
if (mangaID != null) {
|
||||||
return Http.url(new URL(mangaApiEndPoint + mangaID)).getJSON();
|
return Http.url(new URL(mangaApiEndPoint + mangaID)).getJSON();
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return Http.url(new URL(chapterApiEndPoint + chapterID)).getJSON();
|
return Http.url(new URL(chapterApiEndPoint + chapterID)).getJSON();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +111,7 @@ public class MangadexRipper extends AbstractJSONRipper {
|
|||||||
Iterator<String> keys = chaptersJSON.keys();
|
Iterator<String> keys = chaptersJSON.keys();
|
||||||
HashMap<Double, String> chapterIDs = new HashMap<>();
|
HashMap<Double, String> chapterIDs = new HashMap<>();
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
String keyValue = (String) keys.next();
|
String keyValue = keys.next();
|
||||||
temp = (JSONObject) chaptersJSON.get(keyValue);
|
temp = (JSONObject) chaptersJSON.get(keyValue);
|
||||||
if (temp.getString("lang_name").equals("English")) {
|
if (temp.getString("lang_name").equals("English")) {
|
||||||
chapterIDs.put(temp.getDouble("chapter"), keyValue);
|
chapterIDs.put(temp.getDouble("chapter"), keyValue);
|
||||||
|
Reference in New Issue
Block a user