Missing braces, various cleanup.

This commit is contained in:
MetaPrime 2017-05-09 16:07:20 -07:00
parent 92405fb9f8
commit cd8784ed85
5 changed files with 130 additions and 141 deletions

View File

@ -1,101 +1,101 @@
package com.rarchives.ripme.ripper.rippers; package com.rarchives.ripme.ripper.rippers;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; 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 org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
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 FapprovedRipper extends AbstractHTMLRipper { public class FapprovedRipper extends AbstractHTMLRipper {
private int pageIndex = 1; private int pageIndex = 1;
private String username = null; private String username = null;
public FapprovedRipper(URL url) throws IOException { public FapprovedRipper(URL url) throws IOException {
super(url); super(url);
} }
@Override @Override
public String getHost() { public String getHost() {
return "fapproved"; return "fapproved";
} }
@Override @Override
public String getDomain() { public String getDomain() {
return "fapproved.com"; return "fapproved.com";
} }
@Override @Override
public String getGID(URL url) throws MalformedURLException { public String getGID(URL url) throws MalformedURLException {
Pattern p = Pattern.compile("^https?://[w.]*fapproved.com/users/([a-zA-Z0-9\\-_]{3,}).*$"); Pattern p = Pattern.compile("^https?://[w.]*fapproved.com/users/([a-zA-Z0-9\\-_]{3,}).*$");
Matcher m = p.matcher(url.toExternalForm()); Matcher m = p.matcher(url.toExternalForm());
if (m.matches()) { if (m.matches()) {
username = m.group(1); username = m.group(1);
return username; return username;
} }
throw new MalformedURLException("Fapproved user not found in " + url + ", expected http://fapproved.com/users/username/images"); throw new MalformedURLException("Fapproved user not found in " + url + ", expected http://fapproved.com/users/username/images");
} }
@Override @Override
public URL sanitizeURL(URL url) throws MalformedURLException { public URL sanitizeURL(URL url) throws MalformedURLException {
return new URL("http://fapproved.com/users/" + getGID(url)); return new URL("http://fapproved.com/users/" + getGID(url));
} }
@Override @Override
public Document getFirstPage() throws IOException { public Document getFirstPage() throws IOException {
pageIndex = 1; pageIndex = 1;
String pageURL = getPageURL(pageIndex); String pageURL = getPageURL(pageIndex);
return Http.url(pageURL) return Http.url(pageURL)
.ignoreContentType() .ignoreContentType()
.get(); .get();
} }
@Override @Override
public Document getNextPage(Document doc) throws IOException { public Document getNextPage(Document doc) throws IOException {
if ( (doc.select("div.pagination li.next.disabled").size() != 0) if ((doc.select("div.pagination li.next.disabled").size() != 0)
|| (doc.select("div.pagination").size() == 0) ) { || (doc.select("div.pagination").size() == 0)) {
throw new IOException("No more pages found"); throw new IOException("No more pages found");
} }
sleep(1000); sleep(1000);
pageIndex++; pageIndex++;
String pageURL = getPageURL(pageIndex); String pageURL = getPageURL(pageIndex);
return Http.url(pageURL) return Http.url(pageURL)
.ignoreContentType() .ignoreContentType()
.get(); .get();
} }
private String getPageURL(int index) throws IOException { private String getPageURL(int index) throws IOException {
if (username == null) { if (username == null) {
username = getGID(this.url); username = getGID(this.url);
} }
return "http://fapproved.com/users/" + username + "/images?page=" + pageIndex; return "http://fapproved.com/users/" + username + "/images?page=" + pageIndex;
} }
@Override @Override
public List<String> getURLsFromPage(Document page) { public List<String> getURLsFromPage(Document page) {
List<String> imageURLs = new ArrayList<String>(); List<String> imageURLs = new ArrayList<String>();
for (Element image : page.select("div.actual-image img")) { for (Element image : page.select("div.actual-image img")) {
String imageURL = image.attr("src"); String imageURL = image.attr("src");
if (imageURL.startsWith("//")) { if (imageURL.startsWith("//")) {
imageURL = "http:" + imageURL; imageURL = "http:" + imageURL;
} }
else if (imageURL.startsWith("/")) { else if (imageURL.startsWith("/")) {
imageURL = "http://fapproved.com" + imageURL; imageURL = "http://fapproved.com" + imageURL;
} }
imageURLs.add(imageURL); imageURLs.add(imageURL);
} }
return imageURLs; return imageURLs;
} }
@Override @Override
public void downloadURL(URL url, int index) { public void downloadURL(URL url, int index) {
addURLToDownload(url, getPrefix(index)); addURLToDownload(url, getPrefix(index));
} }
} }

View File

@ -4,7 +4,6 @@ import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -14,10 +13,8 @@ import java.util.regex.Pattern;
import org.jsoup.Connection.Response; import org.jsoup.Connection.Response;
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.ui.RipStatusMessage.STATUS;
import com.rarchives.ripme.utils.Http; import com.rarchives.ripme.utils.Http;
public class ZizkiRipper extends AbstractHTMLRipper { public class ZizkiRipper extends AbstractHTMLRipper {

View File

@ -3,23 +3,27 @@ package com.rarchives.ripme.ripper.rippers.ripperhelpers;
import java.util.List; import java.util.List;
public class ChanSite { public class ChanSite {
//The domains where the threads are hosted. // The domains where the threads are hosted.
public List<String> domains; public List<String> domains;
//The domains where the images are hosted. // The domains where the images are hosted.
public List<String> cdnDomains; public List<String> cdnDomains;
public ChanSite(List<String> Domains, List<String> CdnDomains){ public ChanSite(List<String> Domains, List<String> CdnDomains) {
if(Domains.isEmpty()) if (Domains.isEmpty()) {
throw new IllegalArgumentException("Domains"); throw new IllegalArgumentException("Domains");
if(CdnDomains.isEmpty()) }
if (CdnDomains.isEmpty()) {
throw new IllegalArgumentException("CdnDomains"); throw new IllegalArgumentException("CdnDomains");
}
domains = Domains; domains = Domains;
cdnDomains = CdnDomains; cdnDomains = CdnDomains;
} }
public ChanSite(List<String> Domains){
if(Domains.isEmpty()) public ChanSite(List<String> Domains) {
throw new IllegalArgumentException("Domains"); if (Domains.isEmpty()) {
throw new IllegalArgumentException("Domains");
}
domains = Domains; domains = Domains;
cdnDomains = Domains; cdnDomains = Domains;
} }
} }

View File

@ -164,18 +164,6 @@ public class RipUtils {
if (url == null) url = urlFromSiteDirectoryName(dir, "vinebox", "http://finebox.co/u/", ""); if (url == null) url = urlFromSiteDirectoryName(dir, "vinebox", "http://finebox.co/u/", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "imgbox", "http://imgbox.com/g/", ""); if (url == null) url = urlFromSiteDirectoryName(dir, "imgbox", "http://imgbox.com/g/", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "modelmayhem", "http://www.modelmayhem.com/", ""); if (url == null) url = urlFromSiteDirectoryName(dir, "modelmayhem", "http://www.modelmayhem.com/", "");
/*
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
if (url == null) url = urlFromSiteDirectoryName(dir, "", "", "");
*/
//if (url == null) url = urlFromSiteDirectoryName(dir, "8muses", "http://www.8muses.com/index/category/", ""); //if (url == null) url = urlFromSiteDirectoryName(dir, "8muses", "http://www.8muses.com/index/category/", "");
return url; return url;
} }
@ -247,9 +235,8 @@ public class RipUtils {
List<String> fields = Arrays.asList(dir.split("_")); List<String> fields = Arrays.asList(dir.split("_"));
String album = fields.get(1); String album = fields.get(1);
String url = "http://"; String url = "http://";
if ( (fields.contains("top") || fields.contains("new")) if ((fields.contains("top") || fields.contains("new"))
&& (fields.contains("year") || fields.contains("month") || fields.contains("week") || fields.contains("all")) && (fields.contains("year") || fields.contains("month") || fields.contains("week") || fields.contains("all"))) {
) {
// Subreddit // Subreddit
fields.remove(0); // "imgur" fields.remove(0); // "imgur"
String sub = ""; String sub = "";

View File

@ -34,7 +34,6 @@ import com.rarchives.ripme.ripper.AbstractRipper;
* Common utility functions used in various places throughout the project. * Common utility functions used in various places throughout the project.
*/ */
public class Utils { public class Utils {
public static final String RIP_DIRECTORY = "rips"; public static final String RIP_DIRECTORY = "rips";
private static final String configFile = "rip.properties"; private static final String configFile = "rip.properties";
private static final Logger logger = Logger.getLogger(Utils.class); private static final Logger logger = Logger.getLogger(Utils.class);
@ -50,7 +49,7 @@ public class Utils {
} }
config = new PropertiesConfiguration(configPath); config = new PropertiesConfiguration(configPath);
logger.info("Loaded " + config.getPath()); logger.info("Loaded " + config.getPath());
if (f.exists()){ if (f.exists()) {
// Config was loaded from file // Config was loaded from file
if ( !config.containsKey("twitter.auth") if ( !config.containsKey("twitter.auth")
|| !config.containsKey("twitter.max_requests") || !config.containsKey("twitter.max_requests")
@ -171,16 +170,18 @@ public class Utils {
public static String stripURLParameter(String url, String parameter) { public static String stripURLParameter(String url, String parameter) {
int paramIndex = url.indexOf("?" + parameter); int paramIndex = url.indexOf("?" + parameter);
boolean wasFirstParam = true; boolean wasFirstParam = true;
if(paramIndex < 0) { if (paramIndex < 0) {
wasFirstParam = false; wasFirstParam = false;
paramIndex = url.indexOf("&" + parameter); paramIndex = url.indexOf("&" + parameter);
} }
if(paramIndex > 0) { if (paramIndex > 0) {
int nextParam = url.indexOf("&", paramIndex+1); int nextParam = url.indexOf("&", paramIndex+1);
if(nextParam != -1) { if (nextParam != -1) {
String c = "&"; String c = "&";
if(wasFirstParam) c = "?"; if (wasFirstParam) {
c = "?";
}
url = url.substring(0, paramIndex) + c + url.substring(nextParam+1, url.length()); url = url.substring(0, paramIndex) + c + url.substring(nextParam+1, url.length());
} else { } else {
url = url.substring(0, paramIndex); url = url.substring(0, paramIndex);
@ -253,7 +254,7 @@ public class Utils {
while(entries.hasMoreElements()) { while(entries.hasMoreElements()) {
JarEntry nextElement = entries.nextElement(); JarEntry nextElement = entries.nextElement();
String entryName = nextElement.getName(); String entryName = nextElement.getName();
if(entryName.startsWith(relPath) if (entryName.startsWith(relPath)
&& entryName.length() > (relPath.length() + "/".length()) && entryName.length() > (relPath.length() + "/".length())
&& !nextElement.isDirectory()) { && !nextElement.isDirectory()) {
String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", ""); String className = entryName.replace('/', '.').replace('\\', '.').replace(".class", "");
@ -401,7 +402,7 @@ public class Utils {
public static Map<String,String> parseUrlQuery(String query) { public static Map<String,String> parseUrlQuery(String query) {
Map<String,String> res = new HashMap<String, String>(); Map<String,String> res = new HashMap<String, String>();
if (query.equals("")){ if (query.equals("")) {
return res; return res;
} }
@ -410,9 +411,9 @@ public class Utils {
try { try {
for (String part : parts) { for (String part : parts) {
if ((pos = part.indexOf('=')) >= 0){ if ((pos = part.indexOf('=')) >= 0) {
res.put(URLDecoder.decode(part.substring(0, pos), "UTF-8"), URLDecoder.decode(part.substring(pos + 1), "UTF-8")); res.put(URLDecoder.decode(part.substring(0, pos), "UTF-8"), URLDecoder.decode(part.substring(pos + 1), "UTF-8"));
}else{ } else {
res.put(URLDecoder.decode(part, "UTF-8"), ""); res.put(URLDecoder.decode(part, "UTF-8"), "");
} }
} }
@ -434,7 +435,7 @@ public class Utils {
* @return The associated value or null if key wasn't found * @return The associated value or null if key wasn't found
*/ */
public static String parseUrlQuery(String query, String key) { public static String parseUrlQuery(String query, String key) {
if (query.equals("")){ if (query.equals("")) {
return null; return null;
} }
@ -444,7 +445,7 @@ public class Utils {
try { try {
for (String part : parts) { for (String part : parts) {
if ((pos = part.indexOf('=')) >= 0) { if ((pos = part.indexOf('=')) >= 0) {
if (URLDecoder.decode(part.substring(0, pos), "UTF-8").equals(key)){ if (URLDecoder.decode(part.substring(0, pos), "UTF-8").equals(key)) {
return URLDecoder.decode(part.substring(pos + 1), "UTF-8"); return URLDecoder.decode(part.substring(pos + 1), "UTF-8");
} }