mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Fixes CAPTCHA solving issue with uploadhere and uploadking
This commit is contained in:
@@ -259,42 +259,36 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
|||||||
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
|
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
|
||||||
logger.debug("Wait time is {}", waitTime);
|
logger.debug("Wait time is {}", waitTime);
|
||||||
|
|
||||||
|
timer(listener, waitTime);
|
||||||
final ImageCaptcha captcha = ReCaptchaExtractor.extractAjaxCaptcha(
|
final ImageCaptcha captcha = ReCaptchaExtractor.extractAjaxCaptcha(
|
||||||
page, http);
|
page, http);
|
||||||
|
|
||||||
|
String content;
|
||||||
if (captcha != null) {
|
if (captcha != null) {
|
||||||
logger.debug("Service is requiring CAPTCHA {}", captcha);
|
logger.debug("Service is requiring CAPTCHA {}", captcha);
|
||||||
final long start = System.currentTimeMillis();
|
|
||||||
resolveCaptcha(captcha);
|
resolveCaptcha(captcha);
|
||||||
|
|
||||||
final long delta = System.currentTimeMillis() - start;
|
content = post(uri)
|
||||||
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(uri)
|
|
||||||
.parameter("recaptcha_challenge_field", captcha.getID())
|
.parameter("recaptcha_challenge_field", captcha.getID())
|
||||||
.parameter("recaptcha_response_field",
|
.parameter("recaptcha_response_field",
|
||||||
captcha.getAnswer()).asString();
|
captcha.getAnswer()).asString();
|
||||||
|
} else {
|
||||||
|
content = page.toString();
|
||||||
|
}
|
||||||
|
|
||||||
String downloadLink = PatternUtils.find(
|
String downloadLink = PatternUtils.find(
|
||||||
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
|
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
|
||||||
if (downloadLink == null) {
|
if (downloadLink == null) {
|
||||||
captchaService.invalid(captcha);
|
captchaService.invalid(captcha);
|
||||||
throw new InvalidCaptchaException();
|
throw new DownloadLinkNotFoundException(
|
||||||
|
new InvalidCaptchaException());
|
||||||
} else {
|
} else {
|
||||||
captchaService.valid(captcha);
|
captchaService.valid(captcha);
|
||||||
}
|
}
|
||||||
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"), "/");
|
||||||
"/");
|
|
||||||
logger.debug("Direct download URI is {}", downloadLink);
|
logger.debug("Direct download URI is {}", downloadLink);
|
||||||
return download(get(downloadLink).position(position));
|
return download(get(downloadLink).position(position));
|
||||||
}
|
}
|
||||||
throw new DownloadLinkNotFoundException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class AuthenticatorImpl extends
|
protected class AuthenticatorImpl extends
|
||||||
|
|||||||
@@ -251,49 +251,41 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
|||||||
@Override
|
@Override
|
||||||
public DownloadChannel openChannel(DownloadListener listener,
|
public DownloadChannel openChannel(DownloadListener listener,
|
||||||
long position) throws IOException {
|
long position) throws IOException {
|
||||||
logger.debug("Downloading {} with uploadking.com");
|
|
||||||
HTMLPage page = get(uri).asPage();
|
HTMLPage page = get(uri).asPage();
|
||||||
|
|
||||||
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
|
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
|
||||||
logger.debug("Wait time is {}", waitTime);
|
logger.debug("Wait time is {}", waitTime);
|
||||||
|
|
||||||
|
timer(listener, waitTime);
|
||||||
final ImageCaptcha captcha = ReCaptchaExtractor.extractAjaxCaptcha(
|
final ImageCaptcha captcha = ReCaptchaExtractor.extractAjaxCaptcha(
|
||||||
page, http);
|
page, http);
|
||||||
|
|
||||||
|
String content;
|
||||||
if (captcha != null) {
|
if (captcha != null) {
|
||||||
logger.debug("Service is requiring CAPTCHA {}", captcha);
|
logger.debug("Service is requiring CAPTCHA {}", captcha);
|
||||||
final long start = System.currentTimeMillis();
|
|
||||||
|
|
||||||
resolveCaptcha(captcha);
|
resolveCaptcha(captcha);
|
||||||
|
|
||||||
final long delta = System.currentTimeMillis() - start;
|
content = post(uri)
|
||||||
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(uri)
|
|
||||||
.parameter("recaptcha_challenge_field", captcha.getID())
|
.parameter("recaptcha_challenge_field", captcha.getID())
|
||||||
.parameter("recaptcha_response_field",
|
.parameter("recaptcha_response_field",
|
||||||
captcha.getAnswer()).asString();
|
captcha.getAnswer()).asString();
|
||||||
|
} else {
|
||||||
|
content = page.toString();
|
||||||
|
}
|
||||||
|
|
||||||
String downloadLink = PatternUtils.find(
|
String downloadLink = PatternUtils.find(
|
||||||
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
|
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
|
||||||
if (downloadLink == null) {
|
if (downloadLink == null) {
|
||||||
captchaService.invalid(captcha);
|
captchaService.invalid(captcha);
|
||||||
throw new InvalidCaptchaException();
|
throw new DownloadLinkNotFoundException(
|
||||||
|
new InvalidCaptchaException());
|
||||||
} else {
|
} else {
|
||||||
captchaService.valid(captcha);
|
captchaService.valid(captcha);
|
||||||
}
|
}
|
||||||
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"), "/");
|
||||||
"/");
|
|
||||||
logger.debug("Direct download URI is {}", downloadLink);
|
logger.debug("Direct download URI is {}", downloadLink);
|
||||||
return download(get(downloadLink).position(position));
|
return download(get(downloadLink).position(position));
|
||||||
}
|
}
|
||||||
throw new DownloadLinkNotFoundException();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected class AuthenticatorImpl extends
|
protected class AuthenticatorImpl extends
|
||||||
|
|||||||
Reference in New Issue
Block a user