<commit_before>package com.rarchives.ripme.ripper.rippers;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
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 org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.ripper.DownloadThreadPool;
import com.rarchives.ripme.utils.Http;

public class FuraffinityRipper extends AbstractHTMLRipper {

	static Map<String, String> cookies;
	static final String urlBase = "http://www.furaffinity.net";

	// Thread pool for finding direct image links from "image" pages (html)
	private DownloadThreadPool furaffinityThreadPool = new DownloadThreadPool(
			"furaffinity");

	@Override
	public DownloadThreadPool getThreadPool() {
		return furaffinityThreadPool;
	}

	public FuraffinityRipper(URL url) throws IOException {
		super(url);
	}

	@Override
	public String getDomain() {
		return "furaffinity.net";
	}

	@Override
	public String getHost() {
		return "furaffinity";
	}

	@Override
	public Document getFirstPage() throws IOException {
		if (cookies == null || cookies.size() == 0) {
			String a = JOptionPane.showInputDialog("Value of a-cookie");
			String b = JOptionPane.showInputDialog("Value of b-cookie");

			cookies = new HashMap<String, String>();
			cookies.put("a", a);
			cookies.put("b", b);
		}

		return Http.url(url).cookies(cookies).get();
	}

	@Override
	public Document getNextPage(Document doc) throws IOException {
		// Find next page
		Elements nextPageUrl = doc.select("td[align=right] form");
		String nextUrl = urlBase+nextPageUrl.first().attr("action");
		if (nextPageUrl.size() == 0) {
			throw new IOException("No more pages");
		}
		sleep(500);<commit_msg>Trying to changed code to login the user instead of manually supplying cookie values.<commit_after>package com.rarchives.ripme.ripper.rippers;

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;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import com.rarchives.ripme.ripper.AbstractHTMLRipper;
import com.rarchives.ripme.ripper.DownloadThreadPool;
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";

	// Thread pool for finding direct image links from "image" pages (html)
	private DownloadThreadPool furaffinityThreadPool = new DownloadThreadPool(
			"furaffinity");

	@Override
	public DownloadThreadPool getThreadPool() {
		return furaffinityThreadPool;
	}

	public FuraffinityRipper(URL url) throws IOException {
		super(url);
	}

	@Override
	public String getDomain() {
		return "furaffinity.net";
	}

	@Override
	public String getHost() {
		return "furaffinity";
	}

	@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());

			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", <PASSWORD>);
			formData.put("login", "Login to FurAffinity");
			
			Response doLogin=Http.url(urlBase+"/login/")
					.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
	public Document getNextPage(Document doc) throws IOException {
		// Find next page
		Elements nextPageUrl = doc.select("td[align=right] form");
		String nextUrl = urlBase+nextPageUrl.first().attr("action");
		if (nextPageUrl.size() == 0) {
			throw new IOException("No more pages");
		}
		sleep(500);
{'fraction_non_alphanumeric': 0.12463887742468015, 'fraction_numerical': 0.002269913330581923, 'mean_word_length': 4.969211822660099, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1695719', 'n_tokens_mistral': 1663, 'n_tokens_neox': 1507, 'n_words': 336}