mirror of
https://github.com/RipMeApp/ripme.git
synced 2025-08-27 15:49:50 +02:00
Merge pull request #1136 from 0x1f595/jabarchives
Updating Jab Archives ripper to add image title
This commit is contained in:
@@ -7,6 +7,12 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.text.Normalizer;
|
||||||
|
import java.text.Normalizer.Form;
|
||||||
|
|
||||||
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
|
||||||
import com.rarchives.ripme.utils.Http;
|
import com.rarchives.ripme.utils.Http;
|
||||||
@@ -17,6 +23,11 @@ import org.jsoup.select.Elements;
|
|||||||
|
|
||||||
public class JabArchivesRipper extends AbstractHTMLRipper {
|
public class JabArchivesRipper extends AbstractHTMLRipper {
|
||||||
|
|
||||||
|
private static final Pattern NONLATIN = Pattern.compile("[^\\w-]");
|
||||||
|
private static final Pattern WHITESPACE = Pattern.compile("[\\s]");
|
||||||
|
|
||||||
|
private Map<String, String> itemPrefixes = Collections.synchronizedMap(new HashMap<String, String>());
|
||||||
|
|
||||||
public JabArchivesRipper(URL url) throws IOException {
|
public JabArchivesRipper(URL url) throws IOException {
|
||||||
super(url);
|
super(url);
|
||||||
}
|
}
|
||||||
@@ -62,17 +73,29 @@ public class JabArchivesRipper extends AbstractHTMLRipper {
|
|||||||
return Http.url(nextUrl).get();
|
return Http.url(nextUrl).get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getSlug(String input) {
|
||||||
|
// Get a URL/file-safe version of a string
|
||||||
|
String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
|
||||||
|
String normalized = Normalizer.normalize(nowhitespace, Form.NFD);
|
||||||
|
String slug = NONLATIN.matcher(normalized).replaceAll("");
|
||||||
|
return slug.toLowerCase(Locale.ENGLISH);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> getURLsFromPage(Document doc) {
|
public List<String> getURLsFromPage(Document doc) {
|
||||||
List<String> result = new ArrayList<String>();
|
List<String> result = new ArrayList<String>();
|
||||||
for (Element el : doc.select("#contentMain img")) {
|
for (Element el : doc.select("#contentMain img")) {
|
||||||
result.add("https://jabarchives.com" + el.attr("src").replace("thumb", "large"));
|
String url = "https://jabarchives.com" + el.attr("src").replace("thumb", "large");
|
||||||
|
result.add(url);
|
||||||
|
|
||||||
|
String title = el.parent().attr("title");
|
||||||
|
itemPrefixes.put(url, getSlug(title) + "_");
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void downloadURL(URL url, int index) {
|
public void downloadURL(URL url, int index) {
|
||||||
addURLToDownload(url, getPrefix(index));
|
addURLToDownload(url, itemPrefixes.get(url.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user