WordpressComicRipper: fix indentation

This commit is contained in:
MetaPrime 2017-05-09 15:53:13 -07:00
parent c75aad47d4
commit 92405fb9f8

View File

@ -11,155 +11,151 @@ import java.util.regex.Pattern;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AbstractHTMLRipper; import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
public class WordpressComicRipper extends AbstractHTMLRipper { public class WordpressComicRipper extends AbstractHTMLRipper {
public WordpressComicRipper(URL url) throws IOException { public WordpressComicRipper(URL url) throws IOException {
super(url); super(url);
} }
public static List<String> explicit_domains = Arrays.asList("www.totempole666.com", public static List<String> explicit_domains = Arrays.asList("www.totempole666.com",
"buttsmithy.com", "themonsterunderthebed.net", "prismblush.com"); "buttsmithy.com", "themonsterunderthebed.net", "prismblush.com");
@Override
public String getHost() {
String host = url.toExternalForm().split("/")[2];
return host;
}
@Override @Override
public String getDomain() { public String getHost() {
String host = url.toExternalForm().split("/")[2]; String host = url.toExternalForm().split("/")[2];
return host; return host;
} }
@Override @Override
public boolean canRip(URL url) { public String getDomain() {
String url_name = url.toExternalForm(); String host = url.toExternalForm().split("/")[2];
if (explicit_domains.contains(url_name.split("/")[2]) == true) { return host;
Pattern totempole666Pat = Pattern.compile("https?://www\\.totempole666.com/comic/([a-zA-Z0-9_-]*)/?$"); }
Matcher totempole666Mat = totempole666Pat.matcher(url.toExternalForm());
if (totempole666Mat.matches()) {
return true;
}
Pattern buttsmithyPat = Pattern.compile("https?://buttsmithy.com/archives/comic/([a-zA-Z0-9_-]*)/?$"); @Override
Matcher buttsmithyMat = buttsmithyPat.matcher(url.toExternalForm()); public boolean canRip(URL url) {
if (buttsmithyMat.matches()) { String url_name = url.toExternalForm();
return true; if (explicit_domains.contains(url_name.split("/")[2]) == true) {
} Pattern totempole666Pat = Pattern.compile("https?://www\\.totempole666.com/comic/([a-zA-Z0-9_-]*)/?$");
Pattern theMonsterUnderTheBedPat = Pattern.compile("https?://themonsterunderthebed.net/\\?comic=([a-zA-Z0-9_-]*)/?$");
Matcher theMonsterUnderTheBedMat = theMonsterUnderTheBedPat.matcher(url.toExternalForm());
if (theMonsterUnderTheBedMat.matches()) {
return true;
}
Pattern prismblushPat = Pattern.compile("https?://prismblush.com/comic/([a-zA-Z0-9_-]*)/?$");
Matcher prismblushMat = prismblushPat.matcher(url.toExternalForm());
if (prismblushMat.matches()) {
return true;
}
}
return false;
}
@Override
public String getAlbumTitle(URL url) throws MalformedURLException {
Pattern totempole666Pat = Pattern.compile("(?:https?://)?(?:www\\.)?totempole666.com\\/comic/([a-zA-Z0-9_-]*)/?$");
Matcher totempole666Mat = totempole666Pat.matcher(url.toExternalForm()); Matcher totempole666Mat = totempole666Pat.matcher(url.toExternalForm());
if (totempole666Mat.matches()) { if (totempole666Mat.matches()) {
return "totempole666.com" + "_" + "The_cummoner"; return true;
} }
Pattern buttsmithyPat = Pattern.compile("https?://buttsmithy.com/archives/comic/([a-zA-Z0-9_-]*)/?$"); Pattern buttsmithyPat = Pattern.compile("https?://buttsmithy.com/archives/comic/([a-zA-Z0-9_-]*)/?$");
Matcher buttsmithyMat = buttsmithyPat.matcher(url.toExternalForm()); Matcher buttsmithyMat = buttsmithyPat.matcher(url.toExternalForm());
if (buttsmithyMat.matches()) { if (buttsmithyMat.matches()) {
return "buttsmithy.com" + "_" + "Alfie"; return true;
} }
Pattern theMonsterUnderTheBedPat = Pattern.compile("https?://themonsterunderthebed.net/?comic=([a-zA-Z0-9_-]*)/?$"); Pattern theMonsterUnderTheBedPat = Pattern.compile("https?://themonsterunderthebed.net/\\?comic=([a-zA-Z0-9_-]*)/?$");
Matcher theMonsterUnderTheBedMat = theMonsterUnderTheBedPat.matcher(url.toExternalForm()); Matcher theMonsterUnderTheBedMat = theMonsterUnderTheBedPat.matcher(url.toExternalForm());
if (theMonsterUnderTheBedMat.matches()) { if (theMonsterUnderTheBedMat.matches()) {
return "themonsterunderthebed.net_TheMonsterUnderTheBed"; return true;
} }
Pattern prismblushPat = Pattern.compile("https?://prismblush.com/comic/([a-zA-Z0-9_-]*)/?$"); Pattern prismblushPat = Pattern.compile("https?://prismblush.com/comic/([a-zA-Z0-9_-]*)/?$");
Matcher prismblushMat = prismblushPat.matcher(url.toExternalForm()); Matcher prismblushMat = prismblushPat.matcher(url.toExternalForm());
if (prismblushMat.matches()) { if (prismblushMat.matches()) {
return "prismblush.com_" + prismblushMat.group(1).replaceAll("-pg-\\d+", ""); return true;
} }
return super.getAlbumTitle(url);
} }
return false;
@Override
public String getGID(URL url) throws MalformedURLException {
String url_name = url.toExternalForm();
// We shouldn't need to return any GID
if (explicit_domains.contains(url_name.split("/")[2]) == true) {
return "";
}
throw new MalformedURLException("You should never see this error message");
}
@Override
public Document getFirstPage() throws IOException {
// "url" is an instance field of the superclass
return Http.url(url).get();
}
@Override
public Document getNextPage(Document doc) throws IOException {
// Find next page
String nextPage = "";
Element elem = null;
if (explicit_domains.contains("www.totempole666.com") == true
|| explicit_domains.contains("buttsmithy.com") == true
|| explicit_domains.contains("themonsterunderthebed.net")
|| explicit_domains.contains("prismblush.com")) {
elem = doc.select("a.comic-nav-next").first();
if (elem == null) {
throw new IOException("No more pages");
}
nextPage = elem.attr("href");
}
if (nextPage == "") {
throw new IOException("No more pages");
}
else {
return Http.url(nextPage).get();
}
}
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>();
if (explicit_domains.contains("www.totempole666.com") == true
|| explicit_domains.contains("buttsmithy.com") == true
|| explicit_domains.contains("themonsterunderthebed.net")
|| explicit_domains.contains("prismblush.com")) {
Element elem = doc.select("div.comic-table > div#comic > a > img").first();
// If doc is the last page in the comic then elem.attr("src") returns null
// because there is no link <a> to the next page
if (elem == null) {
logger.debug("Got last page in totempole666 comic");
elem = doc.select("div.comic-table > div#comic > img").first();
}
result.add(elem.attr("src"));
}
return result;
}
@Override
public void downloadURL(URL url, int index) {
addURLToDownload(url, getPrefix(index));
}
} }
@Override
public String getAlbumTitle(URL url) throws MalformedURLException {
Pattern totempole666Pat = Pattern.compile("(?:https?://)?(?:www\\.)?totempole666.com\\/comic/([a-zA-Z0-9_-]*)/?$");
Matcher totempole666Mat = totempole666Pat.matcher(url.toExternalForm());
if (totempole666Mat.matches()) {
return "totempole666.com" + "_" + "The_cummoner";
}
Pattern buttsmithyPat = Pattern.compile("https?://buttsmithy.com/archives/comic/([a-zA-Z0-9_-]*)/?$");
Matcher buttsmithyMat = buttsmithyPat.matcher(url.toExternalForm());
if (buttsmithyMat.matches()) {
return "buttsmithy.com" + "_" + "Alfie";
}
Pattern theMonsterUnderTheBedPat = Pattern.compile("https?://themonsterunderthebed.net/?comic=([a-zA-Z0-9_-]*)/?$");
Matcher theMonsterUnderTheBedMat = theMonsterUnderTheBedPat.matcher(url.toExternalForm());
if (theMonsterUnderTheBedMat.matches()) {
return "themonsterunderthebed.net_TheMonsterUnderTheBed";
}
Pattern prismblushPat = Pattern.compile("https?://prismblush.com/comic/([a-zA-Z0-9_-]*)/?$");
Matcher prismblushMat = prismblushPat.matcher(url.toExternalForm());
if (prismblushMat.matches()) {
return "prismblush.com_" + prismblushMat.group(1).replaceAll("-pg-\\d+", "");
}
return super.getAlbumTitle(url);
}
@Override
public String getGID(URL url) throws MalformedURLException {
String url_name = url.toExternalForm();
// We shouldn't need to return any GID
if (explicit_domains.contains(url_name.split("/")[2]) == true) {
return "";
}
throw new MalformedURLException("You should never see this error message");
}
@Override
public Document getFirstPage() throws IOException {
// "url" is an instance field of the superclass
return Http.url(url).get();
}
@Override
public Document getNextPage(Document doc) throws IOException {
// Find next page
String nextPage = "";
Element elem = null;
if (explicit_domains.contains("www.totempole666.com") == true
|| explicit_domains.contains("buttsmithy.com") == true
|| explicit_domains.contains("themonsterunderthebed.net")
|| explicit_domains.contains("prismblush.com")) {
elem = doc.select("a.comic-nav-next").first();
if (elem == null) {
throw new IOException("No more pages");
}
nextPage = elem.attr("href");
}
if (nextPage == "") {
throw new IOException("No more pages");
} else {
return Http.url(nextPage).get();
}
}
@Override
public List<String> getURLsFromPage(Document doc) {
List<String> result = new ArrayList<String>();
if (explicit_domains.contains("www.totempole666.com") == true
|| explicit_domains.contains("buttsmithy.com") == true
|| explicit_domains.contains("themonsterunderthebed.net")
|| explicit_domains.contains("prismblush.com")) {
Element elem = doc.select("div.comic-table > div#comic > a > img").first();
// If doc is the last page in the comic then elem.attr("src") returns null
// because there is no link <a> to the next page
if (elem == null) {
logger.debug("Got last page in totempole666 comic");
elem = doc.select("div.comic-table > div#comic > img").first();
}
result.add(elem.attr("src"));
}
return result;
}
@Override
public void downloadURL(URL url, int index) {
addURLToDownload(url, getPrefix(index));
}
}