Can now blacklist nhentai tags

This commit is contained in:
cyian-1756 2018-05-13 12:12:23 -04:00
parent 34425361ae
commit aca2d24a65
2 changed files with 51 additions and 0 deletions

View File

@ -2,6 +2,7 @@ package com.rarchives.ripme.ripper.rippers;
import com.rarchives.ripme.ripper.AbstractHTMLRipper; import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.ripper.DownloadThreadPool; import com.rarchives.ripme.ripper.DownloadThreadPool;
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 com.rarchives.ripme.utils.Utils;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
@ -64,6 +65,39 @@ public class NhentaiRipper extends AbstractHTMLRipper {
return "nhentai" + title; return "nhentai" + title;
} }
private List<String> getTags(Document doc) {
List<String> tags = new ArrayList<>();
for (Element tag : doc.select("a.tag")) {
tags.add(tag.attr("href").replaceAll("/tag/", "").replaceAll("/", ""));
}
return tags;
}
/**
* Checks for blacklisted tags on page. If it finds one it returns it, if not it return null
*
* @param doc
* @return String
*/
private String checkTags(Document doc) {
String[] blackListedTags = Utils.getConfigStringArray("nhentai.blacklist.tags");
// If the user hasn't blacklisted any tags we return false;
if (blackListedTags == null) {
return null;
}
logger.info("Blacklisted tags " + blackListedTags[0]);
List<String> tagsOnPage = getTags(doc);
for (String tag : blackListedTags) {
for (String pageTag : tagsOnPage) {
logger.info("tag: " + tag + " pageTag: " + pageTag);
if (tag.trim().toLowerCase().equals(pageTag.toLowerCase())) {
return tag;
}
}
}
return null;
}
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
// Ex: https://nhentai.net/g/159174/ // Ex: https://nhentai.net/g/159174/
@ -82,6 +116,13 @@ public class NhentaiRipper extends AbstractHTMLRipper {
if (firstPage == null) { if (firstPage == null) {
firstPage = Http.url(url).get(); firstPage = Http.url(url).get();
} }
String blacklistedTag = checkTags(firstPage);
if (blacklistedTag != null) {
sendUpdate(RipStatusMessage.STATUS.DOWNLOAD_WARN, "Skipping " + url.toExternalForm() + " as it " +
"contains the blacklisted tag \"" + blacklistedTag + "\"");
return null;
}
return firstPage; return firstPage;
} }

View File

@ -92,6 +92,16 @@ public class Utils {
public static String getConfigString(String key, String defaultValue) { public static String getConfigString(String key, String defaultValue) {
return config.getString(key, defaultValue); return config.getString(key, defaultValue);
} }
public static String[] getConfigStringArray(String key) {
String[] s = config.getStringArray(key);
if (s.length == 0) {
return null;
} else {
return s;
}
}
public static int getConfigInteger(String key, int defaultValue) { public static int getConfigInteger(String key, int defaultValue) {
return config.getInt(key, defaultValue); return config.getInt(key, defaultValue);
} }