1
0
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:
2012-01-17 17:07:48 -02:00
parent 08d22a12fe
commit 673bfc6639
56 changed files with 536 additions and 399 deletions

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-depositfiles</artifactId>

View File

@@ -43,16 +43,16 @@ public class DepositFilesService extends AbstractHttpService implements
*/
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=(.*)");
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]*)");
private static final Pattern VALID_LOGIN_REDIRECT = Pattern
.compile("window.location.href");
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -139,14 +139,14 @@ public class DepositFilesService extends AbstractHttpService implements
logger.debug("Starting upload to depositfiles.com");
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 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);
uploadFuture = multipartPost(url).parameter("files", channel)
uploadFuture = multipartPost(uri).parameter("files", channel)
.parameter("go", true)
.parameter("UPLOAD_IDENTIFIER", uploadID)
.parameter("agree", true)
@@ -158,7 +158,7 @@ public class DepositFilesService extends AbstractHttpService implements
public String finish() throws IOException {
try {
final String link = uploadFuture.get().findScript(
DOWNLOAD_URL_PATTERN, 0);
DOWNLOAD_URI_PATTERN, 0);
if (link == null)
return null;
return link;

View File

@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -31,9 +31,9 @@ public class DepositFilesServiceTest {
UploaderCapability.UNAUTHENTICATED_UPLOAD));
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);
System.out.println(url);
Assert.assertNotNull(uri);
System.out.println(uri);
}
}

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-filesonic</artifactId>

View File

@@ -4,7 +4,7 @@
package com.rogiel.httpchannel.filesonic;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
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>
*/
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 password;
@@ -25,10 +25,10 @@ public class FileSonicAPI {
return id;
}
public URL getUploadURL() throws IOException {
return new URL(((FSGetUploadURL) execute(FSUpload.class,
public URI getUploadURI() throws IOException {
return URI.create((((FSGetUploadURL) execute(FSUpload.class,
"upload?method=getUploadUrl").getResponse()).getResponse()
.getUploadURL());
.getUploadURI()));
}
public long getMaxFilesize() throws IOException {
@@ -47,10 +47,10 @@ public class FileSonicAPI {
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 {
final URL url = new URL(BASE_URL + requestURL + "&u=" + email + "&p="
+ password + "&format=xml");
return JAXB.unmarshal(url.openStream(), type);
final URI uri = URI.create(BASE_URI + requestURI + "&u=" + email
+ "&p=" + password + "&format=xml");
return JAXB.unmarshal(uri.toURL().openStream(), type);
}
}

View File

@@ -20,13 +20,13 @@ public class FSGetUploadURL extends FSResponse {
@XmlAccessorType(XmlAccessType.NONE)
public static class FSGetUploadURLResponse {
@XmlElement(name = "url")
private String uploadURL;
@XmlElement(name = "uri")
private String uploadURI;
@XmlElement(name = "max-filesize")
private long maxFilesize;
public String getUploadURL() {
return uploadURL;
public String getUploadURI() {
return uploadURI;
}
public long getMaxFilesize() {

View File

@@ -57,9 +57,9 @@ public class FileSonicService extends AbstractHttpService implements Service,
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]*");
/**
* The FileSonic API
@@ -67,7 +67,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
private final FileSonicAPI api = new FileSonicAPI();
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -156,7 +156,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to filesonic.com");
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(api.getUploadURL().toString())
uploadFuture = multipartPost(api.getUploadURI().toString())
.parameter("files[]", channel).asStringAsync();
return waitChannelLink(channel, uploadFuture);
}
@@ -164,7 +164,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return PatternUtils.find(DOWNLOAD_URL_PATTERN,
return PatternUtils.find(DOWNLOAD_URI_PATTERN,
uploadFuture.get());
} catch (InterruptedException e) {
return null;

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-hotfile</artifactId>

View File

@@ -17,7 +17,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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");
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]*");
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
// .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]*)/(.*)");
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -135,14 +135,14 @@ public class HotFileService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -151,8 +151,8 @@ public class HotFileService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -198,9 +198,9 @@ public class HotFileService extends AbstractHttpService implements Service,
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to hotfile.com");
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);
@@ -212,7 +212,7 @@ public class HotFileService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return uploadFuture.get().getInputValue(DOWNLOAD_URL_PATTERN);
return uploadFuture.get().getInputValue(DOWNLOAD_URI_PATTERN);
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
@@ -223,15 +223,15 @@ public class HotFileService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> {
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
super(url, configuration);
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
logger.debug("Downloading {} from hotfile.com", url);
final HTMLPage page = get(url).asPage();
logger.debug("Downloading {} from hotfile.com", uri);
final HTMLPage page = get(uri).asPage();
// // try to find timer
// final String stringTimer = PatternUtils.find(DOWNLOAD_TIMER,

View File

@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
@@ -80,7 +80,7 @@ public class HotFileServiceTest {
@Test
public void testServiceId() {
assertEquals(ServiceID.create("hotfile"), service.getID());
assertEquals(ServiceID.create("hotfile"), service.getServiceID());
}
@Test
@@ -146,10 +146,10 @@ public class HotFileServiceTest {
@Test
public void testDownloader() throws IOException {
final URL downloadUrl = new URL(
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.htm");
final URI downloadUrl = URI
.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)
.openChannel(null, 0);
@@ -165,8 +165,7 @@ public class HotFileServiceTest {
final DownloadChannel channel = service
.getDownloader(
new URL(
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
URI.create("http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
.openChannel(null, 0);
final ByteArrayOutputStream bout = new ByteArrayOutputStream();

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-megaupload</artifactId>

View File

@@ -17,7 +17,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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");
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]*");
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
// .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]*)");
private static final Pattern LOGIN_USERNAME_PATTERN = Pattern
.compile("flashvars\\.username = \"(.*)\";");
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -139,14 +139,14 @@ public class MegaUploadService extends AbstractHttpService implements Service,
}
@Override
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URL url,
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URI uri,
MegaUploadDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<MegaUploadDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -155,8 +155,8 @@ public class MegaUploadService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -208,11 +208,11 @@ public class MegaUploadService extends AbstractHttpService implements Service,
logger.debug("Starting upload to megaupload.com");
final HTMLPage page = get("http://www.megaupload.com/multiupload/")
.asPage();
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
logger.debug("Upload URL is {}", url);
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URI is {}", uri);
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url)
uploadFuture = multipartPost(uri)
.parameter("multimessage_0", configuration.description())
.parameter("multifile_0", channel).asStringAsync();
return waitChannelLink(channel, uploadFuture);
@@ -221,7 +221,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return PatternUtils.find(DOWNLOAD_URL_PATTERN,
return PatternUtils.find(DOWNLOAD_URI_PATTERN,
uploadFuture.get());
} catch (InterruptedException e) {
return null;
@@ -234,16 +234,16 @@ public class MegaUploadService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<MegaUploadDownloaderConfiguration> implements
Downloader<MegaUploadDownloaderConfiguration> {
public DownloaderImpl(URL url,
public DownloaderImpl(URI uri,
MegaUploadDownloaderConfiguration configuration) {
super(url, configuration);
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
logger.debug("Starting {} download from megaupload.com", url);
HttpResponse response = get(url).request();
logger.debug("Starting {} download from megaupload.com", uri);
HttpResponse response = get(uri).request();
// disable direct downloads, we don't support them!
if (response.getEntity().getContentType().getValue()
@@ -259,7 +259,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
.parameter("set_ddl", "0").request();
// execute and re-request download
response = get(url).request();
response = get(uri).request();
}
final HTMLPage page = HttpClientUtils.toPage(response);

View File

@@ -22,7 +22,7 @@ import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.channels.Channels;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.Files;
@@ -79,7 +79,7 @@ public class MegaUploadServiceTest {
@Test
public void testServiceId() {
assertEquals(ServiceID.create("megaupload"), service.getID());
assertEquals(ServiceID.create("megaupload"), service.getServiceID());
}
@Test
@@ -145,7 +145,7 @@ public class MegaUploadServiceTest {
@Test
public void testFreeDownloader() throws IOException {
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() {
@Override
public boolean timer(long time) {
@@ -166,7 +166,7 @@ public class MegaUploadServiceTest {
.login();
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() {
@Override
public boolean timer(long time) {
@@ -190,7 +190,7 @@ public class MegaUploadServiceTest {
@SuppressWarnings({ "unused" })
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() {
@Override
public boolean timer(long time) {

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-multiupload</artifactId>

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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");
// 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]*");
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
.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]*)/(.*)");
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -119,14 +119,14 @@ public class MultiUploadService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -135,8 +135,8 @@ public class MultiUploadService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_LINK_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_LINK_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -184,12 +184,12 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to multiupload.com");
final String url = get("http://www.multiupload.com/").asPage()
.findFormAction(UPLOAD_URL_PATTERN);
logger.debug("Upload URL is {}", url);
final String uri = get("http://www.multiupload.com/").asPage()
.findFormAction(UPLOAD_URI_PATTERN);
logger.debug("Upload URI is {}", uri);
final LinkedUploadChannel channel = createLinkedChannel(this);
PostMultipartRequest request = multipartPost(url).parameter(
PostMultipartRequest request = multipartPost(uri).parameter(
"description_0", configuration.description()).parameter(
"file_0", channel);
for (final MultiUploadMirrorService mirror : configuration
@@ -223,9 +223,9 @@ public class MultiUploadService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> {
protected DownloaderImpl(URL url,
protected DownloaderImpl(URI uri,
NullDownloaderConfiguration configuration) {
super(url, configuration);
super(uri, configuration);
}
@Override
@@ -233,7 +233,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
long position) throws IOException,
DownloadLinkNotFoundException, DownloadLimitExceededException,
DownloadNotAuthorizedException, DownloadNotResumableException {
final HTMLPage page = get(url).asPage();
final HTMLPage page = get(uri).asPage();
final String link = page.findLink(DIRECT_DOWNLOAD_LINK_PATTERN);
logger.debug("Direct download link is {}", link);
if (link == null)

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.MessageDigest;
@@ -33,16 +33,16 @@ public class MultiUploadServiceTest {
@Test
public void testUploader() throws IOException {
final URL url = ChannelUtils.upload(service, TEST_UPLOAD_FILE);
Assert.assertNotNull(url);
System.out.println("Uploaded file to " + url);
final URI uri = ChannelUtils.upload(service, TEST_UPLOAD_FILE);
Assert.assertNotNull(uri);
System.out.println("Uploaded file to " + uri);
}
@Test
public void testDownloader() throws IOException, NoSuchAlgorithmException {
final byte[] data = ChannelUtils
.toByteArray(((DownloadService<?>) service).getDownloader(
new URL("http://www.multiupload.com/TJOYWB4JEW"))
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
.openChannel());
assertChecksum("Downloaded data checksum did not matched", "SHA1",
data, EXPECTED_FULL_CHECKSUM);
@@ -53,7 +53,7 @@ public class MultiUploadServiceTest {
NoSuchAlgorithmException {
final byte[] data = ChannelUtils
.toByteArray(((DownloadService<?>) service).getDownloader(
new URL("http://www.multiupload.com/TJOYWB4JEW"))
URI.create("http://www.multiupload.com/TJOYWB4JEW"))
.openChannel(50));
assertChecksum("Downloaded data checksum did not matched", "SHA1",
data, EXPECTED_RESUME_CHECKSUM);

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-uploadhere</artifactId>

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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");
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]*");
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
.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]*");
private static final Pattern TIMER_PATTERN = Pattern.compile(
"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]*)\\\\/(.*))\"");
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -118,14 +118,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -134,8 +134,8 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -185,14 +185,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
final HTMLPage page = get("http://www.uploadhere.com/").asPage();
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");
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
new Object[] { url, userCookie, uploadID });
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
new Object[] { uri, userCookie, uploadID });
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url).parameter("file_0", channel)
uploadFuture = multipartPost(uri).parameter("file_0", channel)
.parameter("u", userCookie)
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
return waitChannelLink(channel, uploadFuture);
@@ -222,14 +222,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> {
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
super(url, configuration);
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
HTMLPage page = get(url).asPage();
HTMLPage page = get(uri).asPage();
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
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");
}
String content = post(url)
String content = post(uri)
.parameter("recaptcha_challenge_field", captcha.getID())
.parameter("recaptcha_response_field",
captcha.getAnswer()).asString();
String downloadLink = PatternUtils.find(
DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
if (downloadLink == null) {
captchaService.invalid(captcha);
throw new InvalidCaptchaException();
@@ -265,7 +265,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
}
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));
}
throw new DownloadLinkNotFoundException();

View File

@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -31,10 +31,10 @@ public class UploadHereServiceTest {
UploaderCapability.UNAUTHENTICATED_UPLOAD));
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);
System.out.println(url);
Assert.assertNotNull(uri);
System.out.println(uri);
}
// @Test
@@ -43,7 +43,7 @@ public class UploadHereServiceTest {
// @Override
// public boolean resolve(Captcha rawCaptcha) {
// final ImageCaptcha captcha = (ImageCaptcha) rawCaptcha;
// System.out.println(captcha.getImageURL());
// System.out.println(captcha.getImageURI());
// try {
// captcha.setAnswer(new BufferedReader(new InputStreamReader(
// System.in)).readLine());
@@ -56,7 +56,7 @@ public class UploadHereServiceTest {
// });
//
// 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)));
// }
}

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-uploadking</artifactId>
@@ -15,7 +15,7 @@
<dependency>
<groupId>com.rogiel.httpchannel.captcha</groupId>
<artifactId>httpchannel-captcha-captchatrader</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
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");
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]*");
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
.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]*");
private static final Pattern TIMER_PATTERN = Pattern.compile(
"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]*)\\\\/(.*))\"");
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -118,14 +118,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -134,8 +134,8 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -185,14 +185,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
final HTMLPage page = get("http://www.uploadking.com/").asPage();
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");
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
new Object[] { url, userCookie, uploadID });
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
new Object[] { uri, userCookie, uploadID });
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url).parameter("file", channel)
uploadFuture = multipartPost(uri).parameter("file", channel)
.parameter("u", userCookie)
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
return waitChannelLink(channel, uploadFuture);
@@ -219,15 +219,15 @@ public class UploadKingService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> {
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
super(url, configuration);
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
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;
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");
}
String content = post(url)
String content = post(uri)
.parameter("recaptcha_challenge_field", captcha.getID())
.parameter("recaptcha_response_field",
captcha.getAnswer()).asString();
String downloadLink = PatternUtils.find(
DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
if (downloadLink == null) {
captchaService.invalid(captcha);
throw new InvalidCaptchaException();
@@ -264,7 +264,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
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));
}
throw new DownloadLinkNotFoundException();

View File

@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -37,10 +37,10 @@ public class UploadKingServiceTest {
UploaderCapability.UNAUTHENTICATED_UPLOAD));
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);
System.out.println(url);
Assert.assertNotNull(uri);
System.out.println(uri);
}
@Test
@@ -55,7 +55,8 @@ public class UploadKingServiceTest {
service.setCaptchaService(s);
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)));
}
}

View File

@@ -3,7 +3,7 @@
<parent>
<artifactId>httpchannel-service</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service-zshare</artifactId>

View File

@@ -30,22 +30,22 @@ public class ZShareService extends AbstractHttpService implements Service/*
*/
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]*)?/",
// Pattern.CASE_INSENSITIVE);
// private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
// .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]*");
// private static final Pattern TIMER_PATTERN = Pattern.compile(
// "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]*)\\\\/(.*))\"");
//
// private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -95,14 +95,14 @@ public class ZShareService extends AbstractHttpService implements Service/*
// }
// @Override
// public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
// public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
// NullDownloaderConfiguration configuration) {
// return new DownloaderImpl(url, configuration);
// return new DownloaderImpl(uri, configuration);
// }
//
// @Override
// public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
// return getDownloader(url, newDownloaderConfiguration());
// public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
// return getDownloader(uri, newDownloaderConfiguration());
// }
//
// @Override
@@ -111,8 +111,8 @@ public class ZShareService extends AbstractHttpService implements Service/*
// }
//
// @Override
// public boolean matchURL(URL url) {
// return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
// public boolean matchURI(URI uri) {
// return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
// }
//
// @Override
@@ -162,12 +162,12 @@ public class ZShareService extends AbstractHttpService implements Service/*
// public UploadChannel openChannel() throws IOException {
// final HTMLPage page = get("http://www.zshare.net/").asPage();
//
// final String url = page.findFormAction(UPLOAD_URL_PATTERN);
// System.out.println(url+"cgi-bin/ubr_upload.pl");
// final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
// System.out.println(uri+"cgi-bin/ubr_upload.pl");
//
// final LinkedUploadChannel channel = createLinkedChannel(this);
// 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("TOS", true).parameter("is_private", false)
// .asStringAsync();
@@ -196,15 +196,15 @@ public class ZShareService extends AbstractHttpService implements Service/*
// protected class DownloaderImpl extends
// AbstractHttpDownloader<NullDownloaderConfiguration> implements
// Downloader<NullDownloaderConfiguration> {
// public DownloaderImpl(URL url, NullDownloaderConfiguration configuration)
// public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration)
// {
// super(url, configuration);
// super(uri, configuration);
// }
//
// @Override
// public DownloadChannel openChannel(DownloadListener listener,
// long position) throws IOException {
// HTMLPage page = get(url).asPage();
// HTMLPage page = get(uri).asPage();
//
// final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
//
@@ -218,12 +218,12 @@ public class ZShareService extends AbstractHttpService implements Service/*
// // if (delta < waitTime)
// // timer(listener, waitTime - delta);
// //
// // String content = post(url)
// // String content = post(uri)
// // .parameter("recaptcha_challenge_field", captcha.getID())
// // .parameter("recaptcha_response_field",
// // captcha.getAnswer()).asString();
// // String downloadLink = PatternUtils.find(
// // DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
// // DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
// // if (downloadLink == null)
// // throw new InvalidCaptchaException();
// // downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),

View File

@@ -4,7 +4,7 @@
<parent>
<artifactId>httpchannel</artifactId>
<groupId>com.rogiel.httpchannel</groupId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>
<artifactId>httpchannel-service</artifactId>
@@ -26,12 +26,12 @@
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-api</artifactId>
<version>${project.version}</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.rogiel.httpchannel</groupId>
<artifactId>httpchannel-util</artifactId>
<version>1.0.0</version>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>