mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-05 23:22:51 +00:00
Adds -SNAPSHOT to Maven version parameter and few modifications to API
This commit is contained in:
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel</artifactId>
|
<artifactId>httpchannel</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-api</artifactId>
|
<artifactId>httpchannel-api</artifactId>
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.rogiel.httpchannel.captcha;
|
package com.rogiel.httpchannel.captcha;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
@@ -15,9 +15,9 @@ public class ImageCaptcha implements Captcha {
|
|||||||
*/
|
*/
|
||||||
private final String ID;
|
private final String ID;
|
||||||
/**
|
/**
|
||||||
* The CAPTCHA Image {@link URL}
|
* The CAPTCHA Image {@link URI}
|
||||||
*/
|
*/
|
||||||
private final URL imageURL;
|
private final URI imageURI;
|
||||||
/**
|
/**
|
||||||
* The CAPTCHA answer
|
* The CAPTCHA answer
|
||||||
*/
|
*/
|
||||||
@@ -27,9 +27,9 @@ public class ImageCaptcha implements Captcha {
|
|||||||
*/
|
*/
|
||||||
private Object attachment;
|
private Object attachment;
|
||||||
|
|
||||||
public ImageCaptcha(String id, URL imageURL) {
|
public ImageCaptcha(String id, URI imageURI) {
|
||||||
this.ID = id;
|
this.ID = id;
|
||||||
this.imageURL = imageURL;
|
this.imageURI = imageURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -37,8 +37,8 @@ public class ImageCaptcha implements Captcha {
|
|||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getImageURL() {
|
public URI getImageURI() {
|
||||||
return imageURL;
|
return imageURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -68,7 +68,7 @@ public class ImageCaptcha implements Captcha {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ImageCaptcha [ID=" + ID + ", imageURL=" + imageURL
|
return "ImageCaptcha [ID=" + ID + ", imageURI=" + imageURI
|
||||||
+ ", answer=" + answer + ", attachment=" + attachment + "]";
|
+ ", answer=" + answer + ", attachment=" + attachment + "]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.rogiel.httpchannel.service;
|
package com.rogiel.httpchannel.service;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.tools.FileObject;
|
import javax.tools.FileObject;
|
||||||
|
|
||||||
@@ -33,27 +33,27 @@ public interface DownloadService<C extends DownloaderConfiguration> extends
|
|||||||
Service {
|
Service {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the {@link Downloader}. This instance will be
|
* Creates a new instance of the {@link Downloader}. This instance will be
|
||||||
* attached to the {@link URL}, {@link FileObject} provided through the the
|
* attached to the {@link URI}, {@link FileObject} provided through the the
|
||||||
* arguments and the parent {@link Service} instance.
|
* arguments and the parent {@link Service} instance.
|
||||||
*
|
*
|
||||||
* @param url
|
* @param uri
|
||||||
* the url to be downloaded
|
* the uri to be downloaded
|
||||||
* @param configuration
|
* @param configuration
|
||||||
* the downloader configurationf
|
* the downloader configuration
|
||||||
* @return an new instance of {@link Downloader}
|
* @return an new instance of {@link Downloader}
|
||||||
*/
|
*/
|
||||||
Downloader<C> getDownloader(URL url, C configuration);
|
Downloader<C> getDownloader(URI uri, C configuration);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of the {@link Downloader}. This instance will be
|
* Creates a new instance of the {@link Downloader}. This instance will be
|
||||||
* attached to the {@link URL}, {@link FileObject} provided through the the
|
* attached to the {@link URI}, {@link FileObject} provided through the the
|
||||||
* arguments and the parent {@link Service} instance.
|
* arguments and the parent {@link Service} instance.
|
||||||
*
|
*
|
||||||
* @param url
|
* @param uri
|
||||||
* the url to be downloaded
|
* the uri to be downloaded
|
||||||
* @return an new instance of {@link Downloader}
|
* @return an new instance of {@link Downloader}
|
||||||
*/
|
*/
|
||||||
Downloader<C> getDownloader(URL url);
|
Downloader<C> getDownloader(URI uri);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new configuration object. If a service does not support or
|
* Creates a new configuration object. If a service does not support or
|
||||||
@@ -65,17 +65,17 @@ public interface DownloadService<C extends DownloaderConfiguration> extends
|
|||||||
C newDownloaderConfiguration();
|
C newDownloaderConfiguration();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if this {@link Service} can download from this URL. Implementations
|
* Check if this {@link Service} can download from this URI. Implementations
|
||||||
* might or might not perform network activity.
|
* might or might not perform network activity.
|
||||||
* <p>
|
* <p>
|
||||||
* <b>Please note</b> that the value returned by this method may vary based
|
* <b>Please note</b> that the value returned by this method may vary based
|
||||||
* on it's state (i.e. premium or not).
|
* on it's state (i.e. premium or not).
|
||||||
*
|
*
|
||||||
* @param url
|
* @param uri
|
||||||
* the {@link URL} to be tested.
|
* the {@link URI} to be tested.
|
||||||
* @return true if supported, false otherwise.
|
* @return true if supported, false otherwise.
|
||||||
*/
|
*/
|
||||||
boolean matchURL(URL url);
|
boolean matchURI(URI uri);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the matrix of capabilities for this {@link Downloader}.
|
* Return the matrix of capabilities for this {@link Downloader}.
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ public interface Service extends Cloneable {
|
|||||||
*
|
*
|
||||||
* @return the id of the service
|
* @return the id of the service
|
||||||
*/
|
*/
|
||||||
ServiceID getID();
|
ServiceID getServiceID();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Major version of this service
|
* Get Major version of this service
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package com.rogiel.httpchannel.service;
|
package com.rogiel.httpchannel.service;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.channels.Channel;
|
import java.nio.channels.Channel;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public interface UploadChannel extends HttpChannel, WritableByteChannel {
|
|||||||
*
|
*
|
||||||
* @return the download link for this upload
|
* @return the download link for this upload
|
||||||
*/
|
*/
|
||||||
URL getDownloadLink();
|
URI getDownloadLink();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws UploadLinkNotFoundException
|
* @throws UploadLinkNotFoundException
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package com.rogiel.httpchannel.service.helper;
|
package com.rogiel.httpchannel.service.helper;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
|
||||||
import com.rogiel.httpchannel.service.DownloadService;
|
import com.rogiel.httpchannel.service.DownloadService;
|
||||||
|
|
||||||
@@ -25,8 +25,8 @@ import com.rogiel.httpchannel.service.DownloadService;
|
|||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public class DownloadServices {
|
public class DownloadServices {
|
||||||
public static boolean canDownload(DownloadService<?> service, URL url)
|
public static boolean canDownload(DownloadService<?> service, URI uri)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return service.matchURL(url);
|
return service.matchURI(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.rogiel.httpchannel.service.helper;
|
package com.rogiel.httpchannel.service.helper;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.ServiceLoader;
|
import java.util.ServiceLoader;
|
||||||
|
|
||||||
@@ -41,17 +41,17 @@ public class Services {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to detect which service should be used to download the given URL
|
* Tries to detect which service should be used to download the given URI
|
||||||
*
|
*
|
||||||
* @param url
|
* @param uri
|
||||||
* the URL
|
* the URI
|
||||||
* @return the matched service
|
* @return the matched service
|
||||||
*/
|
*/
|
||||||
public static DownloadService<?> matchURL(URL url) {
|
public static DownloadService<?> matchURI(URI uri) {
|
||||||
for (final Service service : iterate()) {
|
for (final Service service : iterate()) {
|
||||||
if (!(service instanceof DownloadService))
|
if (!(service instanceof DownloadService))
|
||||||
continue;
|
continue;
|
||||||
if (((DownloadService<?>) service).matchURL(url))
|
if (((DownloadService<?>) service).matchURI(uri))
|
||||||
return (DownloadService<?>) service;
|
return (DownloadService<?>) service;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -66,7 +66,7 @@ public class Services {
|
|||||||
*/
|
*/
|
||||||
public static Service getService(ServiceID id) {
|
public static Service getService(ServiceID id) {
|
||||||
for (final Service service : iterate()) {
|
for (final Service service : iterate()) {
|
||||||
if (service.getID().equals(id))
|
if (service.getServiceID().equals(id))
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -106,7 +106,7 @@ public class Services {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID next() {
|
public ServiceID next() {
|
||||||
return iterator.next().getID();
|
return iterator.next().getServiceID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-captcha</artifactId>
|
<artifactId>httpchannel-captcha</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<groupId>com.rogiel.httpchannel.captcha</groupId>
|
<groupId>com.rogiel.httpchannel.captcha</groupId>
|
||||||
|
|||||||
@@ -5,9 +5,7 @@ package com.captchatrader;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
@@ -50,7 +48,7 @@ public class CaptchaTrader {
|
|||||||
private final HttpClient client = new DefaultHttpClient();
|
private final HttpClient client = new DefaultHttpClient();
|
||||||
private final JSONParser json = new JSONParser();
|
private final JSONParser json = new JSONParser();
|
||||||
|
|
||||||
private final URI apiURL;
|
private final URI apiURI;
|
||||||
private final String applicationKey;
|
private final String applicationKey;
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String password;
|
private final String password;
|
||||||
@@ -61,9 +59,9 @@ public class CaptchaTrader {
|
|||||||
* @param applicationKey
|
* @param applicationKey
|
||||||
* the key
|
* the key
|
||||||
*/
|
*/
|
||||||
public CaptchaTrader(URI apiURL, String applicationKey, String username,
|
public CaptchaTrader(URI apiURI, String applicationKey, String username,
|
||||||
String password) {
|
String password) {
|
||||||
this.apiURL = apiURL;
|
this.apiURI = apiURI;
|
||||||
this.applicationKey = applicationKey;
|
this.applicationKey = applicationKey;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
@@ -74,7 +72,7 @@ public class CaptchaTrader {
|
|||||||
*
|
*
|
||||||
* @param applicationKey
|
* @param applicationKey
|
||||||
* the key
|
* the key
|
||||||
* @throws MalformedURLException
|
* @throws MalformedURIException
|
||||||
*/
|
*/
|
||||||
public CaptchaTrader(String applicationKey, String username, String password) {
|
public CaptchaTrader(String applicationKey, String username, String password) {
|
||||||
this(URI.create("http://api.captchatrader.com/"), applicationKey,
|
this(URI.create("http://api.captchatrader.com/"), applicationKey,
|
||||||
@@ -84,27 +82,27 @@ public class CaptchaTrader {
|
|||||||
/**
|
/**
|
||||||
* Submit a CAPTCHA already hosted on an existing website.
|
* Submit a CAPTCHA already hosted on an existing website.
|
||||||
*
|
*
|
||||||
* @param url
|
* @param uri
|
||||||
* The URL of the CAPTCHA image.
|
* The URI of the CAPTCHA image.
|
||||||
* @return The decoded CAPTCHA.
|
* @return The decoded CAPTCHA.
|
||||||
* @throws Any
|
* @throws Any
|
||||||
* exceptions sent by the server.
|
* exceptions sent by the server.
|
||||||
*/
|
*/
|
||||||
public ResolvedCaptcha submit(URL url) throws CaptchaTraderException,
|
public ResolvedCaptcha submit(URI uri) throws CaptchaTraderException,
|
||||||
IOException {
|
IOException {
|
||||||
final URI requestUri = apiURL.resolve("submit");
|
final URI requestUri = apiURI.resolve("submit");
|
||||||
final HttpPost request = new HttpPost(requestUri);
|
final HttpPost request = new HttpPost(requestUri);
|
||||||
final MultipartEntity entity = new MultipartEntity();
|
final MultipartEntity entity = new MultipartEntity();
|
||||||
|
|
||||||
entity.addPart("api_key", new StringBody(applicationKey));
|
entity.addPart("api_key", new StringBody(applicationKey));
|
||||||
entity.addPart("username", new StringBody(username));
|
entity.addPart("username", new StringBody(username));
|
||||||
entity.addPart("password", new StringBody(password));
|
entity.addPart("password", new StringBody(password));
|
||||||
entity.addPart("value", new StringBody(url.toString()));
|
entity.addPart("value", new StringBody(uri.toString()));
|
||||||
|
|
||||||
request.setEntity(entity);
|
request.setEntity(entity);
|
||||||
final List<Object> response = validate(execute(request));
|
final List<Object> response = validate(execute(request));
|
||||||
|
|
||||||
return new ResolvedCaptcha(this, ((Long) response.get(0)).intValue(),
|
return new ResolvedCaptcha(this, ((Long) response.get(0)).toString(),
|
||||||
(String) response.get(1));
|
(String) response.get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,17 +116,16 @@ public class CaptchaTrader {
|
|||||||
* @throws CaptchaTraderException
|
* @throws CaptchaTraderException
|
||||||
* any of the possible errors
|
* any of the possible errors
|
||||||
*/
|
*/
|
||||||
public void response(ResolvedCaptcha captcha, boolean state)
|
public void respond(ResolvedCaptcha captcha, boolean state)
|
||||||
throws CaptchaTraderException, IOException {
|
throws CaptchaTraderException, IOException {
|
||||||
final URI requestUri = apiURL.resolve("respond");
|
final URI requestUri = apiURI.resolve("respond");
|
||||||
final HttpPost request = new HttpPost(requestUri);
|
final HttpPost request = new HttpPost(requestUri);
|
||||||
final MultipartEntity entity = new MultipartEntity();
|
final MultipartEntity entity = new MultipartEntity();
|
||||||
|
|
||||||
entity.addPart("is_correct", new StringBody(state ? "1" : "0"));
|
entity.addPart("is_correct", new StringBody(state ? "1" : "0"));
|
||||||
entity.addPart("username", new StringBody(username));
|
|
||||||
entity.addPart("password", new StringBody(password));
|
entity.addPart("password", new StringBody(password));
|
||||||
entity.addPart("ticket",
|
entity.addPart("ticket", new StringBody(captcha.getID()));
|
||||||
new StringBody(Integer.toString(captcha.getID())));
|
entity.addPart("username", new StringBody(username));
|
||||||
|
|
||||||
request.setEntity(entity);
|
request.setEntity(entity);
|
||||||
validate(execute(request));
|
validate(execute(request));
|
||||||
@@ -143,7 +140,7 @@ public class CaptchaTrader {
|
|||||||
*/
|
*/
|
||||||
public int getCredits() throws CaptchaTraderException, IOException {
|
public int getCredits() throws CaptchaTraderException, IOException {
|
||||||
return ((Number) validate(
|
return ((Number) validate(
|
||||||
execute(new HttpGet(apiURL.resolve("get_credits/username:"
|
execute(new HttpGet(apiURI.resolve("get_credits/username:"
|
||||||
+ username + "/password:" + password + "/")))).get(1))
|
+ username + "/password:" + password + "/")))).get(1))
|
||||||
.intValue();
|
.intValue();
|
||||||
}
|
}
|
||||||
@@ -185,7 +182,7 @@ public class CaptchaTrader {
|
|||||||
return new InvalidApplicationKeyException();
|
return new InvalidApplicationKeyException();
|
||||||
case "INVALID PARAMETERS":
|
case "INVALID PARAMETERS":
|
||||||
return new InvalidParametersException();
|
return new InvalidParametersException();
|
||||||
case "INVALID URL":
|
case "INVALID URI":
|
||||||
return new InvalidURLException();
|
return new InvalidURLException();
|
||||||
case "INVALID USER":
|
case "INVALID USER":
|
||||||
return new InvalidUserException();
|
return new InvalidUserException();
|
||||||
|
|||||||
@@ -13,16 +13,16 @@ import com.captchatrader.exception.CaptchaTraderException;
|
|||||||
*/
|
*/
|
||||||
public class ResolvedCaptcha {
|
public class ResolvedCaptcha {
|
||||||
private final CaptchaTrader api;
|
private final CaptchaTrader api;
|
||||||
private final int id;
|
private final String id;
|
||||||
private final String answer;
|
private final String answer;
|
||||||
|
|
||||||
public ResolvedCaptcha(CaptchaTrader api, int id, String answer) {
|
public ResolvedCaptcha(CaptchaTrader api, String id, String answer) {
|
||||||
this.api = api;
|
this.api = api;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.answer = answer;
|
this.answer = answer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getID() {
|
public String getID() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,10 +31,10 @@ public class ResolvedCaptcha {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void valid() throws CaptchaTraderException, IOException {
|
public void valid() throws CaptchaTraderException, IOException {
|
||||||
api.response(this, true);
|
api.respond(this, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void invalid() throws CaptchaTraderException, IOException {
|
public void invalid() throws CaptchaTraderException, IOException {
|
||||||
api.response(this, true);
|
api.respond(this, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class CaptchaTraderService implements ImageCaptchaService {
|
|||||||
/**
|
/**
|
||||||
* The current application key to be used
|
* The current application key to be used
|
||||||
*/
|
*/
|
||||||
private String currentApplicationKey = APP_KEY;
|
private String currentApplicationKey = CaptchaTraderService.APP_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The CaptchaTrader.com API object
|
* The CaptchaTrader.com API object
|
||||||
@@ -56,8 +56,8 @@ public class CaptchaTraderService implements ImageCaptchaService {
|
|||||||
public void solve(ImageCaptcha captcha)
|
public void solve(ImageCaptcha captcha)
|
||||||
throws UnsolvableCaptchaServiceException {
|
throws UnsolvableCaptchaServiceException {
|
||||||
try {
|
try {
|
||||||
logger.debug("Resolving CAPTCHA {}", captcha.getImageURL());
|
logger.debug("Resolving CAPTCHA {}", captcha.getImageURI());
|
||||||
final ResolvedCaptcha resolved = api.submit(captcha.getImageURL());
|
final ResolvedCaptcha resolved = api.submit(captcha.getImageURI());
|
||||||
captcha.setAnswer(resolved.getAnswer());
|
captcha.setAnswer(resolved.getAnswer());
|
||||||
captcha.setAttachment(resolved);
|
captcha.setAttachment(resolved);
|
||||||
logger.debug("CAPTCHA solved, answer is \"{}\"",
|
logger.debug("CAPTCHA solved, answer is \"{}\"",
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.captchatrader;
|
package com.captchatrader;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
@@ -33,7 +33,7 @@ public class CaptchaTraderTest {
|
|||||||
"2acc44805ec208cc4d6b00c75a414996", p.getProperty("username"),
|
"2acc44805ec208cc4d6b00c75a414996", p.getProperty("username"),
|
||||||
p.getProperty("password"));
|
p.getProperty("password"));
|
||||||
final ResolvedCaptcha resolved = api
|
final ResolvedCaptcha resolved = api
|
||||||
.submit(new URL(
|
.submit(new URI(
|
||||||
"http://www.google.com/recaptcha/api/image?c=03AHJ_VusNSxAzZgs9OEvH79rOWOFDYXE2ElE5qkCr9kFU-ZU7gqy72tqEL3j_qCLYwdXgh4jaxU1iECISuUwt0zHbelni-lq8c7RVGSjUtJiMyHwlTTsG5CxWKIEus--yy3GPvwaW9l4N7hFnT57lLq272EOxcFDGYA"));
|
"http://www.google.com/recaptcha/api/image?c=03AHJ_VusNSxAzZgs9OEvH79rOWOFDYXE2ElE5qkCr9kFU-ZU7gqy72tqEL3j_qCLYwdXgh4jaxU1iECISuUwt0zHbelni-lq8c7RVGSjUtJiMyHwlTTsG5CxWKIEus--yy3GPvwaW9l4N7hFnT57lLq272EOxcFDGYA"));
|
||||||
System.out.println(resolved);
|
System.out.println(resolved);
|
||||||
resolved.valid();
|
resolved.valid();
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel</artifactId>
|
<artifactId>httpchannel</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-captcha</artifactId>
|
<artifactId>httpchannel-captcha</artifactId>
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<artifactId>httpchannel-api</artifactId>
|
<artifactId>httpchannel-api</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel</artifactId>
|
<artifactId>httpchannel</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-channelcopy</artifactId>
|
<artifactId>httpchannel-channelcopy</artifactId>
|
||||||
@@ -14,18 +14,19 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<artifactId>httpchannel-api</artifactId>
|
<artifactId>httpchannel-api</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rogiel.httpchannel.services</groupId>
|
<groupId>com.rogiel.httpchannel.services</groupId>
|
||||||
<artifactId>httpchannel-service-megaupload</artifactId>
|
<artifactId>httpchannel-service-megaupload</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rogiel.httpchannel.services</groupId>
|
<groupId>com.rogiel.httpchannel.services</groupId>
|
||||||
<artifactId>httpchannel-service-multiupload</artifactId>
|
<artifactId>httpchannel-service-multiupload</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.rogiel.httpchannel.copy;
|
package com.rogiel.httpchannel.copy;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -41,7 +41,7 @@ import com.rogiel.httpchannel.service.helper.Services;
|
|||||||
*
|
*
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public class ChannelCopy implements Callable<List<URL>> {
|
public class ChannelCopy implements Callable<List<URI>> {
|
||||||
/**
|
/**
|
||||||
* The input channel
|
* The input channel
|
||||||
*/
|
*/
|
||||||
@@ -101,12 +101,12 @@ public class ChannelCopy implements Callable<List<URL>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes with an {@link URL}. First tries to open an
|
* Initializes with an {@link URI}. First tries to open an
|
||||||
* {@link DownloadChannel}, if no service is found,
|
* {@link DownloadChannel}, if no service is found,
|
||||||
* {@link NoServiceFoundException} is thrown.
|
* {@link NoServiceFoundException} is thrown.
|
||||||
*
|
*
|
||||||
* @param url
|
* @param uri
|
||||||
* the source {@link URL}
|
* the source {@link URI}
|
||||||
* @throws DownloadLinkNotFoundException
|
* @throws DownloadLinkNotFoundException
|
||||||
* if the download link could not be found
|
* if the download link could not be found
|
||||||
* @throws DownloadLimitExceededException
|
* @throws DownloadLimitExceededException
|
||||||
@@ -114,17 +114,17 @@ public class ChannelCopy implements Callable<List<URL>> {
|
|||||||
* @throws DownloadNotAuthorizedException
|
* @throws DownloadNotAuthorizedException
|
||||||
* if the download was not authorized by the service
|
* if the download was not authorized by the service
|
||||||
* @throws NoServiceFoundException
|
* @throws NoServiceFoundException
|
||||||
* if no service could be found for the {@link URL}
|
* if no service could be found for the {@link URI}
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
* if any IO error occur
|
* if any IO error occur
|
||||||
*/
|
*/
|
||||||
public ChannelCopy(URL url) throws DownloadLinkNotFoundException,
|
public ChannelCopy(URI uri) throws DownloadLinkNotFoundException,
|
||||||
DownloadLimitExceededException, DownloadNotAuthorizedException,
|
DownloadLimitExceededException, DownloadNotAuthorizedException,
|
||||||
IOException {
|
IOException {
|
||||||
final DownloadService<?> service = Services.matchURL(url);
|
final DownloadService<?> service = Services.matchURI(uri);
|
||||||
if (service == null)
|
if (service == null)
|
||||||
throw new NoServiceFoundException(url.toString());
|
throw new NoServiceFoundException(uri.toString());
|
||||||
final DownloadChannel downloadChannel = service.getDownloader(url)
|
final DownloadChannel downloadChannel = service.getDownloader(uri)
|
||||||
.openChannel();
|
.openChannel();
|
||||||
|
|
||||||
this.downloadChannel = downloadChannel;
|
this.downloadChannel = downloadChannel;
|
||||||
@@ -173,7 +173,7 @@ public class ChannelCopy implements Callable<List<URL>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<URL> call() throws IOException {
|
public List<URI> call() throws IOException {
|
||||||
final ByteBuffer buffer = ByteBuffer.allocate(16 * 1024);
|
final ByteBuffer buffer = ByteBuffer.allocate(16 * 1024);
|
||||||
try {
|
try {
|
||||||
while (downloadChannel.read(buffer) >= 0) {
|
while (downloadChannel.read(buffer) >= 0) {
|
||||||
@@ -196,11 +196,11 @@ public class ChannelCopy implements Callable<List<URL>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final List<URL> urls = new ArrayList<>();
|
final List<URI> uris = new ArrayList<>();
|
||||||
for (final UploadChannel channel : uploadChannels) {
|
for (final UploadChannel channel : uploadChannels) {
|
||||||
urls.add(channel.getDownloadLink());
|
uris.add(channel.getDownloadLink());
|
||||||
}
|
}
|
||||||
|
|
||||||
return urls;
|
return uris;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service-depositfiles</artifactId>
|
<artifactId>httpchannel-service-depositfiles</artifactId>
|
||||||
|
|||||||
@@ -43,16 +43,16 @@ public class DepositFilesService extends AbstractHttpService implements
|
|||||||
*/
|
*/
|
||||||
public static final ServiceID SERVICE_ID = ServiceID.create("depositfiles");
|
public static final ServiceID SERVICE_ID = ServiceID.create("depositfiles");
|
||||||
|
|
||||||
private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
private static final Pattern UPLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://fileshare([0-9]*)\\.depositfiles\\.com/(.*)/\\?X-Progress-ID=(.*)");
|
.compile("http://fileshare([0-9]*)\\.depositfiles\\.com/(.*)/\\?X-Progress-ID=(.*)");
|
||||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://(www\\.)?depositfiles\\.com/files/([0-9A-z]*)");
|
.compile("http://(www\\.)?depositfiles\\.com/files/([0-9A-z]*)");
|
||||||
|
|
||||||
private static final Pattern VALID_LOGIN_REDIRECT = Pattern
|
private static final Pattern VALID_LOGIN_REDIRECT = Pattern
|
||||||
.compile("window.location.href");
|
.compile("window.location.href");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID getID() {
|
public ServiceID getServiceID() {
|
||||||
return SERVICE_ID;
|
return SERVICE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,14 +139,14 @@ public class DepositFilesService extends AbstractHttpService implements
|
|||||||
logger.debug("Starting upload to depositfiles.com");
|
logger.debug("Starting upload to depositfiles.com");
|
||||||
final HTMLPage page = get("http://www.depositfiles.com/").asPage();
|
final HTMLPage page = get("http://www.depositfiles.com/").asPage();
|
||||||
|
|
||||||
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
|
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
|
||||||
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
|
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
|
||||||
final String maxFileSize = page.getInputValue("MAX_FILE_SIZE");
|
final String maxFileSize = page.getInputValue("MAX_FILE_SIZE");
|
||||||
|
|
||||||
logger.debug("Upload URL: {}, ID: {}", url, uploadID);
|
logger.debug("Upload URI: {}, ID: {}", uri, uploadID);
|
||||||
|
|
||||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
uploadFuture = multipartPost(url).parameter("files", channel)
|
uploadFuture = multipartPost(uri).parameter("files", channel)
|
||||||
.parameter("go", true)
|
.parameter("go", true)
|
||||||
.parameter("UPLOAD_IDENTIFIER", uploadID)
|
.parameter("UPLOAD_IDENTIFIER", uploadID)
|
||||||
.parameter("agree", true)
|
.parameter("agree", true)
|
||||||
@@ -158,7 +158,7 @@ public class DepositFilesService extends AbstractHttpService implements
|
|||||||
public String finish() throws IOException {
|
public String finish() throws IOException {
|
||||||
try {
|
try {
|
||||||
final String link = uploadFuture.get().findScript(
|
final String link = uploadFuture.get().findScript(
|
||||||
DOWNLOAD_URL_PATTERN, 0);
|
DOWNLOAD_URI_PATTERN, 0);
|
||||||
if (link == null)
|
if (link == null)
|
||||||
return null;
|
return null;
|
||||||
return link;
|
return link;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@@ -31,9 +31,9 @@ public class DepositFilesServiceTest {
|
|||||||
UploaderCapability.UNAUTHENTICATED_UPLOAD));
|
UploaderCapability.UNAUTHENTICATED_UPLOAD));
|
||||||
|
|
||||||
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
||||||
final URL url = ChannelUtils.upload(service, path);
|
final URI uri = ChannelUtils.upload(service, path);
|
||||||
|
|
||||||
Assert.assertNotNull(url);
|
Assert.assertNotNull(uri);
|
||||||
System.out.println(url);
|
System.out.println(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service-filesonic</artifactId>
|
<artifactId>httpchannel-service-filesonic</artifactId>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
package com.rogiel.httpchannel.filesonic;
|
package com.rogiel.httpchannel.filesonic;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ import com.rogiel.httpchannel.filesonic.xml.FSUpload;
|
|||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public class FileSonicAPI {
|
public class FileSonicAPI {
|
||||||
private static final String BASE_URL = "http://api.filesonic.com/";
|
private static final String BASE_URI = "http://api.filesonic.com/";
|
||||||
|
|
||||||
private String email;
|
private String email;
|
||||||
private String password;
|
private String password;
|
||||||
@@ -25,10 +25,10 @@ public class FileSonicAPI {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public URL getUploadURL() throws IOException {
|
public URI getUploadURI() throws IOException {
|
||||||
return new URL(((FSGetUploadURL) execute(FSUpload.class,
|
return URI.create((((FSGetUploadURL) execute(FSUpload.class,
|
||||||
"upload?method=getUploadUrl").getResponse()).getResponse()
|
"upload?method=getUploadUrl").getResponse()).getResponse()
|
||||||
.getUploadURL());
|
.getUploadURI()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxFilesize() throws IOException {
|
public long getMaxFilesize() throws IOException {
|
||||||
@@ -47,10 +47,10 @@ public class FileSonicAPI {
|
|||||||
this.password = null;
|
this.password = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private <T extends FSAPI> T execute(Class<T> type, String requestURL)
|
private <T extends FSAPI> T execute(Class<T> type, String requestURI)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final URL url = new URL(BASE_URL + requestURL + "&u=" + email + "&p="
|
final URI uri = URI.create(BASE_URI + requestURI + "&u=" + email
|
||||||
+ password + "&format=xml");
|
+ "&p=" + password + "&format=xml");
|
||||||
return JAXB.unmarshal(url.openStream(), type);
|
return JAXB.unmarshal(uri.toURL().openStream(), type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,13 +20,13 @@ public class FSGetUploadURL extends FSResponse {
|
|||||||
|
|
||||||
@XmlAccessorType(XmlAccessType.NONE)
|
@XmlAccessorType(XmlAccessType.NONE)
|
||||||
public static class FSGetUploadURLResponse {
|
public static class FSGetUploadURLResponse {
|
||||||
@XmlElement(name = "url")
|
@XmlElement(name = "uri")
|
||||||
private String uploadURL;
|
private String uploadURI;
|
||||||
@XmlElement(name = "max-filesize")
|
@XmlElement(name = "max-filesize")
|
||||||
private long maxFilesize;
|
private long maxFilesize;
|
||||||
|
|
||||||
public String getUploadURL() {
|
public String getUploadURI() {
|
||||||
return uploadURL;
|
return uploadURI;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getMaxFilesize() {
|
public long getMaxFilesize() {
|
||||||
|
|||||||
@@ -57,9 +57,9 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
|||||||
public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
|
public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The download URL pattern
|
* The download URI pattern
|
||||||
*/
|
*/
|
||||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://www.filesonic.com/file/[0-9A-z]*");
|
.compile("http://www.filesonic.com/file/[0-9A-z]*");
|
||||||
/**
|
/**
|
||||||
* The FileSonic API
|
* The FileSonic API
|
||||||
@@ -67,7 +67,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
|||||||
private final FileSonicAPI api = new FileSonicAPI();
|
private final FileSonicAPI api = new FileSonicAPI();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID getID() {
|
public ServiceID getServiceID() {
|
||||||
return SERVICE_ID;
|
return SERVICE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,7 +156,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
|||||||
public UploadChannel openChannel() throws IOException {
|
public UploadChannel openChannel() throws IOException {
|
||||||
logger.debug("Starting upload to filesonic.com");
|
logger.debug("Starting upload to filesonic.com");
|
||||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
uploadFuture = multipartPost(api.getUploadURL().toString())
|
uploadFuture = multipartPost(api.getUploadURI().toString())
|
||||||
.parameter("files[]", channel).asStringAsync();
|
.parameter("files[]", channel).asStringAsync();
|
||||||
return waitChannelLink(channel, uploadFuture);
|
return waitChannelLink(channel, uploadFuture);
|
||||||
}
|
}
|
||||||
@@ -164,7 +164,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
|||||||
@Override
|
@Override
|
||||||
public String finish() throws IOException {
|
public String finish() throws IOException {
|
||||||
try {
|
try {
|
||||||
return PatternUtils.find(DOWNLOAD_URL_PATTERN,
|
return PatternUtils.find(DOWNLOAD_URI_PATTERN,
|
||||||
uploadFuture.get());
|
uploadFuture.get());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service-hotfile</artifactId>
|
<artifactId>httpchannel-service-hotfile</artifactId>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package com.rogiel.httpchannel.service.impl;
|
package com.rogiel.httpchannel.service.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -71,7 +71,7 @@ public class HotFileService extends AbstractHttpService implements Service,
|
|||||||
*/
|
*/
|
||||||
public static final ServiceID SERVICE_ID = ServiceID.create("hotfile");
|
public static final ServiceID SERVICE_ID = ServiceID.create("hotfile");
|
||||||
|
|
||||||
private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
private static final Pattern UPLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://u[0-9]*\\.hotfile\\.com/upload\\.cgi\\?[0-9]*");
|
.compile("http://u[0-9]*\\.hotfile\\.com/upload\\.cgi\\?[0-9]*");
|
||||||
|
|
||||||
private static final Pattern DOWNLOAD_DIRECT_LINK_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_DIRECT_LINK_PATTERN = Pattern
|
||||||
@@ -81,11 +81,11 @@ public class HotFileService extends AbstractHttpService implements Service,
|
|||||||
// private static final Pattern DOWNLOAD_FILESIZE = Pattern
|
// private static final Pattern DOWNLOAD_FILESIZE = Pattern
|
||||||
// .compile("[0-9]*(\\.[0-9]*)? (K|M|G)B");
|
// .compile("[0-9]*(\\.[0-9]*)? (K|M|G)B");
|
||||||
|
|
||||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://hotfile\\.com/dl/([0-9]*)/([A-Za-z0-9]*)/(.*)");
|
.compile("http://hotfile\\.com/dl/([0-9]*)/([A-Za-z0-9]*)/(.*)");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID getID() {
|
public ServiceID getServiceID() {
|
||||||
return SERVICE_ID;
|
return SERVICE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,14 +135,14 @@ public class HotFileService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
|
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
|
||||||
NullDownloaderConfiguration configuration) {
|
NullDownloaderConfiguration configuration) {
|
||||||
return new DownloaderImpl(url, configuration);
|
return new DownloaderImpl(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
|
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
|
||||||
return getDownloader(url, newDownloaderConfiguration());
|
return getDownloader(uri, newDownloaderConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -151,8 +151,8 @@ public class HotFileService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matchURL(URL url) {
|
public boolean matchURI(URI uri) {
|
||||||
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
|
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -198,9 +198,9 @@ public class HotFileService extends AbstractHttpService implements Service,
|
|||||||
public UploadChannel openChannel() throws IOException {
|
public UploadChannel openChannel() throws IOException {
|
||||||
logger.debug("Starting upload to hotfile.com");
|
logger.debug("Starting upload to hotfile.com");
|
||||||
final HTMLPage page = get("http://www.hotfile.com/").asPage();
|
final HTMLPage page = get("http://www.hotfile.com/").asPage();
|
||||||
final String action = page.findFormAction(UPLOAD_URL_PATTERN);
|
final String action = page.findFormAction(UPLOAD_URI_PATTERN);
|
||||||
|
|
||||||
logger.debug("Upload URL is {}", action);
|
logger.debug("Upload URI is {}", action);
|
||||||
|
|
||||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ public class HotFileService extends AbstractHttpService implements Service,
|
|||||||
@Override
|
@Override
|
||||||
public String finish() throws IOException {
|
public String finish() throws IOException {
|
||||||
try {
|
try {
|
||||||
return uploadFuture.get().getInputValue(DOWNLOAD_URL_PATTERN);
|
return uploadFuture.get().getInputValue(DOWNLOAD_URI_PATTERN);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return null;
|
return null;
|
||||||
} catch (ExecutionException e) {
|
} catch (ExecutionException e) {
|
||||||
@@ -223,15 +223,15 @@ public class HotFileService extends AbstractHttpService implements Service,
|
|||||||
|
|
||||||
protected class DownloaderImpl extends
|
protected class DownloaderImpl extends
|
||||||
AbstractHttpDownloader<NullDownloaderConfiguration> {
|
AbstractHttpDownloader<NullDownloaderConfiguration> {
|
||||||
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
|
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
|
||||||
super(url, configuration);
|
super(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DownloadChannel openChannel(DownloadListener listener,
|
public DownloadChannel openChannel(DownloadListener listener,
|
||||||
long position) throws IOException {
|
long position) throws IOException {
|
||||||
logger.debug("Downloading {} from hotfile.com", url);
|
logger.debug("Downloading {} from hotfile.com", uri);
|
||||||
final HTMLPage page = get(url).asPage();
|
final HTMLPage page = get(uri).asPage();
|
||||||
|
|
||||||
// // try to find timer
|
// // try to find timer
|
||||||
// final String stringTimer = PatternUtils.find(DOWNLOAD_TIMER,
|
// final String stringTimer = PatternUtils.find(DOWNLOAD_TIMER,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.SeekableByteChannel;
|
import java.nio.channels.SeekableByteChannel;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -80,7 +80,7 @@ public class HotFileServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServiceId() {
|
public void testServiceId() {
|
||||||
assertEquals(ServiceID.create("hotfile"), service.getID());
|
assertEquals(ServiceID.create("hotfile"), service.getServiceID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -146,10 +146,10 @@ public class HotFileServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDownloader() throws IOException {
|
public void testDownloader() throws IOException {
|
||||||
final URL downloadUrl = new URL(
|
final URI downloadUrl = URI
|
||||||
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.htm");
|
.create("http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.htm");
|
||||||
|
|
||||||
final DownloadService<?> service = Services.matchURL(downloadUrl);
|
final DownloadService<?> service = Services.matchURI(downloadUrl);
|
||||||
|
|
||||||
final DownloadChannel channel = service.getDownloader(downloadUrl)
|
final DownloadChannel channel = service.getDownloader(downloadUrl)
|
||||||
.openChannel(null, 0);
|
.openChannel(null, 0);
|
||||||
@@ -165,8 +165,7 @@ public class HotFileServiceTest {
|
|||||||
|
|
||||||
final DownloadChannel channel = service
|
final DownloadChannel channel = service
|
||||||
.getDownloader(
|
.getDownloader(
|
||||||
new URL(
|
URI.create("http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
|
||||||
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
|
|
||||||
.openChannel(null, 0);
|
.openChannel(null, 0);
|
||||||
|
|
||||||
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service-megaupload</artifactId>
|
<artifactId>httpchannel-service-megaupload</artifactId>
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package com.rogiel.httpchannel.service.impl;
|
package com.rogiel.httpchannel.service.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -71,7 +71,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
|||||||
*/
|
*/
|
||||||
public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
|
public static final ServiceID SERVICE_ID = ServiceID.create("megaupload");
|
||||||
|
|
||||||
private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
private static final Pattern UPLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://www([0-9]*)\\.megaupload\\.com/upload_done\\.php\\?UPLOAD_IDENTIFIER=[0-9]*");
|
.compile("http://www([0-9]*)\\.megaupload\\.com/upload_done\\.php\\?UPLOAD_IDENTIFIER=[0-9]*");
|
||||||
|
|
||||||
private static final Pattern DOWNLOAD_DIRECT_LINK_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_DIRECT_LINK_PATTERN = Pattern
|
||||||
@@ -81,14 +81,14 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
|||||||
// private static final Pattern DOWNLOAD_FILESIZE = Pattern
|
// private static final Pattern DOWNLOAD_FILESIZE = Pattern
|
||||||
// .compile("[0-9]*(\\.[0-9]*)? (K|M|G)B");
|
// .compile("[0-9]*(\\.[0-9]*)? (K|M|G)B");
|
||||||
|
|
||||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://www\\.megaupload\\.com/\\?d=([A-Za-z0-9]*)");
|
.compile("http://www\\.megaupload\\.com/\\?d=([A-Za-z0-9]*)");
|
||||||
|
|
||||||
private static final Pattern LOGIN_USERNAME_PATTERN = Pattern
|
private static final Pattern LOGIN_USERNAME_PATTERN = Pattern
|
||||||
.compile("flashvars\\.username = \"(.*)\";");
|
.compile("flashvars\\.username = \"(.*)\";");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID getID() {
|
public ServiceID getServiceID() {
|
||||||
return SERVICE_ID;
|
return SERVICE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,14 +139,14 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URL url,
|
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URI uri,
|
||||||
MegaUploadDownloaderConfiguration configuration) {
|
MegaUploadDownloaderConfiguration configuration) {
|
||||||
return new DownloaderImpl(url, configuration);
|
return new DownloaderImpl(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URL url) {
|
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URI uri) {
|
||||||
return getDownloader(url, newDownloaderConfiguration());
|
return getDownloader(uri, newDownloaderConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -155,8 +155,8 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matchURL(URL url) {
|
public boolean matchURI(URI uri) {
|
||||||
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
|
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -208,11 +208,11 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
|||||||
logger.debug("Starting upload to megaupload.com");
|
logger.debug("Starting upload to megaupload.com");
|
||||||
final HTMLPage page = get("http://www.megaupload.com/multiupload/")
|
final HTMLPage page = get("http://www.megaupload.com/multiupload/")
|
||||||
.asPage();
|
.asPage();
|
||||||
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
|
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
|
||||||
logger.debug("Upload URL is {}", url);
|
logger.debug("Upload URI is {}", uri);
|
||||||
|
|
||||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
uploadFuture = multipartPost(url)
|
uploadFuture = multipartPost(uri)
|
||||||
.parameter("multimessage_0", configuration.description())
|
.parameter("multimessage_0", configuration.description())
|
||||||
.parameter("multifile_0", channel).asStringAsync();
|
.parameter("multifile_0", channel).asStringAsync();
|
||||||
return waitChannelLink(channel, uploadFuture);
|
return waitChannelLink(channel, uploadFuture);
|
||||||
@@ -221,7 +221,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
|||||||
@Override
|
@Override
|
||||||
public String finish() throws IOException {
|
public String finish() throws IOException {
|
||||||
try {
|
try {
|
||||||
return PatternUtils.find(DOWNLOAD_URL_PATTERN,
|
return PatternUtils.find(DOWNLOAD_URI_PATTERN,
|
||||||
uploadFuture.get());
|
uploadFuture.get());
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
return null;
|
return null;
|
||||||
@@ -234,16 +234,16 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
|||||||
protected class DownloaderImpl extends
|
protected class DownloaderImpl extends
|
||||||
AbstractHttpDownloader<MegaUploadDownloaderConfiguration> implements
|
AbstractHttpDownloader<MegaUploadDownloaderConfiguration> implements
|
||||||
Downloader<MegaUploadDownloaderConfiguration> {
|
Downloader<MegaUploadDownloaderConfiguration> {
|
||||||
public DownloaderImpl(URL url,
|
public DownloaderImpl(URI uri,
|
||||||
MegaUploadDownloaderConfiguration configuration) {
|
MegaUploadDownloaderConfiguration configuration) {
|
||||||
super(url, configuration);
|
super(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DownloadChannel openChannel(DownloadListener listener,
|
public DownloadChannel openChannel(DownloadListener listener,
|
||||||
long position) throws IOException {
|
long position) throws IOException {
|
||||||
logger.debug("Starting {} download from megaupload.com", url);
|
logger.debug("Starting {} download from megaupload.com", uri);
|
||||||
HttpResponse response = get(url).request();
|
HttpResponse response = get(uri).request();
|
||||||
|
|
||||||
// disable direct downloads, we don't support them!
|
// disable direct downloads, we don't support them!
|
||||||
if (response.getEntity().getContentType().getValue()
|
if (response.getEntity().getContentType().getValue()
|
||||||
@@ -259,7 +259,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
|||||||
.parameter("set_ddl", "0").request();
|
.parameter("set_ddl", "0").request();
|
||||||
|
|
||||||
// execute and re-request download
|
// execute and re-request download
|
||||||
response = get(url).request();
|
response = get(uri).request();
|
||||||
}
|
}
|
||||||
|
|
||||||
final HTMLPage page = HttpClientUtils.toPage(response);
|
final HTMLPage page = HttpClientUtils.toPage(response);
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.SeekableByteChannel;
|
import java.nio.channels.SeekableByteChannel;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -79,7 +79,7 @@ public class MegaUploadServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testServiceId() {
|
public void testServiceId() {
|
||||||
assertEquals(ServiceID.create("megaupload"), service.getID());
|
assertEquals(ServiceID.create("megaupload"), service.getServiceID());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -145,7 +145,7 @@ public class MegaUploadServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testFreeDownloader() throws IOException {
|
public void testFreeDownloader() throws IOException {
|
||||||
final DownloadChannel channel = service.getDownloader(
|
final DownloadChannel channel = service.getDownloader(
|
||||||
new URL("http://www.megaupload.com/?d=CVQKJ1KM")).openChannel(
|
URI.create("http://www.megaupload.com/?d=CVQKJ1KM")).openChannel(
|
||||||
new DownloadListener() {
|
new DownloadListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean timer(long time) {
|
public boolean timer(long time) {
|
||||||
@@ -166,7 +166,7 @@ public class MegaUploadServiceTest {
|
|||||||
.login();
|
.login();
|
||||||
|
|
||||||
final DownloadChannel channel = service.getDownloader(
|
final DownloadChannel channel = service.getDownloader(
|
||||||
new URL("http://www.megaupload.com/?d=CVQKJ1KM")).openChannel(
|
URI.create("http://www.megaupload.com/?d=CVQKJ1KM")).openChannel(
|
||||||
new DownloadListener() {
|
new DownloadListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean timer(long time) {
|
public boolean timer(long time) {
|
||||||
@@ -190,7 +190,7 @@ public class MegaUploadServiceTest {
|
|||||||
|
|
||||||
@SuppressWarnings({ "unused" })
|
@SuppressWarnings({ "unused" })
|
||||||
final DownloadChannel channel = service.getDownloader(
|
final DownloadChannel channel = service.getDownloader(
|
||||||
new URL("http://www.megaupload.com/?d=CVQKJ1KM"), config)
|
URI.create("http://www.megaupload.com/?d=CVQKJ1KM"), config)
|
||||||
.openChannel(new DownloadListener() {
|
.openChannel(new DownloadListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean timer(long time) {
|
public boolean timer(long time) {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service-multiupload</artifactId>
|
<artifactId>httpchannel-service-multiupload</artifactId>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.rogiel.httpchannel.service.impl;
|
package com.rogiel.httpchannel.service.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -56,7 +56,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
public static final ServiceID SERVICE_ID = ServiceID.create("multiupload");
|
public static final ServiceID SERVICE_ID = ServiceID.create("multiupload");
|
||||||
|
|
||||||
// http://www52.multiupload.com/upload/?UPLOAD_IDENTIFIER=73132658610746
|
// http://www52.multiupload.com/upload/?UPLOAD_IDENTIFIER=73132658610746
|
||||||
private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
private static final Pattern UPLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://www([0-9]*)\\.multiupload\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
|
.compile("http://www([0-9]*)\\.multiupload\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
|
||||||
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
||||||
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
||||||
@@ -66,7 +66,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
.compile("http://www[0-9]*\\.multiupload\\.com(:[0-9]*)?/files/([0-9a-zA-Z]*)/(.*)");
|
.compile("http://www[0-9]*\\.multiupload\\.com(:[0-9]*)?/files/([0-9a-zA-Z]*)/(.*)");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID getID() {
|
public ServiceID getServiceID() {
|
||||||
return SERVICE_ID;
|
return SERVICE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -119,14 +119,14 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
|
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
|
||||||
NullDownloaderConfiguration configuration) {
|
NullDownloaderConfiguration configuration) {
|
||||||
return new DownloaderImpl(url, configuration);
|
return new DownloaderImpl(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
|
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
|
||||||
return getDownloader(url, newDownloaderConfiguration());
|
return getDownloader(uri, newDownloaderConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -135,8 +135,8 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matchURL(URL url) {
|
public boolean matchURI(URI uri) {
|
||||||
return DOWNLOAD_LINK_PATTERN.matcher(url.toString()).matches();
|
return DOWNLOAD_LINK_PATTERN.matcher(uri.toString()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -184,12 +184,12 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
@Override
|
@Override
|
||||||
public UploadChannel openChannel() throws IOException {
|
public UploadChannel openChannel() throws IOException {
|
||||||
logger.debug("Starting upload to multiupload.com");
|
logger.debug("Starting upload to multiupload.com");
|
||||||
final String url = get("http://www.multiupload.com/").asPage()
|
final String uri = get("http://www.multiupload.com/").asPage()
|
||||||
.findFormAction(UPLOAD_URL_PATTERN);
|
.findFormAction(UPLOAD_URI_PATTERN);
|
||||||
logger.debug("Upload URL is {}", url);
|
logger.debug("Upload URI is {}", uri);
|
||||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
|
|
||||||
PostMultipartRequest request = multipartPost(url).parameter(
|
PostMultipartRequest request = multipartPost(uri).parameter(
|
||||||
"description_0", configuration.description()).parameter(
|
"description_0", configuration.description()).parameter(
|
||||||
"file_0", channel);
|
"file_0", channel);
|
||||||
for (final MultiUploadMirrorService mirror : configuration
|
for (final MultiUploadMirrorService mirror : configuration
|
||||||
@@ -223,9 +223,9 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
protected class DownloaderImpl extends
|
protected class DownloaderImpl extends
|
||||||
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
||||||
Downloader<NullDownloaderConfiguration> {
|
Downloader<NullDownloaderConfiguration> {
|
||||||
protected DownloaderImpl(URL url,
|
protected DownloaderImpl(URI uri,
|
||||||
NullDownloaderConfiguration configuration) {
|
NullDownloaderConfiguration configuration) {
|
||||||
super(url, configuration);
|
super(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -233,7 +233,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
|||||||
long position) throws IOException,
|
long position) throws IOException,
|
||||||
DownloadLinkNotFoundException, DownloadLimitExceededException,
|
DownloadLinkNotFoundException, DownloadLimitExceededException,
|
||||||
DownloadNotAuthorizedException, DownloadNotResumableException {
|
DownloadNotAuthorizedException, DownloadNotResumableException {
|
||||||
final HTMLPage page = get(url).asPage();
|
final HTMLPage page = get(uri).asPage();
|
||||||
final String link = page.findLink(DIRECT_DOWNLOAD_LINK_PATTERN);
|
final String link = page.findLink(DIRECT_DOWNLOAD_LINK_PATTERN);
|
||||||
logger.debug("Direct download link is {}", link);
|
logger.debug("Direct download link is {}", link);
|
||||||
if (link == null)
|
if (link == null)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.rogiel.httpchannel.service.impl;
|
package com.rogiel.httpchannel.service.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@@ -33,16 +33,16 @@ public class MultiUploadServiceTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUploader() throws IOException {
|
public void testUploader() throws IOException {
|
||||||
final URL url = ChannelUtils.upload(service, TEST_UPLOAD_FILE);
|
final URI uri = ChannelUtils.upload(service, TEST_UPLOAD_FILE);
|
||||||
Assert.assertNotNull(url);
|
Assert.assertNotNull(uri);
|
||||||
System.out.println("Uploaded file to " + url);
|
System.out.println("Uploaded file to " + uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDownloader() throws IOException, NoSuchAlgorithmException {
|
public void testDownloader() throws IOException, NoSuchAlgorithmException {
|
||||||
final byte[] data = ChannelUtils
|
final byte[] data = ChannelUtils
|
||||||
.toByteArray(((DownloadService<?>) service).getDownloader(
|
.toByteArray(((DownloadService<?>) service).getDownloader(
|
||||||
new URL("http://www.multiupload.com/TJOYWB4JEW"))
|
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
|
||||||
.openChannel());
|
.openChannel());
|
||||||
assertChecksum("Downloaded data checksum did not matched", "SHA1",
|
assertChecksum("Downloaded data checksum did not matched", "SHA1",
|
||||||
data, EXPECTED_FULL_CHECKSUM);
|
data, EXPECTED_FULL_CHECKSUM);
|
||||||
@@ -53,7 +53,7 @@ public class MultiUploadServiceTest {
|
|||||||
NoSuchAlgorithmException {
|
NoSuchAlgorithmException {
|
||||||
final byte[] data = ChannelUtils
|
final byte[] data = ChannelUtils
|
||||||
.toByteArray(((DownloadService<?>) service).getDownloader(
|
.toByteArray(((DownloadService<?>) service).getDownloader(
|
||||||
new URL("http://www.multiupload.com/TJOYWB4JEW"))
|
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
|
||||||
.openChannel(50));
|
.openChannel(50));
|
||||||
assertChecksum("Downloaded data checksum did not matched", "SHA1",
|
assertChecksum("Downloaded data checksum did not matched", "SHA1",
|
||||||
data, EXPECTED_RESUME_CHECKSUM);
|
data, EXPECTED_RESUME_CHECKSUM);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service-uploadhere</artifactId>
|
<artifactId>httpchannel-service-uploadhere</artifactId>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.rogiel.httpchannel.service.impl;
|
package com.rogiel.httpchannel.service.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -54,21 +54,21 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
|||||||
*/
|
*/
|
||||||
public static final ServiceID SERVICE_ID = ServiceID.create("uploadhere");
|
public static final ServiceID SERVICE_ID = ServiceID.create("uploadhere");
|
||||||
|
|
||||||
private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
private static final Pattern UPLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://www([0-9]*)\\.uploadhere\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
|
.compile("http://www([0-9]*)\\.uploadhere\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
|
||||||
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
||||||
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
||||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://(www\\.)?uploadhere.\\com/[0-9A-z]*");
|
.compile("http://(www\\.)?uploadhere.\\com/[0-9A-z]*");
|
||||||
private static final Pattern TIMER_PATTERN = Pattern.compile(
|
private static final Pattern TIMER_PATTERN = Pattern.compile(
|
||||||
"count = ([0-9]*);", Pattern.COMMENTS);
|
"count = ([0-9]*);", Pattern.COMMENTS);
|
||||||
private static final Pattern DIERCT_DOWNLOAD_URL_PATTERN = Pattern
|
private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
|
||||||
.compile("(http:\\\\/\\\\/www[0-9]*\\.uploadhere\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
|
.compile("(http:\\\\/\\\\/www[0-9]*\\.uploadhere\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
|
||||||
|
|
||||||
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
|
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID getID() {
|
public ServiceID getServiceID() {
|
||||||
return SERVICE_ID;
|
return SERVICE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,14 +118,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
|
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
|
||||||
NullDownloaderConfiguration configuration) {
|
NullDownloaderConfiguration configuration) {
|
||||||
return new DownloaderImpl(url, configuration);
|
return new DownloaderImpl(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
|
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
|
||||||
return getDownloader(url, newDownloaderConfiguration());
|
return getDownloader(uri, newDownloaderConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -134,8 +134,8 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matchURL(URL url) {
|
public boolean matchURI(URI uri) {
|
||||||
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
|
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,14 +185,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
|||||||
final HTMLPage page = get("http://www.uploadhere.com/").asPage();
|
final HTMLPage page = get("http://www.uploadhere.com/").asPage();
|
||||||
|
|
||||||
final String userCookie = page.getInputValueById("usercookie");
|
final String userCookie = page.getInputValueById("usercookie");
|
||||||
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
|
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
|
||||||
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
|
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
|
||||||
|
|
||||||
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
|
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
|
||||||
new Object[] { url, userCookie, uploadID });
|
new Object[] { uri, userCookie, uploadID });
|
||||||
|
|
||||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
uploadFuture = multipartPost(url).parameter("file_0", channel)
|
uploadFuture = multipartPost(uri).parameter("file_0", channel)
|
||||||
.parameter("u", userCookie)
|
.parameter("u", userCookie)
|
||||||
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
|
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
|
||||||
return waitChannelLink(channel, uploadFuture);
|
return waitChannelLink(channel, uploadFuture);
|
||||||
@@ -222,14 +222,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
|||||||
protected class DownloaderImpl extends
|
protected class DownloaderImpl extends
|
||||||
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
||||||
Downloader<NullDownloaderConfiguration> {
|
Downloader<NullDownloaderConfiguration> {
|
||||||
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
|
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
|
||||||
super(url, configuration);
|
super(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DownloadChannel openChannel(DownloadListener listener,
|
public DownloadChannel openChannel(DownloadListener listener,
|
||||||
long position) throws IOException {
|
long position) throws IOException {
|
||||||
HTMLPage page = get(url).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);
|
||||||
@@ -251,12 +251,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
|||||||
logger.debug("CAPTCHA solving took longer than timer, skipping it");
|
logger.debug("CAPTCHA solving took longer than timer, skipping it");
|
||||||
}
|
}
|
||||||
|
|
||||||
String content = post(url)
|
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();
|
||||||
String downloadLink = PatternUtils.find(
|
String downloadLink = PatternUtils.find(
|
||||||
DIERCT_DOWNLOAD_URL_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 InvalidCaptchaException();
|
||||||
@@ -265,7 +265,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
||||||
"/");
|
"/");
|
||||||
logger.debug("Direct download URL is {}", downloadLink);
|
logger.debug("Direct download URI is {}", downloadLink);
|
||||||
return download(get(downloadLink).position(position));
|
return download(get(downloadLink).position(position));
|
||||||
}
|
}
|
||||||
throw new DownloadLinkNotFoundException();
|
throw new DownloadLinkNotFoundException();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
@@ -31,10 +31,10 @@ public class UploadHereServiceTest {
|
|||||||
UploaderCapability.UNAUTHENTICATED_UPLOAD));
|
UploaderCapability.UNAUTHENTICATED_UPLOAD));
|
||||||
|
|
||||||
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
||||||
final URL url = ChannelUtils.upload(service, path);
|
final URI uri = ChannelUtils.upload(service, path);
|
||||||
|
|
||||||
Assert.assertNotNull(url);
|
Assert.assertNotNull(uri);
|
||||||
System.out.println(url);
|
System.out.println(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Test
|
// @Test
|
||||||
@@ -43,7 +43,7 @@ public class UploadHereServiceTest {
|
|||||||
// @Override
|
// @Override
|
||||||
// public boolean resolve(Captcha rawCaptcha) {
|
// public boolean resolve(Captcha rawCaptcha) {
|
||||||
// final ImageCaptcha captcha = (ImageCaptcha) rawCaptcha;
|
// final ImageCaptcha captcha = (ImageCaptcha) rawCaptcha;
|
||||||
// System.out.println(captcha.getImageURL());
|
// System.out.println(captcha.getImageURI());
|
||||||
// try {
|
// try {
|
||||||
// captcha.setAnswer(new BufferedReader(new InputStreamReader(
|
// captcha.setAnswer(new BufferedReader(new InputStreamReader(
|
||||||
// System.in)).readLine());
|
// System.in)).readLine());
|
||||||
@@ -56,7 +56,7 @@ public class UploadHereServiceTest {
|
|||||||
// });
|
// });
|
||||||
//
|
//
|
||||||
// final DownloadChannel channel = service.getDownloader(
|
// final DownloadChannel channel = service.getDownloader(
|
||||||
// new URL("http://www.uploadhere.com/9WCEQF1Q07")).openChannel();
|
// new URI("http://www.uploadhere.com/9WCEQF1Q07")).openChannel();
|
||||||
// System.out.println(new String(ChannelUtils.toByteArray(channel)));
|
// System.out.println(new String(ChannelUtils.toByteArray(channel)));
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service-uploadking</artifactId>
|
<artifactId>httpchannel-service-uploadking</artifactId>
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rogiel.httpchannel.captcha</groupId>
|
<groupId>com.rogiel.httpchannel.captcha</groupId>
|
||||||
<artifactId>httpchannel-captcha-captchatrader</artifactId>
|
<artifactId>httpchannel-captcha-captchatrader</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package com.rogiel.httpchannel.service.impl;
|
package com.rogiel.httpchannel.service.impl;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -54,21 +54,21 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
|||||||
*/
|
*/
|
||||||
public static final ServiceID SERVICE_ID = ServiceID.create("uploadking");
|
public static final ServiceID SERVICE_ID = ServiceID.create("uploadking");
|
||||||
|
|
||||||
private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
private static final Pattern UPLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://www([0-9]*)\\.uploadking\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
|
.compile("http://www([0-9]*)\\.uploadking\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
|
||||||
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
||||||
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
||||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||||
.compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
|
.compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
|
||||||
private static final Pattern TIMER_PATTERN = Pattern.compile(
|
private static final Pattern TIMER_PATTERN = Pattern.compile(
|
||||||
"count = ([0-9]*);", Pattern.COMMENTS);
|
"count = ([0-9]*);", Pattern.COMMENTS);
|
||||||
private static final Pattern DIERCT_DOWNLOAD_URL_PATTERN = Pattern
|
private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
|
||||||
.compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
|
.compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
|
||||||
|
|
||||||
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
|
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID getID() {
|
public ServiceID getServiceID() {
|
||||||
return SERVICE_ID;
|
return SERVICE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,14 +118,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
|
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
|
||||||
NullDownloaderConfiguration configuration) {
|
NullDownloaderConfiguration configuration) {
|
||||||
return new DownloaderImpl(url, configuration);
|
return new DownloaderImpl(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
|
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
|
||||||
return getDownloader(url, newDownloaderConfiguration());
|
return getDownloader(uri, newDownloaderConfiguration());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -134,8 +134,8 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean matchURL(URL url) {
|
public boolean matchURI(URI uri) {
|
||||||
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
|
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -185,14 +185,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
|||||||
final HTMLPage page = get("http://www.uploadking.com/").asPage();
|
final HTMLPage page = get("http://www.uploadking.com/").asPage();
|
||||||
|
|
||||||
final String userCookie = page.getInputValueById("usercookie");
|
final String userCookie = page.getInputValueById("usercookie");
|
||||||
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
|
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
|
||||||
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
|
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
|
||||||
|
|
||||||
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
|
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
|
||||||
new Object[] { url, userCookie, uploadID });
|
new Object[] { uri, userCookie, uploadID });
|
||||||
|
|
||||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
uploadFuture = multipartPost(url).parameter("file", channel)
|
uploadFuture = multipartPost(uri).parameter("file", channel)
|
||||||
.parameter("u", userCookie)
|
.parameter("u", userCookie)
|
||||||
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
|
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
|
||||||
return waitChannelLink(channel, uploadFuture);
|
return waitChannelLink(channel, uploadFuture);
|
||||||
@@ -219,15 +219,15 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
|||||||
protected class DownloaderImpl extends
|
protected class DownloaderImpl extends
|
||||||
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
||||||
Downloader<NullDownloaderConfiguration> {
|
Downloader<NullDownloaderConfiguration> {
|
||||||
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
|
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
|
||||||
super(url, configuration);
|
super(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@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");
|
logger.debug("Downloading {} with uploadking.com");
|
||||||
HTMLPage page = get(url).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);
|
||||||
@@ -250,12 +250,12 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
|||||||
logger.debug("CAPTCHA solving took longer than timer, skipping it");
|
logger.debug("CAPTCHA solving took longer than timer, skipping it");
|
||||||
}
|
}
|
||||||
|
|
||||||
String content = post(url)
|
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();
|
||||||
String downloadLink = PatternUtils.find(
|
String downloadLink = PatternUtils.find(
|
||||||
DIERCT_DOWNLOAD_URL_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 InvalidCaptchaException();
|
||||||
@@ -264,7 +264,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
|||||||
}
|
}
|
||||||
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
||||||
"/");
|
"/");
|
||||||
logger.debug("Direct download URL is {}", downloadLink);
|
logger.debug("Direct download URI is {}", downloadLink);
|
||||||
return download(get(downloadLink).position(position));
|
return download(get(downloadLink).position(position));
|
||||||
}
|
}
|
||||||
throw new DownloadLinkNotFoundException();
|
throw new DownloadLinkNotFoundException();
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
@@ -37,10 +37,10 @@ public class UploadKingServiceTest {
|
|||||||
UploaderCapability.UNAUTHENTICATED_UPLOAD));
|
UploaderCapability.UNAUTHENTICATED_UPLOAD));
|
||||||
|
|
||||||
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
||||||
final URL url = ChannelUtils.upload(service, path);
|
final URI uri = ChannelUtils.upload(service, path);
|
||||||
|
|
||||||
Assert.assertNotNull(url);
|
Assert.assertNotNull(uri);
|
||||||
System.out.println(url);
|
System.out.println(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -55,7 +55,8 @@ public class UploadKingServiceTest {
|
|||||||
service.setCaptchaService(s);
|
service.setCaptchaService(s);
|
||||||
|
|
||||||
final DownloadChannel channel = service.getDownloader(
|
final DownloadChannel channel = service.getDownloader(
|
||||||
new URL("http://www.uploadking.com/WM3PHD9JAY")).openChannel(0);
|
URI.create("http://www.uploadking.com/WM3PHD9JAY"))
|
||||||
|
.openChannel(0);
|
||||||
System.out.println(new String(ChannelUtils.toByteArray(channel)));
|
System.out.println(new String(ChannelUtils.toByteArray(channel)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service-zshare</artifactId>
|
<artifactId>httpchannel-service-zshare</artifactId>
|
||||||
|
|||||||
@@ -30,22 +30,22 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
|||||||
*/
|
*/
|
||||||
public static final ServiceID SERVICE_ID = ServiceID.create("zshare");
|
public static final ServiceID SERVICE_ID = ServiceID.create("zshare");
|
||||||
|
|
||||||
// private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
// private static final Pattern UPLOAD_URI_PATTERN = Pattern
|
||||||
// .compile("http://dl([0-9]*)\\.zshare\\.net(\\:[0-9]*)?/",
|
// .compile("http://dl([0-9]*)\\.zshare\\.net(\\:[0-9]*)?/",
|
||||||
// Pattern.CASE_INSENSITIVE);
|
// Pattern.CASE_INSENSITIVE);
|
||||||
// private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
// private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
||||||
// .compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
// .compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
||||||
// private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
// private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||||
// .compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
|
// .compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
|
||||||
// private static final Pattern TIMER_PATTERN = Pattern.compile(
|
// private static final Pattern TIMER_PATTERN = Pattern.compile(
|
||||||
// "count = ([0-9]*);", Pattern.COMMENTS);
|
// "count = ([0-9]*);", Pattern.COMMENTS);
|
||||||
// private static final Pattern DIERCT_DOWNLOAD_URL_PATTERN = Pattern
|
// private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
|
||||||
// .compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
|
// .compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
|
||||||
//
|
//
|
||||||
// private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
|
// private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ServiceID getID() {
|
public ServiceID getServiceID() {
|
||||||
return SERVICE_ID;
|
return SERVICE_ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,14 +95,14 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// @Override
|
// @Override
|
||||||
// public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
|
// public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
|
||||||
// NullDownloaderConfiguration configuration) {
|
// NullDownloaderConfiguration configuration) {
|
||||||
// return new DownloaderImpl(url, configuration);
|
// return new DownloaderImpl(uri, configuration);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// @Override
|
// @Override
|
||||||
// public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
|
// public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
|
||||||
// return getDownloader(url, newDownloaderConfiguration());
|
// return getDownloader(uri, newDownloaderConfiguration());
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// @Override
|
// @Override
|
||||||
@@ -111,8 +111,8 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// @Override
|
// @Override
|
||||||
// public boolean matchURL(URL url) {
|
// public boolean matchURI(URI uri) {
|
||||||
// return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
|
// return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// @Override
|
// @Override
|
||||||
@@ -162,12 +162,12 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
|||||||
// public UploadChannel openChannel() throws IOException {
|
// public UploadChannel openChannel() throws IOException {
|
||||||
// final HTMLPage page = get("http://www.zshare.net/").asPage();
|
// final HTMLPage page = get("http://www.zshare.net/").asPage();
|
||||||
//
|
//
|
||||||
// final String url = page.findFormAction(UPLOAD_URL_PATTERN);
|
// final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
|
||||||
// System.out.println(url+"cgi-bin/ubr_upload.pl");
|
// System.out.println(uri+"cgi-bin/ubr_upload.pl");
|
||||||
//
|
//
|
||||||
// final LinkedUploadChannel channel = createLinkedChannel(this);
|
// final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||||
// uploadFuture =
|
// uploadFuture =
|
||||||
// multipartPost(url+"cgi-bin/ubr_upload.pl").parameter("file", channel)
|
// multipartPost(uri+"cgi-bin/ubr_upload.pl").parameter("file", channel)
|
||||||
// .parameter("descr", configuration.description())
|
// .parameter("descr", configuration.description())
|
||||||
// .parameter("TOS", true).parameter("is_private", false)
|
// .parameter("TOS", true).parameter("is_private", false)
|
||||||
// .asStringAsync();
|
// .asStringAsync();
|
||||||
@@ -196,15 +196,15 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
|||||||
// protected class DownloaderImpl extends
|
// protected class DownloaderImpl extends
|
||||||
// AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
// AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
||||||
// Downloader<NullDownloaderConfiguration> {
|
// Downloader<NullDownloaderConfiguration> {
|
||||||
// public DownloaderImpl(URL url, NullDownloaderConfiguration configuration)
|
// public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration)
|
||||||
// {
|
// {
|
||||||
// super(url, configuration);
|
// super(uri, configuration);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// @Override
|
// @Override
|
||||||
// public DownloadChannel openChannel(DownloadListener listener,
|
// public DownloadChannel openChannel(DownloadListener listener,
|
||||||
// long position) throws IOException {
|
// long position) throws IOException {
|
||||||
// HTMLPage page = get(url).asPage();
|
// HTMLPage page = get(uri).asPage();
|
||||||
//
|
//
|
||||||
// final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
|
// final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
|
||||||
//
|
//
|
||||||
@@ -218,12 +218,12 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
|||||||
// // if (delta < waitTime)
|
// // if (delta < waitTime)
|
||||||
// // timer(listener, waitTime - delta);
|
// // timer(listener, waitTime - delta);
|
||||||
// //
|
// //
|
||||||
// // String content = post(url)
|
// // 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();
|
||||||
// // String downloadLink = PatternUtils.find(
|
// // String downloadLink = PatternUtils.find(
|
||||||
// // DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
|
// // DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
|
||||||
// // if (downloadLink == null)
|
// // if (downloadLink == null)
|
||||||
// // throw new InvalidCaptchaException();
|
// // throw new InvalidCaptchaException();
|
||||||
// // downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
// // downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel</artifactId>
|
<artifactId>httpchannel</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-service</artifactId>
|
<artifactId>httpchannel-service</artifactId>
|
||||||
@@ -26,12 +26,12 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<artifactId>httpchannel-api</artifactId>
|
<artifactId>httpchannel-api</artifactId>
|
||||||
<version>${project.version}</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<artifactId>httpchannel-util</artifactId>
|
<artifactId>httpchannel-util</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>httpchannel</artifactId>
|
<artifactId>httpchannel</artifactId>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<relativePath>..</relativePath>
|
<relativePath>..</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
<artifactId>httpchannel-util</artifactId>
|
<artifactId>httpchannel-util</artifactId>
|
||||||
@@ -12,7 +12,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<artifactId>httpchannel-api</artifactId>
|
<artifactId>httpchannel-api</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.httpcomponents</groupId>
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
|||||||
@@ -4,8 +4,7 @@
|
|||||||
package com.rogiel.httpchannel.captcha;
|
package com.rogiel.httpchannel.captcha;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.rogiel.httpchannel.http.HttpContext;
|
import com.rogiel.httpchannel.http.HttpContext;
|
||||||
@@ -13,46 +12,73 @@ import com.rogiel.httpchannel.util.PatternUtils;
|
|||||||
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* This class provides utility methods to extract an {@link ImageCaptcha} from
|
||||||
|
* an page containing an Google ReCaptcha CAPTCHA embedded into it.
|
||||||
*
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public class ReCaptchaExtractor {
|
public class ReCaptchaExtractor {
|
||||||
|
/**
|
||||||
|
* This pattern extracts the SITE-ID from the Ajax ReCaptcha API
|
||||||
|
*/
|
||||||
private static final Pattern CAPTCHA_ID_PATTERN = Pattern
|
private static final Pattern CAPTCHA_ID_PATTERN = Pattern
|
||||||
.compile("Recaptcha\\.create\\(\"([0-9A-z|_|\\-]*)\", ");
|
.compile("Recaptcha\\.create\\(\"([0-9A-z|_|\\-]*)\", ");
|
||||||
private static final Pattern CAPTCHA_URL_PATTERN = Pattern
|
private static final Pattern CAPTCHA_URI_PATTERN = Pattern
|
||||||
.compile("http://www\\.google\\.com/recaptcha/api/challenge\\?k=([0-9A-z|\\-]*)(&(.*))?");
|
.compile("http://www\\.google\\.com/recaptcha/api/challenge\\?k=([0-9A-z|\\-]*)(&(.*))?");
|
||||||
private static final Pattern CAPTCHA_IMAGE_PATTERN = Pattern
|
private static final Pattern CAPTCHA_IMAGE_PATTERN = Pattern
|
||||||
.compile("challenge : '(.*)'");
|
.compile("challenge : '(.*)'");
|
||||||
|
|
||||||
private static final String CHALLENGE_BASE_URL = "http://www.google.com/recaptcha/api/challenge?ajax=1&k=";
|
private static final String CHALLENGE_BASE_URI = "http://www.google.com/recaptcha/api/challenge?ajax=1&k=";
|
||||||
private static final String IMAGE_BASE_URL = "http://www.google.com/recaptcha/api/image?c=";
|
private static final String IMAGE_BASE_URI = "http://www.google.com/recaptcha/api/image?c=";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the {@link ImageCaptcha} for an ReCAPTCHA using the standard JS
|
||||||
|
* include method
|
||||||
|
*
|
||||||
|
* @param page
|
||||||
|
* the page
|
||||||
|
* @param ctx
|
||||||
|
* the {@link HttpContext}
|
||||||
|
* @return the {@link ImageCaptcha} embedded at the given <code>page</code>
|
||||||
|
*/
|
||||||
public static ImageCaptcha extractCaptcha(HTMLPage page, HttpContext ctx) {
|
public static ImageCaptcha extractCaptcha(HTMLPage page, HttpContext ctx) {
|
||||||
final String url = page.findScriptSrc(CAPTCHA_URL_PATTERN);
|
final String uri = page.findScriptSrc(CAPTCHA_URI_PATTERN);
|
||||||
if (url == null)
|
if (uri == null)
|
||||||
return null;
|
return null;
|
||||||
try {
|
try {
|
||||||
return doExtract(ctx.get(url).asString());
|
return doExtract(ctx.get(uri).asString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the {@link ImageCaptcha} for an ReCAPTCHA using the Ajax API
|
||||||
|
*
|
||||||
|
* @param page
|
||||||
|
* the page
|
||||||
|
* @param ctx
|
||||||
|
* the {@link HttpContext}
|
||||||
|
* @return the {@link ImageCaptcha} contained at the given <code>page</code>
|
||||||
|
*/
|
||||||
public static ImageCaptcha extractAjaxCaptcha(HTMLPage page, HttpContext ctx) {
|
public static ImageCaptcha extractAjaxCaptcha(HTMLPage page, HttpContext ctx) {
|
||||||
final String siteID = page.findScript(CAPTCHA_ID_PATTERN, 1);
|
final String siteID = page.findScript(CAPTCHA_ID_PATTERN, 1);
|
||||||
try {
|
try {
|
||||||
return doExtract(ctx.get(CHALLENGE_BASE_URL + siteID).asString());
|
return doExtract(ctx.get(CHALLENGE_BASE_URI + siteID).asString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Actually performs the extracting job.
|
||||||
|
*
|
||||||
|
* @param content
|
||||||
|
* the page content
|
||||||
|
* @return the {@link ImageCaptcha}
|
||||||
|
*/
|
||||||
private static ImageCaptcha doExtract(String content) {
|
private static ImageCaptcha doExtract(String content) {
|
||||||
final String id = PatternUtils.find(CAPTCHA_IMAGE_PATTERN, content, 1);
|
final String id = PatternUtils.find(CAPTCHA_IMAGE_PATTERN, content, 1);
|
||||||
try {
|
return new ImageCaptcha(id, URI.create(IMAGE_BASE_URI + id));
|
||||||
return new ImageCaptcha(id, new URL(IMAGE_BASE_URL + id));
|
|
||||||
} catch (MalformedURLException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,13 +11,13 @@ import org.apache.http.client.methods.HttpGet;
|
|||||||
public class GetRequest extends Request {
|
public class GetRequest extends Request {
|
||||||
private long position = 0;
|
private long position = 0;
|
||||||
|
|
||||||
public GetRequest(HttpContext ctx, String url) {
|
public GetRequest(HttpContext ctx, String uri) {
|
||||||
super(ctx, url);
|
super(ctx, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpResponse request() throws IOException {
|
public HttpResponse request() throws IOException {
|
||||||
final HttpGet get = new HttpGet(url);
|
final HttpGet get = new HttpGet(uri);
|
||||||
if (position > 0)
|
if (position > 0)
|
||||||
get.addHeader("Range", "bytes=" + position + "-");
|
get.addHeader("Range", "bytes=" + position + "-");
|
||||||
return ctx.client.execute(get);
|
return ctx.client.execute(get);
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.rogiel.httpchannel.http;
|
package com.rogiel.httpchannel.http;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
@@ -22,19 +22,19 @@ public class HttpContext {
|
|||||||
*/
|
*/
|
||||||
protected DefaultHttpClient client = new DefaultHttpClient();
|
protected DefaultHttpClient client = new DefaultHttpClient();
|
||||||
|
|
||||||
public GetRequest get(String url) {
|
public GetRequest get(String uri) {
|
||||||
return new GetRequest(this, url);
|
return new GetRequest(this, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetRequest get(URL url) {
|
public GetRequest get(URI uri) {
|
||||||
return get(url.toString());
|
return get(uri.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostRequest post(String url) {
|
public PostRequest post(String uri) {
|
||||||
return new PostRequest(this, url);
|
return new PostRequest(this, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostMultipartRequest multipartPost(String url) {
|
public PostMultipartRequest multipartPost(String uri) {
|
||||||
return new PostMultipartRequest(this, url);
|
return new PostMultipartRequest(this, uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,14 +18,14 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannelContentBody;
|
|||||||
public class PostMultipartRequest extends PostRequest {
|
public class PostMultipartRequest extends PostRequest {
|
||||||
private final MultipartEntity entity;
|
private final MultipartEntity entity;
|
||||||
|
|
||||||
public PostMultipartRequest(HttpContext ctx, String url) {
|
public PostMultipartRequest(HttpContext ctx, String uri) {
|
||||||
super(ctx, url);
|
super(ctx, uri);
|
||||||
this.entity = new MultipartEntity();
|
this.entity = new MultipartEntity();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpResponse request() throws IOException {
|
public HttpResponse request() throws IOException {
|
||||||
final HttpPost post = new HttpPost(url);
|
final HttpPost post = new HttpPost(uri);
|
||||||
post.setEntity(entity);
|
post.setEntity(entity);
|
||||||
return ctx.client.execute(post);
|
return ctx.client.execute(post);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,13 @@ import org.apache.http.message.BasicNameValuePair;
|
|||||||
public class PostRequest extends Request {
|
public class PostRequest extends Request {
|
||||||
protected final List<NameValuePair> params = new ArrayList<NameValuePair>();
|
protected final List<NameValuePair> params = new ArrayList<NameValuePair>();
|
||||||
|
|
||||||
public PostRequest(HttpContext ctx, String url) {
|
public PostRequest(HttpContext ctx, String uri) {
|
||||||
super(ctx, url);
|
super(ctx, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HttpResponse request() throws IOException {
|
public HttpResponse request() throws IOException {
|
||||||
final HttpPost post = new HttpPost(url);
|
final HttpPost post = new HttpPost(uri);
|
||||||
post.setEntity(new UrlEncodedFormEntity(params));
|
post.setEntity(new UrlEncodedFormEntity(params));
|
||||||
return ctx.client.execute(post);
|
return ctx.client.execute(post);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,11 +15,11 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
|||||||
|
|
||||||
public abstract class Request {
|
public abstract class Request {
|
||||||
protected final HttpContext ctx;
|
protected final HttpContext ctx;
|
||||||
protected final String url;
|
protected final String uri;
|
||||||
|
|
||||||
public Request(HttpContext ctx, String url) {
|
public Request(HttpContext ctx, String uri) {
|
||||||
this.ctx = ctx;
|
this.ctx = ctx;
|
||||||
this.url = url;
|
this.uri = uri;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract HttpResponse request() throws IOException;
|
public abstract HttpResponse request() throws IOException;
|
||||||
@@ -59,7 +59,7 @@ public abstract class Request {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getURL() {
|
public String getURI() {
|
||||||
return url;
|
return uri;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2,7 +2,7 @@ package com.rogiel.httpchannel.service;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
|
||||||
import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
|
import com.rogiel.httpchannel.service.Downloader.DownloaderConfiguration;
|
||||||
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
|
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
|
||||||
@@ -23,9 +23,9 @@ import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
|
|||||||
public abstract class AbstractDownloader<C extends DownloaderConfiguration>
|
public abstract class AbstractDownloader<C extends DownloaderConfiguration>
|
||||||
implements Downloader<C> {
|
implements Downloader<C> {
|
||||||
/**
|
/**
|
||||||
* The download URL
|
* The download URI
|
||||||
*/
|
*/
|
||||||
protected final URL url;
|
protected final URI uri;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The {@link Downloader} configuration
|
* The {@link Downloader} configuration
|
||||||
@@ -35,13 +35,13 @@ public abstract class AbstractDownloader<C extends DownloaderConfiguration>
|
|||||||
/**
|
/**
|
||||||
* Creates a new instance
|
* Creates a new instance
|
||||||
*
|
*
|
||||||
* @param url
|
* @param uri
|
||||||
* the download url
|
* the download uri
|
||||||
* @param configuration
|
* @param configuration
|
||||||
* the configuration object
|
* the configuration object
|
||||||
*/
|
*/
|
||||||
protected AbstractDownloader(URL url, C configuration) {
|
protected AbstractDownloader(URI uri, C configuration) {
|
||||||
this.url = url;
|
this.uri = uri;
|
||||||
this.configuration = configuration;
|
this.configuration = configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package com.rogiel.httpchannel.service;
|
package com.rogiel.httpchannel.service;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.http.Header;
|
import org.apache.http.Header;
|
||||||
@@ -39,8 +39,8 @@ public abstract class AbstractHttpDownloader<C extends DownloaderConfiguration>
|
|||||||
extends AbstractDownloader<C> implements Downloader<C> {
|
extends AbstractDownloader<C> implements Downloader<C> {
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
protected AbstractHttpDownloader(URL url, C configuration) {
|
protected AbstractHttpDownloader(URI uri, C configuration) {
|
||||||
super(url, configuration);
|
super(uri, configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected long getContentLength(HttpResponse response) {
|
protected long getContentLength(HttpResponse response) {
|
||||||
@@ -70,7 +70,7 @@ public abstract class AbstractHttpDownloader<C extends DownloaderConfiguration>
|
|||||||
.getStatusLine().getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT))
|
.getStatusLine().getStatusCode() == HttpStatus.SC_PARTIAL_CONTENT))
|
||||||
throw new DownloadLinkNotFoundException();
|
throw new DownloadLinkNotFoundException();
|
||||||
|
|
||||||
final String filename = FilenameUtils.getName(request.getURL());
|
final String filename = FilenameUtils.getName(request.getURI());
|
||||||
final long contentLength = getContentLength(response);
|
final long contentLength = getContentLength(response);
|
||||||
return createInputStreamChannel(response.getEntity().getContent(),
|
return createInputStreamChannel(response.getEntity().getContent(),
|
||||||
contentLength, filename);
|
contentLength, filename);
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
package com.rogiel.httpchannel.service;
|
package com.rogiel.httpchannel.service;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import com.rogiel.httpchannel.http.GetRequest;
|
import com.rogiel.httpchannel.http.GetRequest;
|
||||||
@@ -45,23 +45,23 @@ public abstract class AbstractHttpService extends AbstractService implements
|
|||||||
return channel;
|
return channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetRequest get(String url) {
|
public GetRequest get(String uri) {
|
||||||
return http.get(url);
|
return http.get(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GetRequest get(URL url) {
|
public GetRequest get(URI uri) {
|
||||||
return http.get(url);
|
return http.get(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostRequest post(String url) {
|
public PostRequest post(String uri) {
|
||||||
return http.post(url);
|
return http.post(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostRequest post(URL url) {
|
public PostRequest post(URI uri) {
|
||||||
return post(url.toString());
|
return post(uri.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public PostMultipartRequest multipartPost(String url) {
|
public PostMultipartRequest multipartPost(String uri) {
|
||||||
return http.multipartPost(url);
|
return http.multipartPost(uri);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,8 +17,9 @@
|
|||||||
package com.rogiel.httpchannel.service.channel;
|
package com.rogiel.httpchannel.service.channel;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
|
import java.nio.channels.Channel;
|
||||||
import java.nio.channels.ClosedChannelException;
|
import java.nio.channels.ClosedChannelException;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
|
|
||||||
@@ -29,19 +30,43 @@ import com.rogiel.httpchannel.service.UploadChannel;
|
|||||||
import com.rogiel.httpchannel.service.exception.UploadLinkNotFoundException;
|
import com.rogiel.httpchannel.service.exception.UploadLinkNotFoundException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
* This channel is linked onto another {@link Channel} that actually writes data
|
||||||
|
* into the network stream.
|
||||||
*
|
*
|
||||||
|
* @author <a href="http://www.rogiel.com">Rogiel</a>
|
||||||
*/
|
*/
|
||||||
public class LinkedUploadChannel implements UploadChannel {
|
public class LinkedUploadChannel implements UploadChannel {
|
||||||
|
/**
|
||||||
|
* The logger instance
|
||||||
|
*/
|
||||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The destionation {@link Channel}. Data writted is forwarded to this
|
||||||
|
* channel.
|
||||||
|
*/
|
||||||
private WritableByteChannel channel;
|
private WritableByteChannel channel;
|
||||||
|
/**
|
||||||
|
* The close callback, that notifies once the channel has been closed
|
||||||
|
*/
|
||||||
private final LinkedUploadChannelCloseCallback closeCallback;
|
private final LinkedUploadChannelCloseCallback closeCallback;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The length of the data being uploaded
|
||||||
|
*/
|
||||||
private final long length;
|
private final long length;
|
||||||
|
/**
|
||||||
|
* The file name
|
||||||
|
*/
|
||||||
private final String filename;
|
private final String filename;
|
||||||
private URL downloadLink;
|
/**
|
||||||
|
* Only set when {@link #close()} is called and the download has finished.
|
||||||
|
*/
|
||||||
|
private URI downloadLink;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether the channel is still open or not
|
||||||
|
*/
|
||||||
private boolean open = true;
|
private boolean open = true;
|
||||||
|
|
||||||
public LinkedUploadChannel(LinkedUploadChannelCloseCallback closeCallback,
|
public LinkedUploadChannel(LinkedUploadChannelCloseCallback closeCallback,
|
||||||
@@ -55,11 +80,11 @@ public class LinkedUploadChannel implements UploadChannel {
|
|||||||
public int write(ByteBuffer src) throws IOException {
|
public int write(ByteBuffer src) throws IOException {
|
||||||
if (channel == null)
|
if (channel == null)
|
||||||
throw new IOException("Channel is not linked yet");
|
throw new IOException("Channel is not linked yet");
|
||||||
if(!open)
|
if (!open)
|
||||||
throw new ClosedChannelException();
|
throw new ClosedChannelException();
|
||||||
try {
|
try {
|
||||||
return channel.write(src);
|
return channel.write(src);
|
||||||
} catch(IOException e) {
|
} catch (IOException e) {
|
||||||
close();
|
close();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@@ -77,7 +102,7 @@ public class LinkedUploadChannel implements UploadChannel {
|
|||||||
logger.debug("Download link returned by service is {}", downloadLink);
|
logger.debug("Download link returned by service is {}", downloadLink);
|
||||||
if (downloadLink == null)
|
if (downloadLink == null)
|
||||||
throw new UploadLinkNotFoundException();
|
throw new UploadLinkNotFoundException();
|
||||||
this.downloadLink = new URL(downloadLink);
|
this.downloadLink = URI.create(downloadLink);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface LinkedUploadChannelCloseCallback {
|
public interface LinkedUploadChannelCloseCallback {
|
||||||
@@ -95,16 +120,33 @@ public class LinkedUploadChannel implements UploadChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public URL getDownloadLink() {
|
public URI getDownloadLink() {
|
||||||
return downloadLink;
|
return downloadLink;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Links this {@link Channel} to the destionation {@link Channel}. All data
|
||||||
|
* written in this channel will be redirected to the destination
|
||||||
|
* {@link Channel}.
|
||||||
|
*
|
||||||
|
* @param channel
|
||||||
|
* the target channel
|
||||||
|
* @throws IOException
|
||||||
|
* if the channel is already linked or the destination channel
|
||||||
|
* is closed
|
||||||
|
*/
|
||||||
protected void linkChannel(WritableByteChannel channel) throws IOException {
|
protected void linkChannel(WritableByteChannel channel) throws IOException {
|
||||||
if (this.channel != null)
|
if (this.channel != null)
|
||||||
throw new IOException("This channel is already linked.");
|
throw new IOException("This channel is already linked");
|
||||||
|
if (!channel.isOpen())
|
||||||
|
throw new IOException("The destination channel is closed");
|
||||||
this.channel = channel;
|
this.channel = channel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return <code>true</code> if the channel is linked with the destination
|
||||||
|
* {@link Channel}
|
||||||
|
*/
|
||||||
public boolean isLinked() {
|
public boolean isLinked() {
|
||||||
return channel != null;
|
return channel != null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ package com.rogiel.httpchannel.util;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
@@ -65,7 +65,7 @@ public class ChannelUtils {
|
|||||||
return out.toByteArray();
|
return out.toByteArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static URL upload(UploadService<?> service, Path path)
|
public static URI upload(UploadService<?> service, Path path)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
final UploadChannel uploadChannel = UploadServices
|
final UploadChannel uploadChannel = UploadServices
|
||||||
.upload(service, path).openChannel();
|
.upload(service, path).openChannel();
|
||||||
|
|||||||
@@ -35,14 +35,14 @@ public class HttpClientUtils {
|
|||||||
private static final ExecutorService threadPool = Executors
|
private static final ExecutorService threadPool = Executors
|
||||||
.newCachedThreadPool();
|
.newCachedThreadPool();
|
||||||
|
|
||||||
public static HttpResponse get(HttpClient client, String url)
|
public static HttpResponse get(HttpClient client, String uri)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return client.execute(new HttpGet(url));
|
return client.execute(new HttpGet(uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getString(HttpClient client, String url)
|
public static String getString(HttpClient client, String uri)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
return toString(get(client, url));
|
return toString(get(client, uri));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String execute(HttpClient client, HttpUriRequest request)
|
public static String execute(HttpClient client, HttpUriRequest request)
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ public class HTMLPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to find a link that has an URL following the given pattern
|
* Tries to find a link that has an URI following the given pattern
|
||||||
*
|
*
|
||||||
* @param pattern
|
* @param pattern
|
||||||
* the pattern
|
* the pattern
|
||||||
@@ -119,11 +119,11 @@ public class HTMLPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to find a frame that has an URL following the given pattern
|
* Tries to find a frame that has an URI following the given pattern
|
||||||
*
|
*
|
||||||
* @param pattern
|
* @param pattern
|
||||||
* the pattern
|
* the pattern
|
||||||
* @return the iframe url, if found. <code>null</code> otherwise
|
* @return the iframe uri, if found. <code>null</code> otherwise
|
||||||
*/
|
*/
|
||||||
public String findFrame(final Pattern pattern) {
|
public String findFrame(final Pattern pattern) {
|
||||||
for (final TagNode tag : filter(TagNode.class, new FramePatternFilter(
|
for (final TagNode tag : filter(TagNode.class, new FramePatternFilter(
|
||||||
@@ -134,11 +134,11 @@ public class HTMLPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tries to find a image that has an URL following the given pattern
|
* Tries to find a image that has an URI following the given pattern
|
||||||
*
|
*
|
||||||
* @param pattern
|
* @param pattern
|
||||||
* the pattern
|
* the pattern
|
||||||
* @return the iframe url, if found. <code>null</code> otherwise
|
* @return the iframe uri, if found. <code>null</code> otherwise
|
||||||
*/
|
*/
|
||||||
public String findImage(final Pattern pattern) {
|
public String findImage(final Pattern pattern) {
|
||||||
for (final ImageTag tag : filter(ImageTag.class,
|
for (final ImageTag tag : filter(ImageTag.class,
|
||||||
@@ -154,7 +154,7 @@ public class HTMLPage {
|
|||||||
*
|
*
|
||||||
* @param pattern
|
* @param pattern
|
||||||
* the pattern
|
* the pattern
|
||||||
* @return the URL found, if any. <code>null</code> otherwise
|
* @return the URI found, if any. <code>null</code> otherwise
|
||||||
*/
|
*/
|
||||||
public String findFormAction(final Pattern pattern) {
|
public String findFormAction(final Pattern pattern) {
|
||||||
for (final FormTag tag : filter(FormTag.class,
|
for (final FormTag tag : filter(FormTag.class,
|
||||||
|
|||||||
136
pom.xml
136
pom.xml
@@ -4,18 +4,70 @@
|
|||||||
|
|
||||||
<groupId>com.rogiel.httpchannel</groupId>
|
<groupId>com.rogiel.httpchannel</groupId>
|
||||||
<artifactId>httpchannel</artifactId>
|
<artifactId>httpchannel</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>1.0.0-SNAPSHOT</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>HttpChannel</name>
|
<name>HttpChannel</name>
|
||||||
<description>Library capable of downloading and uploading files from free servers using channels.</description>
|
<description>Library capable of downloading and uploading files from free servers using channels.</description>
|
||||||
|
<url>http://httpchannel.rogiel.com/</url>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<developerConnection>scm:git:${basedir}</developerConnection>
|
||||||
|
<connection>scm:git:${basedir}</connection>
|
||||||
|
</scm>
|
||||||
|
<distributionManagement>
|
||||||
|
<downloadUrl>http://httpchannel.rogiel.com/maven2/com/rogiel/httpchannel</downloadUrl>
|
||||||
|
<repository>
|
||||||
|
<uniqueVersion>false</uniqueVersion>
|
||||||
|
<id>httpchannel-repository</id>
|
||||||
|
<name>HttpChannel Maven Repository</name>
|
||||||
|
<url>scp://rogiels@rogiel.com/home/rogiels/httpchannel.rogiel.com/maven2</url>
|
||||||
|
<layout>default</layout>
|
||||||
|
</repository>
|
||||||
|
<site>
|
||||||
|
<id>httpchannel-site</id>
|
||||||
|
<name>httpchannel-site</name>
|
||||||
|
<url>scp://rogiels@rogiel.com/home/rogiels/httpchannel.rogiel.com</url>
|
||||||
|
</site>
|
||||||
|
</distributionManagement>
|
||||||
|
<issueManagement>
|
||||||
|
<system>GitHub</system>
|
||||||
|
<url>https://github.com/seedbox/httpchannel/issues</url>
|
||||||
|
</issueManagement>
|
||||||
|
|
||||||
|
<ciManagement>
|
||||||
|
<system>GitHub</system>
|
||||||
|
<url>https://github.com/seedbox/httpchannel</url>
|
||||||
|
</ciManagement>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>Rogiel</id>
|
||||||
|
<name>Rogiel</name>
|
||||||
|
<email>rogiel@rogiel.com</email>
|
||||||
|
<url>http://www.rogiel.com/</url>
|
||||||
|
<timezone>-3</timezone>
|
||||||
|
<roles>
|
||||||
|
<role>Creator</role>
|
||||||
|
<role>API Designer</role>
|
||||||
|
</roles>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>GNU General Public License version 3</name>
|
||||||
|
<url>http://www.gnu.org/licenses/gpl.txt</url>
|
||||||
|
<distribution>repo</distribution>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
<modules>
|
<modules>
|
||||||
<module>httpchannel-api</module>
|
<module>httpchannel-api</module>
|
||||||
<module>httpchannel-service</module>
|
<module>httpchannel-service</module>
|
||||||
<module>httpchannel-util</module>
|
|
||||||
<module>httpchannel-channelcopy</module>
|
|
||||||
<module>httpchannel-captcha</module>
|
<module>httpchannel-captcha</module>
|
||||||
|
<module>httpchannel-channelcopy</module>
|
||||||
|
<module>httpchannel-util</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -38,20 +90,70 @@
|
|||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-site-plugin</artifactId>
|
||||||
|
<version>3.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<descriptors>
|
<outputEncoding>UTF-8</outputEncoding>
|
||||||
<descriptor>src/main/assembly/distribution-bin.xml</descriptor>
|
<reportPlugins>
|
||||||
</descriptors>
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>2.8</version>
|
||||||
|
<configuration>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-project-info-reports-plugin</artifactId>
|
||||||
|
<version>2.4</version>
|
||||||
|
<configuration>
|
||||||
|
<developerConnection>scm:git@github.com:seedbox/httpchannel.git</developerConnection>
|
||||||
|
<anonymousConnection>scm:git://github.com/seedbox/httpchannel.git</anonymousConnection>
|
||||||
|
<webAccessUrl>https://github.com/seedbox/httpchannel</webAccessUrl>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-changelog-plugin</artifactId>
|
||||||
|
<version>2.2</version>
|
||||||
|
<configuration>
|
||||||
|
<outputEncoding>UTF-8</outputEncoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-jxr-plugin</artifactId>
|
||||||
|
<version>2.3</version>
|
||||||
|
<configuration>
|
||||||
|
<inputEncoding>UTF-8</inputEncoding>
|
||||||
|
<outputEncoding>UTF-8</outputEncoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</reportPlugins>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<dependencies>
|
||||||
<execution>
|
<dependency>
|
||||||
<phase>package</phase>
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
<goals>
|
<artifactId>wagon-ssh</artifactId>
|
||||||
<goal>assembly</goal>
|
<version>2.1</version>
|
||||||
</goals>
|
</dependency>
|
||||||
</execution>
|
</dependencies>
|
||||||
</executions>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-deploy-plugin</artifactId>
|
||||||
|
<version>2.7</version>
|
||||||
|
<configuration>
|
||||||
|
<uniqueVersion>false</uniqueVersion>
|
||||||
|
</configuration>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
|
<artifactId>wagon-ssh</artifactId>
|
||||||
|
<version>2.1</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
@@ -74,9 +176,7 @@
|
|||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-jdk14</artifactId>
|
<artifactId>slf4j-jdk14</artifactId>
|
||||||
<version>1.6.4</version>
|
<version>1.6.4</version>
|
||||||
<scope>runtime</scope>
|
<scope>test</scope>
|
||||||
<optional>true</optional>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
<url>http://httpchannel.rogiel.com/</url>
|
|
||||||
</project>
|
</project>
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<assembly
|
|
||||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
||||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
|
||||||
<id>bin</id>
|
|
||||||
<formats>
|
|
||||||
<format>zip</format>
|
|
||||||
</formats>
|
|
||||||
<baseDirectory></baseDirectory>
|
|
||||||
<moduleSets>
|
|
||||||
<moduleSet>
|
|
||||||
<includeSubModules>true</includeSubModules>
|
|
||||||
<binaries>
|
|
||||||
<unpack>true</unpack>
|
|
||||||
<useStrictFiltering>true</useStrictFiltering>
|
|
||||||
<unpackOptions>
|
|
||||||
<includes>
|
|
||||||
<include>com/rogiel/httpchannel/**</include>
|
|
||||||
</includes>
|
|
||||||
</unpackOptions>
|
|
||||||
<includeDependencies>false</includeDependencies>
|
|
||||||
<includes>
|
|
||||||
<include>httpchannel-api</include>
|
|
||||||
<include>httpchannel-service</include>
|
|
||||||
</includes>
|
|
||||||
</binaries>
|
|
||||||
</moduleSet>
|
|
||||||
</moduleSets>
|
|
||||||
</assembly>
|
|
||||||
Reference in New Issue
Block a user