1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-06 07:32:50 +00:00

Implements CaptchaTrader service

This commit is contained in:
2012-01-17 12:28:22 -02:00
parent e943b08ede
commit 08d22a12fe
81 changed files with 2750 additions and 543 deletions

View File

@@ -10,11 +10,4 @@
<groupId>com.rogiel.httpchannel.services</groupId>
<name>HttpChannel/Service/UploadHere</name>
<description>Provides upload access to uploadhere.com</description>
<dependencies>
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-captcha-recaptcha</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</project>

View File

@@ -6,8 +6,8 @@ import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import com.rogiel.httpchannel.captcha.impl.AjaxReCaptchaService;
import com.rogiel.httpchannel.captcha.impl.ReCaptcha;
import com.rogiel.httpchannel.captcha.ImageCaptcha;
import com.rogiel.httpchannel.captcha.ReCaptchaExtractor;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
@@ -67,8 +67,6 @@ public class UploadHereService extends AbstractHttpService implements Service,
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
private final AjaxReCaptchaService captchaService = new AjaxReCaptchaService();
@Override
public ServiceID getID() {
return SERVICE_ID;
@@ -190,6 +188,9 @@ public class UploadHereService extends AbstractHttpService implements Service,
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
new Object[] { url, userCookie, uploadID });
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url).parameter("file_0", channel)
.parameter("u", userCookie)
@@ -202,6 +203,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
try {
final String linkId = PatternUtils.find(DOWNLOAD_ID_PATTERN,
uploadFuture.get(), 1);
logger.debug("Upload to uploadhere.com finished");
if (linkId == null)
return null;
return new StringBuilder("http://www.uploadhere.com/").append(
@@ -230,15 +232,24 @@ public class UploadHereService extends AbstractHttpService implements Service,
HTMLPage page = get(url).asPage();
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
logger.debug("Wait time is {}", waitTime);
final ReCaptcha captcha = captchaService.create(page.toString());
final ImageCaptcha captcha = ReCaptchaExtractor.extractAjaxCaptcha(
page, http);
if (captcha != null) {
logger.debug("Service is requiring CAPTCHA {}", captcha);
final long start = System.currentTimeMillis();
resolveCaptcha(captcha);
final long delta = System.currentTimeMillis() - start;
if (delta < waitTime)
if (delta < waitTime) {
logger.debug(
"After captcha resolving, still {} ms remaining",
delta);
timer(listener, waitTime - delta);
} else {
logger.debug("CAPTCHA solving took longer than timer, skipping it");
}
String content = post(url)
.parameter("recaptcha_challenge_field", captcha.getID())
@@ -246,10 +257,15 @@ public class UploadHereService extends AbstractHttpService implements Service,
captcha.getAnswer()).asString();
String downloadLink = PatternUtils.find(
DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
if (downloadLink == null)
if (downloadLink == null) {
captchaService.invalid(captcha);
throw new InvalidCaptchaException();
} else {
captchaService.valid(captcha);
}
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
"/");
logger.debug("Direct download URL is {}", downloadLink);
return download(get(downloadLink).position(position));
}
throw new DownloadLinkNotFoundException();