mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Implements uploadhere.com service
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.rogiel.httpchannel.captcha.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.rogiel.httpchannel.util.PatternUtils;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*/
|
||||
public class AjaxReCaptchaService extends BaseReCaptchaService {
|
||||
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
|
||||
.compile("Recaptcha\\.create\\(\"([0-9A-z|_|\\-]*)\", ");
|
||||
private static final String BASE_URL = "http://www.google.com/recaptcha/api/challenge?ajax=1&k=";
|
||||
|
||||
@Override
|
||||
public ReCaptcha create(String content) throws MalformedURLException {
|
||||
final String siteID = PatternUtils
|
||||
.find(CAPTCHA_URL_PATTERN, content, 1);
|
||||
try {
|
||||
return super.create(get(BASE_URL + siteID).asString());
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolve(ReCaptcha captcha) {
|
||||
// not supported!
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.rogiel.httpchannel.captcha.impl;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.rogiel.httpchannel.captcha.AbstractImageCaptchaService;
|
||||
import com.rogiel.httpchannel.util.PatternUtils;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class BaseReCaptchaService extends
|
||||
AbstractImageCaptchaService<ReCaptcha> {
|
||||
private static final Pattern CAPTCHA_IMAGE_PATTERN = Pattern
|
||||
.compile("challenge : '(.*)'");
|
||||
private static final String BASE_URL = "http://www.google.com/recaptcha/api/image?c=";
|
||||
|
||||
@Override
|
||||
public ReCaptcha create(String content) throws MalformedURLException {
|
||||
final String id = PatternUtils.find(CAPTCHA_IMAGE_PATTERN, content, 1);
|
||||
return new ReCaptcha(new URL(BASE_URL + id), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolve(ReCaptcha captcha) {
|
||||
// not supported!
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.rogiel.httpchannel.captcha.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class EmbeddedReCaptchaService extends BaseReCaptchaService {
|
||||
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
|
||||
.compile("http://www\\.google\\.com/recaptcha/api/challenge\\?k=([0-9A-z|\\-]*)(&(.*))?");
|
||||
|
||||
@Override
|
||||
public ReCaptcha create(String content) throws MalformedURLException {
|
||||
try {
|
||||
return create(HTMLPage.parse(content));
|
||||
} catch (IOException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ReCaptcha create(HTMLPage page) throws IOException {
|
||||
final String url = page.findScriptSrc(CAPTCHA_URL_PATTERN);
|
||||
if (url == null)
|
||||
return null;
|
||||
return super.create(get(url).asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolve(ReCaptcha captcha) {
|
||||
// not supported!
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.rogiel.httpchannel.captcha.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import com.rogiel.httpchannel.captcha.AbstractImageCaptchaService;
|
||||
import com.rogiel.httpchannel.util.PatternUtils;
|
||||
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class ReCaptchaService extends AbstractImageCaptchaService<ReCaptcha> {
|
||||
// http://www.google.com/recaptcha/api/noscript?k=6LdRTL8SAAAAAE9UOdWZ4d0Ky-aeA7XfSqyWDM2m
|
||||
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
|
||||
.compile("http://www\\.google\\.com/recaptcha/api/challenge\\?k=([0-9A-z|\\-]*)(&(.*))?");
|
||||
private static final Pattern CAPTCHA_IMAGE_PATTERN = Pattern
|
||||
.compile("challenge : '(.*)'");
|
||||
private static final String BASE_URL = "http://www.google.com/recaptcha/api/image?c=";
|
||||
|
||||
@Override
|
||||
public ReCaptcha create(HTMLPage page) throws IOException {
|
||||
final String url = page.findScriptSrc(CAPTCHA_URL_PATTERN);
|
||||
|
||||
if (url == null)
|
||||
return null;
|
||||
final String captchaPage = get(url).asString();
|
||||
|
||||
final String id = PatternUtils.find(CAPTCHA_IMAGE_PATTERN, captchaPage,
|
||||
1);
|
||||
return new ReCaptcha(new URL(BASE_URL + id), id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean resolve(ReCaptcha captcha) {
|
||||
// not supported!
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/**
|
||||
*
|
||||
*/
|
||||
package com.rogiel.httpchannel.captcha.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||
*
|
||||
*/
|
||||
public class AjaxReCaptchaServiceTest {
|
||||
@Test
|
||||
public void test() throws MalformedURLException, IOException {
|
||||
final String content = IOUtils.toString(new URL(
|
||||
"http://www.uploadking.com/WM3PHD9JAY").openStream());
|
||||
final AjaxReCaptchaService ajax = new AjaxReCaptchaService();
|
||||
ajax.create(content);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user