refactored code to cut down on repeat code

This commit is contained in:
cyian-1756 2018-09-13 07:27:27 -04:00
parent 26e27a9ed5
commit d945a51c4d
2 changed files with 27 additions and 27 deletions

View File

@ -12,6 +12,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import com.rarchives.ripme.ui.RipStatusMessage;
import com.rarchives.ripme.utils.RipUtils;
import com.rarchives.ripme.utils.Utils;
import org.json.JSONArray;
import org.json.JSONObject;
@ -31,7 +32,7 @@ public class TsuminoRipper extends AbstractHTMLRipper {
super(url);
}
private List<String> getTags(Document doc) {
public List<String> getTags(Document doc) {
List<String> tags = new ArrayList<>();
LOGGER.info("Getting tags");
for (Element tag : doc.select("div#Tag > a")) {
@ -41,31 +42,6 @@ public class TsuminoRipper extends AbstractHTMLRipper {
return tags;
}
/**
* Checks for blacklisted tags on page. If it finds one it returns it, if not it return null
*
* @param doc
* @return String
*/
public String checkTags(Document doc, String[] blackListedTags) {
// If the user hasn't blacklisted any tags we return null;
if (blackListedTags == null) {
return null;
}
LOGGER.info("Blacklisted tags " + blackListedTags[0]);
List<String> tagsOnPage = getTags(doc);
for (String tag : blackListedTags) {
for (String pageTag : tagsOnPage) {
// We replace all dashes in the tag with spaces because the tags we get from the site are separated using
// dashes
if (tag.trim().toLowerCase().equals(pageTag.toLowerCase())) {
return tag.toLowerCase();
}
}
}
return null;
}
private JSONArray getPageUrls() {
String postURL = "http://www.tsumino.com/Read/Load";
try {
@ -124,7 +100,7 @@ public class TsuminoRipper extends AbstractHTMLRipper {
Connection.Response resp = Http.url(url).response();
cookies.putAll(resp.cookies());
Document doc = resp.parse();
String blacklistedTag = checkTags(doc, Utils.getConfigStringArray("tsumino.blacklist.tags"));
String blacklistedTag = RipUtils.checkTags(Utils.getConfigStringArray("tsumino.blacklist.tags"), getTags(doc));
if (blacklistedTag != null) {
sendUpdate(RipStatusMessage.STATUS.DOWNLOAD_WARN, "Skipping " + url.toExternalForm() + " as it " +
"contains the blacklisted tag \"" + blacklistedTag + "\"");

View File

@ -305,4 +305,28 @@ public class RipUtils {
}
return cookies;
}
/**
* Checks for blacklisted tags on page. If it finds one it returns it, if not it return null
*
* @param blackListedTags a string array of the blacklisted tags
* @param tagsOnPage the tags on the page
* @return String
*/
public static String checkTags(String[] blackListedTags, List<String> tagsOnPage) {
// If the user hasn't blacklisted any tags we return null;
if (blackListedTags == null) {
return null;
}
for (String tag : blackListedTags) {
for (String pageTag : tagsOnPage) {
// We replace all dashes in the tag with spaces because the tags we get from the site are separated using
// dashes
if (tag.trim().toLowerCase().equals(pageTag.toLowerCase())) {
return tag.toLowerCase();
}
}
}
return null;
}
}