Fixed furaffinity ripper. #84

Logs in correctly via https.
Spaces instead of tabs.
No more warnings.
This commit is contained in:
4pr0n 2014-06-27 23:20:52 -07:00
parent 9e40e55ee9
commit b0e5fa8cb0

View File

@ -4,16 +4,12 @@ import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;
import org.jsoup.Connection.Method;
import org.jsoup.Connection.Response;
import org.jsoup.nodes.Document;
@ -22,16 +18,17 @@ import org.jsoup.select.Elements;
import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.ripper.DownloadThreadPool;
import com.rarchives.ripme.utils.Base64;
import com.rarchives.ripme.utils.Http;
public class FuraffinityRipper extends AbstractHTMLRipper {
static Map<String, String> cookies=null;
static final String urlBase = "http://www.furaffinity.net";
static final String urlBase = "https://www.furaffinity.net";
// Thread pool for finding direct image links from "image" pages (html)
private DownloadThreadPool furaffinityThreadPool = new DownloadThreadPool(
"furaffinity");
private DownloadThreadPool furaffinityThreadPool
= new DownloadThreadPool( "furaffinity");
@Override
public DownloadThreadPool getThreadPool() {
@ -55,35 +52,35 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
@Override
public Document getFirstPage() throws IOException {
if (cookies == null || cookies.size() == 0) {
JPasswordField passwordField=new JPasswordField();
String user = JOptionPane.showInputDialog("Username");
JOptionPane.showMessageDialog(null,passwordField,"Password",JOptionPane.QUESTION_MESSAGE|JOptionPane.OK_OPTION);
String pass = Arrays.toString(passwordField.getPassword());
login();
}
return Http.url(url).cookies(cookies).get();
}
private void login() throws IOException {
String user = new String(Base64.decode("cmlwbWU="));
String pass = new String(Base64.decode("cmlwbWVwYXNzd29yZA=="));
Response loginPage = Http.url(urlBase + "/login/")
.referrer(urlBase)
.response();
cookies = loginPage.cookies();
System.out.println("Cookies: "+cookies);
Map<String,String> formData = new HashMap<String,String>();
formData.put("action", "login");
formData.put("retard_protection", "1");
formData.put("name", user);
formData.put("pass", pass);
formData.put("login", "Login to FurAffinity");
formData.put("login", "Login to FurAffinity");
Response doLogin=Http.url(urlBase+"/login/?ref=http://www.furaffinity.net/")
Response doLogin = Http.url(urlBase + "/login/?ref=" + url)
.referrer(urlBase + "/login/")
.cookies(cookies)
.data(formData)
.method(Method.POST)
.response();
cookies.putAll(doLogin.cookies());
System.out.println("Cookies: "+cookies);
}
return Http.url(url).cookies(cookies).get();
}
@Override
@ -116,8 +113,7 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
@Override
public void downloadURL(URL url, int index) {
furaffinityThreadPool.addThread(new FuraffinityDocumentThread(url,
index));
furaffinityThreadPool.addThread(new FuraffinityDocumentThread(url));
sleep(250);
}
@ -136,12 +132,10 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
private class FuraffinityDocumentThread extends Thread {
private URL url;
private int index;
public FuraffinityDocumentThread(URL url, int index) {
public FuraffinityDocumentThread(URL url) {
super();
this.url = url;
this.index = index;
}
@Override
@ -158,8 +152,7 @@ public class FuraffinityRipper extends AbstractHTMLRipper {
logger.info("Found URL " + link);
addURLToDownload(new URL(link),"","",url.toExternalForm(),cookies);
} catch (IOException e) {
logger.error("[!] Exception while loading/parsing " + this.url,
e);
logger.error("[!] Exception while loading/parsing " + this.url, e);
}
}
}