From d945a51c4d4881998ca4bc1bb7c7d0f54a2ab9f5 Mon Sep 17 00:00:00 2001 From: cyian-1756 Date: Thu, 13 Sep 2018 07:27:27 -0400 Subject: [PATCH] refactored code to cut down on repeat code --- .../ripme/ripper/rippers/TsuminoRipper.java | 30 ++----------------- .../com/rarchives/ripme/utils/RipUtils.java | 24 +++++++++++++++ 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/rarchives/ripme/ripper/rippers/TsuminoRipper.java b/src/main/java/com/rarchives/ripme/ripper/rippers/TsuminoRipper.java index 8855ec16..529b08d9 100644 --- a/src/main/java/com/rarchives/ripme/ripper/rippers/TsuminoRipper.java +++ b/src/main/java/com/rarchives/ripme/ripper/rippers/TsuminoRipper.java @@ -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 getTags(Document doc) { + public List getTags(Document doc) { List 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 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 + "\""); diff --git a/src/main/java/com/rarchives/ripme/utils/RipUtils.java b/src/main/java/com/rarchives/ripme/utils/RipUtils.java index f0752c06..5dea166b 100644 --- a/src/main/java/com/rarchives/ripme/utils/RipUtils.java +++ b/src/main/java/com/rarchives/ripme/utils/RipUtils.java @@ -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 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; + } }