mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-05 23:22:51 +00:00
Modularize in maven projects the httpchannel library
This commit creates several maven modules for each segment of the library. Now it is possible to include only individual services to the classpath instead of the full library.
This commit is contained in:
10
httpchannel-service/httpchannel-service-hotfile/pom.xml
Normal file
10
httpchannel-service/httpchannel-service-hotfile/pom.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>httpchannel-service</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-service-hotfile</artifactId>
|
||||
</project>
|
||||
@@ -0,0 +1,319 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.ClientProtocolException;
|
||||
import org.apache.http.entity.mime.MultipartEntity;
|
||||
import org.apache.http.entity.mime.content.StringBody;
|
||||
import org.htmlparser.Tag;
|
||||
|
||||
import com.rogiel.httpchannel.service.AbstractDownloader;
|
||||
import com.rogiel.httpchannel.service.AbstractHttpService;
|
||||
import com.rogiel.httpchannel.service.AuthenticationService;
|
||||
import com.rogiel.httpchannel.service.Authenticator;
|
||||
import com.rogiel.httpchannel.service.AuthenticatorCapability;
|
||||
import com.rogiel.httpchannel.service.CapabilityMatrix;
|
||||
import com.rogiel.httpchannel.service.Credential;
|
||||
import com.rogiel.httpchannel.service.DownloadChannel;
|
||||
import com.rogiel.httpchannel.service.DownloadListener;
|
||||
import com.rogiel.httpchannel.service.DownloadService;
|
||||
import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.DownloaderCapability;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
import com.rogiel.httpchannel.service.UploaderCapability;
|
||||
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannelContentBody;
|
||||
import com.rogiel.httpchannel.service.config.ServiceConfiguration;
|
||||
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
|
||||
import com.rogiel.httpchannel.service.impl.HotFileService.HotFileServiceConfiguration;
|
||||
import com.rogiel.httpchannel.util.ThreadUtils;
|
||||
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||
|
||||
/**
|
||||
* This service handles login, upload and download to HotFile.com.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public class HotFileService extends
|
||||
AbstractHttpService<HotFileServiceConfiguration> implements Service,
|
||||
UploadService, DownloadService, AuthenticationService {
|
||||
private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
||||
.compile("http://u[0-9]*\\.hotfile\\.com/upload\\.cgi\\?[0-9]*");
|
||||
|
||||
private static final Pattern DOWNLOAD_DIRECT_LINK_PATTERN = Pattern
|
||||
.compile("http://hotfile\\.com/get/([0-9]*)/([A-Za-z0-9]*)/([A-Za-z0-9]*)/(.*)");
|
||||
// private static final Pattern DOWNLOAD_TIMER = Pattern
|
||||
// .compile("timerend=d\\.getTime\\(\\)\\+([0-9]*);");
|
||||
// private static final Pattern DOWNLOAD_FILESIZE = Pattern
|
||||
// .compile("[0-9]*(\\.[0-9]*)? (K|M|G)B");
|
||||
|
||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
||||
.compile("http://hotfile\\.com/dl/([0-9]*)/([A-Za-z0-9]*)/(.*)");
|
||||
|
||||
public HotFileService(final HotFileServiceConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "hotfile";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader getUploader(String filename, long filesize,
|
||||
String description) {
|
||||
return new HotFileUploader(filename, filesize);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaximumFilesize() {
|
||||
return 1 * 1024 * 1024 * 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSupportedExtensions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<UploaderCapability> getUploadCapabilities() {
|
||||
return new CapabilityMatrix<UploaderCapability>(
|
||||
UploaderCapability.UNAUTHENTICATED_UPLOAD,
|
||||
UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD,
|
||||
UploaderCapability.PREMIUM_ACCOUNT_UPLOAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Downloader getDownloader(URL url) {
|
||||
return new HotFileDownloader(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchURL(URL url) {
|
||||
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<DownloaderCapability> getDownloadCapabilities() {
|
||||
return new CapabilityMatrix<DownloaderCapability>(
|
||||
DownloaderCapability.PREMIUM_ACCOUNT_DOWNLOAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authenticator getAuthenticator(Credential credential) {
|
||||
return new HotFileAuthenticator(credential);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
|
||||
return new CapabilityMatrix<AuthenticatorCapability>();
|
||||
}
|
||||
|
||||
protected class HotFileUploader implements Uploader,
|
||||
LinkedUploadChannelCloseCallback {
|
||||
private final String filename;
|
||||
private final long filesize;
|
||||
|
||||
private Future<HTMLPage> uploadFuture;
|
||||
|
||||
public HotFileUploader(String filename, long filesize) {
|
||||
super();
|
||||
this.filename = filename;
|
||||
this.filesize = filesize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadChannel upload() throws IOException {
|
||||
final HTMLPage page = getAsPage("http://www.hotfile.com/");
|
||||
final String action = page.getFormAction(UPLOAD_URL_PATTERN);
|
||||
|
||||
final LinkedUploadChannel channel = new LinkedUploadChannel(this,
|
||||
filesize, filename);
|
||||
final MultipartEntity entity = new MultipartEntity();
|
||||
|
||||
entity.addPart("uploads[]", new LinkedUploadChannelContentBody(channel));
|
||||
|
||||
uploadFuture = postAsPageAsync(action, entity);
|
||||
while (!channel.isLinked() && !uploadFuture.isDone()) {
|
||||
ThreadUtils.sleep(100);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String finish() throws IOException {
|
||||
try {
|
||||
return uploadFuture.get().getInputValue(DOWNLOAD_URL_PATTERN);
|
||||
} catch (InterruptedException e) {
|
||||
return null;
|
||||
} catch (ExecutionException e) {
|
||||
throw (IOException) e.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class HotFileDownloader extends AbstractDownloader {
|
||||
private final URL url;
|
||||
|
||||
public HotFileDownloader(URL url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DownloadChannel download(DownloadListener listener, long position)
|
||||
throws IOException {
|
||||
final HTMLPage page = getAsPage(url.toString());
|
||||
|
||||
// // try to find timer
|
||||
// final String stringTimer = PatternUtils.find(DOWNLOAD_TIMER,
|
||||
// content, 2, 1);
|
||||
// int timer = 0;
|
||||
// if (stringTimer != null && stringTimer.length() > 0) {
|
||||
// timer = Integer.parseInt(stringTimer);
|
||||
// }
|
||||
// if (timer > 0) {
|
||||
// throw new DownloadLimitExceededException("Must wait " + timer
|
||||
// + " milliseconds");
|
||||
// }
|
||||
|
||||
final String downloadUrl = page
|
||||
.getLink(DOWNLOAD_DIRECT_LINK_PATTERN);
|
||||
// final String tmHash = PatternUtils.find(DOWNLOAD_TMHASH_PATTERN,
|
||||
// content);F
|
||||
if (downloadUrl != null && downloadUrl.length() > 0) {
|
||||
final HttpResponse downloadResponse = get(downloadUrl);
|
||||
|
||||
final String filename = FilenameUtils.getName(downloadUrl);
|
||||
long contentLength = getContentLength(downloadResponse);
|
||||
|
||||
return new InputStreamDownloadChannel(downloadResponse
|
||||
.getEntity().getContent(), contentLength, filename);
|
||||
// } else if (tmHash != null) {
|
||||
// String dlUrl = PatternUtils.find(FREE_DOWNLOAD_URL_PATTERN,
|
||||
// content);
|
||||
//
|
||||
// String action = PatternUtils.find(DOWNLOAD_ACTION_PATTERN,
|
||||
// content, 1);
|
||||
// int tm = PatternUtils.findInt(DOWNLOAD_TM_PATTERN, content,
|
||||
// 1);
|
||||
// int wait = PatternUtils.findInt(DOWNLOAD_WAIT_PATTERN,
|
||||
// content,
|
||||
// 1);
|
||||
// String waitHash =
|
||||
// PatternUtils.find(DOWNLOAD_WAITHASH_PATTERN,
|
||||
// content, 1);
|
||||
// String upId = PatternUtils.find(DOWNLOAD_UPIDHASH_PATTERN,
|
||||
// content, 1);
|
||||
//
|
||||
// System.out.println("Wait time: "+wait);
|
||||
//
|
||||
// if (wait > 0)
|
||||
// timer(listener, wait * 1000);
|
||||
//
|
||||
// final HttpPost downloadPost = new
|
||||
// HttpPost("http://www.hotfile.com"+dlUrl);
|
||||
// final List<NameValuePair> pairs = new
|
||||
// ArrayList<NameValuePair>();
|
||||
// pairs.add(new BasicNameValuePair("action", action));
|
||||
// pairs.add(new BasicNameValuePair("tm",
|
||||
// Integer.toString(tm)));
|
||||
// pairs.add(new BasicNameValuePair("tmhash", tmHash));
|
||||
// pairs.add(new BasicNameValuePair("wait",
|
||||
// Integer.toString(wait)));
|
||||
// pairs.add(new BasicNameValuePair("waithash", waitHash));
|
||||
// pairs.add(new BasicNameValuePair("upidhash", upId));
|
||||
//
|
||||
// downloadPost.setEntity(new UrlEncodedFormEntity(pairs));
|
||||
//
|
||||
// final HttpResponse downloadResponse = client
|
||||
// .execute(downloadPost);
|
||||
// System.out.println(IOUtils.toString(downloadResponse.getEntity().getContent()));
|
||||
//
|
||||
// return new InputStreamDownloadChannel(downloadResponse
|
||||
// .getEntity().getContent(), 0, "haha");
|
||||
} else {
|
||||
throw new IOException("Download link not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class HotFileAuthenticator implements Authenticator {
|
||||
private final Credential credential;
|
||||
|
||||
public HotFileAuthenticator(Credential credential) {
|
||||
this.credential = credential;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void login() throws ClientProtocolException, IOException {
|
||||
final MultipartEntity entity = new MultipartEntity();
|
||||
|
||||
entity.addPart("returnto", new StringBody("/index.php"));
|
||||
entity.addPart("user", new StringBody(credential.getUsername()));
|
||||
entity.addPart("pass", new StringBody(credential.getPassword()));
|
||||
|
||||
HTMLPage page = postAsPage("http://www.hotfile.com/login.php",
|
||||
entity);
|
||||
final Tag accountTag = page.getTagByID("account");
|
||||
if (accountTag == null)
|
||||
throw new AuthenticationInvalidCredentialException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout() throws IOException {
|
||||
final MultipartEntity entity = new MultipartEntity();
|
||||
entity.addPart("logout", new StringBody("1"));
|
||||
|
||||
postAsString("http://www.megaupload.com/?c=account", entity);
|
||||
// TODO check logout status
|
||||
}
|
||||
}
|
||||
|
||||
public static interface HotFileServiceConfiguration extends
|
||||
ServiceConfiguration {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."
|
||||
+ getMinorVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.rogiel.httpchannel.service.AuthenticationService;
|
||||
import com.rogiel.httpchannel.service.Credential;
|
||||
import com.rogiel.httpchannel.service.DownloadChannel;
|
||||
import com.rogiel.httpchannel.service.DownloadService;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceHelper;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.UploaderCapability;
|
||||
import com.rogiel.httpchannel.service.config.ServiceConfigurationHelper;
|
||||
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
|
||||
import com.rogiel.httpchannel.service.impl.HotFileService.HotFileServiceConfiguration;
|
||||
import com.rogiel.httpchannel.util.ChannelUtils;
|
||||
|
||||
public class HotFileServiceTest {
|
||||
private Service service;
|
||||
private ServiceHelper helper;
|
||||
|
||||
/**
|
||||
* See <b>src/test/resources/config/hotfile.properties</b>
|
||||
* <p>
|
||||
* Key: username
|
||||
*/
|
||||
private String VALID_USERNAME;
|
||||
/**
|
||||
* See <b>src/test/resources/config/hotfile.properties</b>
|
||||
* <p>
|
||||
* Key: password
|
||||
*/
|
||||
private String VALID_PASSWORD;
|
||||
|
||||
private static final String INVALID_USERNAME = "invalid";
|
||||
private static final String INVALID_PASSWORD = "abc";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// MegaUploadServiceConfiguration.class;
|
||||
service = new HotFileService(
|
||||
ServiceConfigurationHelper
|
||||
.defaultConfiguration(HotFileServiceConfiguration.class));
|
||||
helper = new ServiceHelper(service);
|
||||
|
||||
final Properties properties = new Properties();
|
||||
properties.load(new FileInputStream(
|
||||
"src/test/resources/login.properties"));
|
||||
VALID_USERNAME = properties.getProperty("username");
|
||||
VALID_PASSWORD = properties.getProperty("password");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServiceId() {
|
||||
System.out.println("Service: " + service.toString());
|
||||
assertEquals("hotfile", service.getID());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidAuthenticator() throws IOException {
|
||||
((AuthenticationService) service).getAuthenticator(
|
||||
new Credential(VALID_USERNAME, VALID_PASSWORD)).login();
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationInvalidCredentialException.class)
|
||||
public void testInvalidAuthenticator() throws IOException {
|
||||
((AuthenticationService) service).getAuthenticator(
|
||||
new Credential(INVALID_USERNAME, INVALID_PASSWORD)).login();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonLoguedInUploader() throws IOException,
|
||||
URISyntaxException {
|
||||
assertTrue(
|
||||
"This service does not have the capability UploadCapability.FREE_UPLOAD",
|
||||
((UploadService) service).getUploadCapabilities().has(
|
||||
UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD));
|
||||
|
||||
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
||||
final UploadChannel channel = helper.upload(path,
|
||||
"httpchannel test upload");
|
||||
final SeekableByteChannel inChannel = Files.newByteChannel(path);
|
||||
|
||||
try {
|
||||
ChannelUtils.copy(inChannel, channel);
|
||||
} finally {
|
||||
inChannel.close();
|
||||
channel.close();
|
||||
}
|
||||
|
||||
System.out.println(channel.getDownloadLink());
|
||||
Assert.assertNotNull(channel.getDownloadLink());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoguedInUploader() throws IOException {
|
||||
assertTrue(
|
||||
"This service does not have the capability UploadCapability.PREMIUM_UPLOAD",
|
||||
((UploadService) service).getUploadCapabilities().has(
|
||||
UploaderCapability.PREMIUM_ACCOUNT_UPLOAD));
|
||||
|
||||
((AuthenticationService) service).getAuthenticator(
|
||||
new Credential(VALID_USERNAME, VALID_PASSWORD)).login();
|
||||
|
||||
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
||||
final UploadChannel channel = helper.upload(path,
|
||||
"httpchannel test upload");
|
||||
final SeekableByteChannel inChannel = Files.newByteChannel(path);
|
||||
|
||||
try {
|
||||
ChannelUtils.copy(inChannel, channel);
|
||||
} finally {
|
||||
inChannel.close();
|
||||
channel.close();
|
||||
}
|
||||
|
||||
System.out.println(channel.getDownloadLink());
|
||||
Assert.assertNotNull(channel.getDownloadLink());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDownloader() throws IOException, MalformedURLException {
|
||||
final DownloadChannel channel = ((DownloadService) service)
|
||||
.getDownloader(
|
||||
new URL(
|
||||
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
|
||||
.download(null, 0);
|
||||
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
IOUtils.copy(Channels.newInputStream(channel), bout);
|
||||
System.out.println(bout.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoggedInDownloader() throws IOException,
|
||||
MalformedURLException {
|
||||
((AuthenticationService) service).getAuthenticator(
|
||||
new Credential(VALID_USERNAME, VALID_PASSWORD)).login();
|
||||
|
||||
final DownloadChannel channel = ((DownloadService) service)
|
||||
.getDownloader(
|
||||
new URL(
|
||||
"http://hotfile.com/dl/129251605/9b4faf2/simulado_2010_1_res_all.zip.html"))
|
||||
.download(null, 0);
|
||||
|
||||
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
IOUtils.copy(Channels.newInputStream(channel), bout);
|
||||
System.out.println(bout.size());
|
||||
}
|
||||
}
|
||||
1
httpchannel-service/httpchannel-service-hotfile/src/test/resources/.gitignore
vendored
Normal file
1
httpchannel-service/httpchannel-service-hotfile/src/test/resources/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/login.properties
|
||||
@@ -0,0 +1,3 @@
|
||||
This is a simple upload test file.
|
||||
|
||||
This is for testing purposes only.
|
||||
10
httpchannel-service/httpchannel-service-megaupload/pom.xml
Normal file
10
httpchannel-service/httpchannel-service-megaupload/pom.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>httpchannel-service</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-service-megaupload</artifactId>
|
||||
</project>
|
||||
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.io.FilenameUtils;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.NameValuePair;
|
||||
import org.apache.http.client.entity.UrlEncodedFormEntity;
|
||||
import org.apache.http.entity.mime.MultipartEntity;
|
||||
import org.apache.http.entity.mime.content.StringBody;
|
||||
import org.apache.http.message.BasicNameValuePair;
|
||||
|
||||
import com.rogiel.httpchannel.service.AbstractDownloader;
|
||||
import com.rogiel.httpchannel.service.AbstractHttpService;
|
||||
import com.rogiel.httpchannel.service.AuthenticationService;
|
||||
import com.rogiel.httpchannel.service.Authenticator;
|
||||
import com.rogiel.httpchannel.service.AuthenticatorCapability;
|
||||
import com.rogiel.httpchannel.service.CapabilityMatrix;
|
||||
import com.rogiel.httpchannel.service.Credential;
|
||||
import com.rogiel.httpchannel.service.DownloadChannel;
|
||||
import com.rogiel.httpchannel.service.DownloadListener;
|
||||
import com.rogiel.httpchannel.service.DownloadService;
|
||||
import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.DownloaderCapability;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
import com.rogiel.httpchannel.service.UploaderCapability;
|
||||
import com.rogiel.httpchannel.service.channel.InputStreamDownloadChannel;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
|
||||
import com.rogiel.httpchannel.service.channel.LinkedUploadChannelContentBody;
|
||||
import com.rogiel.httpchannel.service.config.ServiceConfiguration;
|
||||
import com.rogiel.httpchannel.service.config.ServiceConfigurationProperty;
|
||||
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
|
||||
import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;
|
||||
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
|
||||
import com.rogiel.httpchannel.service.exception.UploadLinkNotFoundException;
|
||||
import com.rogiel.httpchannel.service.impl.MegaUploadService.MegaUploadServiceConfiguration;
|
||||
import com.rogiel.httpchannel.util.HttpClientUtils;
|
||||
import com.rogiel.httpchannel.util.PatternUtils;
|
||||
import com.rogiel.httpchannel.util.ThreadUtils;
|
||||
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
|
||||
|
||||
/**
|
||||
* This service handles login, upload and download to MegaUpload.com.
|
||||
*
|
||||
* @author Rogiel
|
||||
* @since 1.0
|
||||
*/
|
||||
public class MegaUploadService extends
|
||||
AbstractHttpService<MegaUploadServiceConfiguration> implements Service,
|
||||
UploadService, DownloadService, AuthenticationService {
|
||||
private static final Pattern UPLOAD_URL_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
|
||||
.compile("http://www([0-9]*)\\.megaupload\\.com/files/([A-Za-z0-9]*)/(.*)");
|
||||
private static final Pattern DOWNLOAD_TIMER = Pattern
|
||||
.compile("count=([0-9]*);");
|
||||
// private static final Pattern DOWNLOAD_FILESIZE = Pattern
|
||||
// .compile("[0-9]*(\\.[0-9]*)? (K|M|G)B");
|
||||
|
||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
||||
.compile("http://www\\.megaupload\\.com/\\?d=([A-Za-z0-9]*)");
|
||||
|
||||
private static final Pattern LOGIN_USERNAME_PATTERN = Pattern
|
||||
.compile("flashvars\\.username = \"(.*)\";");
|
||||
|
||||
public MegaUploadService(final MegaUploadServiceConfiguration configuration) {
|
||||
super(configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getID() {
|
||||
return "megaupload";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMajorVersion() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMinorVersion() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader getUploader(String filename, long filesize,
|
||||
String description) {
|
||||
return new MegaUploadUploader(filename, filesize, description);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMaximumFilesize() {
|
||||
return 1 * 1024 * 1024 * 1024;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getSupportedExtensions() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<UploaderCapability> getUploadCapabilities() {
|
||||
return new CapabilityMatrix<UploaderCapability>(
|
||||
UploaderCapability.UNAUTHENTICATED_UPLOAD,
|
||||
UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD,
|
||||
UploaderCapability.PREMIUM_ACCOUNT_UPLOAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Downloader getDownloader(URL url) {
|
||||
return new MegaUploadDownloader(url);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchURL(URL url) {
|
||||
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<DownloaderCapability> getDownloadCapabilities() {
|
||||
return new CapabilityMatrix<DownloaderCapability>(
|
||||
DownloaderCapability.UNAUTHENTICATED_DOWNLOAD,
|
||||
DownloaderCapability.NON_PREMIUM_ACCOUNT_DOWNLOAD,
|
||||
DownloaderCapability.PREMIUM_ACCOUNT_DOWNLOAD);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Authenticator getAuthenticator(Credential credential) {
|
||||
return new MegaUploadAuthenticator(credential);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
|
||||
return new CapabilityMatrix<AuthenticatorCapability>();
|
||||
}
|
||||
|
||||
protected class MegaUploadUploader implements Uploader,
|
||||
LinkedUploadChannelCloseCallback {
|
||||
private final String filename;
|
||||
private final long filesize;
|
||||
private final String description;
|
||||
|
||||
private Future<String> uploadFuture;
|
||||
|
||||
public MegaUploadUploader(String filename, long filesize,
|
||||
String description) {
|
||||
this.filename = filename;
|
||||
this.filesize = filesize;
|
||||
this.description = (description != null ? description
|
||||
: configuration.getDefaultUploadDescription());
|
||||
}
|
||||
|
||||
@Override
|
||||
public UploadChannel upload() throws IOException {
|
||||
final HTMLPage page = getAsPage("http://www.megaupload.com/multiupload/");
|
||||
final String url = page.getFormAction(UPLOAD_URL_PATTERN);
|
||||
|
||||
final LinkedUploadChannel channel = new LinkedUploadChannel(this,
|
||||
filesize, filename);
|
||||
final MultipartEntity entity = new MultipartEntity();
|
||||
|
||||
entity.addPart("multifile_0", new LinkedUploadChannelContentBody(
|
||||
channel));
|
||||
entity.addPart("multimessage_0", new StringBody(description));
|
||||
|
||||
uploadFuture = postAsStringAsync(url, entity);
|
||||
while (!channel.isLinked() && !uploadFuture.isDone()) {
|
||||
ThreadUtils.sleep(100);
|
||||
}
|
||||
return channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String finish() throws IOException {
|
||||
try {
|
||||
String link = PatternUtils.find(DOWNLOAD_URL_PATTERN,
|
||||
uploadFuture.get());
|
||||
if (link == null)
|
||||
throw new UploadLinkNotFoundException();
|
||||
return link;
|
||||
} catch (InterruptedException e) {
|
||||
return null;
|
||||
} catch (ExecutionException e) {
|
||||
throw (IOException) e.getCause();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class MegaUploadDownloader extends AbstractDownloader {
|
||||
private final URL url;
|
||||
|
||||
public MegaUploadDownloader(URL url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DownloadChannel download(DownloadListener listener, long position)
|
||||
throws IOException {
|
||||
HttpResponse response = get(url.toString());
|
||||
|
||||
// disable direct downloads, we don't support them!
|
||||
if (response.getEntity().getContentType().getValue()
|
||||
.equals("application/octet-stream")) {
|
||||
// close connection
|
||||
response.getEntity().getContent().close();
|
||||
|
||||
final List<NameValuePair> pairs = new ArrayList<NameValuePair>();
|
||||
pairs.add(new BasicNameValuePair("do", "directdownloads"));
|
||||
pairs.add(new BasicNameValuePair("accountupdate", "1"));
|
||||
pairs.add(new BasicNameValuePair("set_ddl", "0"));
|
||||
|
||||
// execute update
|
||||
postAsString("http://www.megaupload.com/?c=account",
|
||||
new UrlEncodedFormEntity(pairs));
|
||||
|
||||
// execute and re-request download
|
||||
response = get(url.toString());
|
||||
}
|
||||
|
||||
final HTMLPage page = HttpClientUtils.toPage(response);
|
||||
|
||||
// try to find timer
|
||||
int timer = page.findIntegerInScript(DOWNLOAD_TIMER, 1);
|
||||
if (timer > 0 && configuration.respectWaitTime()) {
|
||||
timer(listener, timer * 1000);
|
||||
}
|
||||
final String downloadUrl = page
|
||||
.getLink(DOWNLOAD_DIRECT_LINK_PATTERN);
|
||||
if (downloadUrl != null && downloadUrl.length() > 0) {
|
||||
final HttpResponse downloadResponse = get(downloadUrl, position);
|
||||
if (downloadResponse.getStatusLine().getStatusCode() == HttpStatus.SC_FORBIDDEN
|
||||
|| downloadResponse.getStatusLine().getStatusCode() == HttpStatus.SC_SERVICE_UNAVAILABLE) {
|
||||
downloadResponse.getEntity().getContent().close();
|
||||
throw new DownloadLimitExceededException("HTTP "
|
||||
+ downloadResponse.getStatusLine().getStatusCode()
|
||||
+ " response");
|
||||
} else {
|
||||
final String filename = FilenameUtils.getName(downloadUrl);
|
||||
final long contentLength = getContentLength(downloadResponse);
|
||||
|
||||
return new InputStreamDownloadChannel(downloadResponse
|
||||
.getEntity().getContent(), contentLength, filename);
|
||||
}
|
||||
} else {
|
||||
throw new DownloadLinkNotFoundException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected class MegaUploadAuthenticator implements Authenticator {
|
||||
private final Credential credential;
|
||||
|
||||
public MegaUploadAuthenticator(Credential credential) {
|
||||
this.credential = credential;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void login() throws IOException {
|
||||
final MultipartEntity entity = new MultipartEntity();
|
||||
|
||||
entity.addPart("login", new StringBody("1"));
|
||||
entity.addPart("username", new StringBody(credential.getUsername()));
|
||||
entity.addPart("password", new StringBody(credential.getPassword()));
|
||||
|
||||
final HTMLPage page = postAsPage(
|
||||
"http://www.megaupload.com/?c=login", entity);
|
||||
String username = page.findInScript(LOGIN_USERNAME_PATTERN, 1);
|
||||
|
||||
if (username == null)
|
||||
throw new AuthenticationInvalidCredentialException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logout() throws IOException {
|
||||
final MultipartEntity entity = new MultipartEntity();
|
||||
entity.addPart("logout", new StringBody("1"));
|
||||
|
||||
postAsString("http://www.megaupload.com/?c=account", entity);
|
||||
// TODO check logout status
|
||||
}
|
||||
}
|
||||
|
||||
public static interface MegaUploadServiceConfiguration extends
|
||||
ServiceConfiguration {
|
||||
@ServiceConfigurationProperty(key = "megaupload.wait", defaultValue = "true")
|
||||
boolean respectWaitTime();
|
||||
|
||||
@ServiceConfigurationProperty(key = "megaupload.port", defaultValue = "80")
|
||||
int getPreferedDownloadPort();
|
||||
|
||||
@ServiceConfigurationProperty(key = "megaupload.description", defaultValue = "Uploaded by seedbox-httpchannel")
|
||||
String getDefaultUploadDescription();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.getClass().getSimpleName() + " " + getMajorVersion() + "."
|
||||
+ getMinorVersion();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* This file is part of seedbox <github.com/seedbox>.
|
||||
*
|
||||
* seedbox is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* seedbox is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with seedbox. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.SeekableByteChannel;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Properties;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.rogiel.httpchannel.service.AuthenticationService;
|
||||
import com.rogiel.httpchannel.service.Credential;
|
||||
import com.rogiel.httpchannel.service.DownloadChannel;
|
||||
import com.rogiel.httpchannel.service.DownloadListener;
|
||||
import com.rogiel.httpchannel.service.DownloadService;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceHelper;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.UploaderCapability;
|
||||
import com.rogiel.httpchannel.service.config.ServiceConfigurationHelper;
|
||||
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
|
||||
import com.rogiel.httpchannel.service.impl.MegaUploadService.MegaUploadServiceConfiguration;
|
||||
import com.rogiel.httpchannel.util.ChannelUtils;
|
||||
|
||||
public class MegaUploadServiceTest {
|
||||
private Service service;
|
||||
private ServiceHelper helper;
|
||||
|
||||
/**
|
||||
* See <b>src/test/resources/config/megaupload.properties</b>
|
||||
* <p>
|
||||
* Key: username
|
||||
*/
|
||||
private String VALID_USERNAME;
|
||||
/**
|
||||
* See <b>src/test/resources/config/megaupload.properties</b>
|
||||
* <p>
|
||||
* Key: password
|
||||
*/
|
||||
private String VALID_PASSWORD;
|
||||
|
||||
private static final String INVALID_USERNAME = "invalid";
|
||||
private static final String INVALID_PASSWORD = "abc";
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
// MegaUploadServiceConfiguration.class;
|
||||
service = new MegaUploadService(
|
||||
ServiceConfigurationHelper
|
||||
.defaultConfiguration(MegaUploadServiceConfiguration.class));
|
||||
helper = new ServiceHelper(service);
|
||||
|
||||
final Properties properties = new Properties();
|
||||
properties.load(new FileInputStream(
|
||||
"src/test/resources/login.properties"));
|
||||
VALID_USERNAME = properties.getProperty("username");
|
||||
VALID_PASSWORD = properties.getProperty("password");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testServiceId() {
|
||||
System.out.println("Service: " + service.toString());
|
||||
assertEquals("megaupload", service.getID());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidAuthenticator() throws IOException {
|
||||
((AuthenticationService) service).getAuthenticator(
|
||||
new Credential(VALID_USERNAME, VALID_PASSWORD)).login();
|
||||
}
|
||||
|
||||
@Test(expected = AuthenticationInvalidCredentialException.class)
|
||||
public void testInvalidAuthenticator() throws IOException {
|
||||
((AuthenticationService) service).getAuthenticator(
|
||||
new Credential(INVALID_USERNAME, INVALID_PASSWORD)).login();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonLoguedInUploader() throws IOException {
|
||||
assertTrue(
|
||||
"This service does not have the capability UploadCapability.FREE_UPLOAD",
|
||||
((UploadService) service).getUploadCapabilities().has(
|
||||
UploaderCapability.NON_PREMIUM_ACCOUNT_UPLOAD));
|
||||
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
||||
final UploadChannel channel = helper.upload(path,
|
||||
"httpchannel test upload");
|
||||
final SeekableByteChannel inChannel = Files.newByteChannel(path);
|
||||
|
||||
try {
|
||||
ChannelUtils.copy(inChannel, channel);
|
||||
} finally {
|
||||
inChannel.close();
|
||||
channel.close();
|
||||
}
|
||||
|
||||
System.out.println(channel.getDownloadLink());
|
||||
Assert.assertNotNull(channel.getDownloadLink());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoguedInUploader() throws IOException {
|
||||
assertTrue(
|
||||
"This service does not have the capability UploadCapability.PREMIUM_UPLOAD",
|
||||
((UploadService) service).getUploadCapabilities().has(
|
||||
UploaderCapability.PREMIUM_ACCOUNT_UPLOAD));
|
||||
|
||||
((AuthenticationService) service).getAuthenticator(
|
||||
new Credential(VALID_USERNAME, VALID_PASSWORD)).login();
|
||||
|
||||
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
||||
final UploadChannel channel = helper.upload(path,
|
||||
"httpchannel test upload");
|
||||
final SeekableByteChannel inChannel = Files.newByteChannel(path);
|
||||
|
||||
try {
|
||||
ChannelUtils.copy(inChannel, channel);
|
||||
} finally {
|
||||
inChannel.close();
|
||||
channel.close();
|
||||
}
|
||||
|
||||
System.out.println(channel.getDownloadLink());
|
||||
Assert.assertNotNull(channel.getDownloadLink());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFreeDownloader() throws IOException, MalformedURLException {
|
||||
final DownloadChannel channel = ((DownloadService) service)
|
||||
.getDownloader(new URL("http://www.megaupload.com/?d=CVQKJ1KM"))
|
||||
.download(new DownloadListener() {
|
||||
@Override
|
||||
public boolean timer(long time) {
|
||||
System.out.println("Waiting " + time);
|
||||
// if (reason == TimerWaitReason.DOWNLOAD_TIMER)
|
||||
// return true;
|
||||
return true;
|
||||
}
|
||||
}, 0);
|
||||
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
IOUtils.copy(Channels.newInputStream(channel), bout);
|
||||
System.out.println(bout.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPremiumDownloader() throws IOException,
|
||||
MalformedURLException {
|
||||
((AuthenticationService) service).getAuthenticator(
|
||||
new Credential(VALID_USERNAME, VALID_PASSWORD)).login();
|
||||
|
||||
final DownloadChannel channel = ((DownloadService) service)
|
||||
.getDownloader(new URL("http://www.megaupload.com/?d=CVQKJ1KM"))
|
||||
.download(new DownloadListener() {
|
||||
@Override
|
||||
public boolean timer(long time) {
|
||||
System.out.println("Waiting " + time);
|
||||
return true;
|
||||
}
|
||||
}, 0);
|
||||
final ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
IOUtils.copy(Channels.newInputStream(channel), bout);
|
||||
System.out.println(bout.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoWaitDownloader() throws IOException,
|
||||
MalformedURLException {
|
||||
service = new MegaUploadService(ServiceConfigurationHelper.file(
|
||||
MegaUploadServiceConfiguration.class, new File(
|
||||
"src/test/resources/megaupload-nowait.properties")));
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
final DownloadChannel channel = ((DownloadService) service)
|
||||
.getDownloader(new URL("http://www.megaupload.com/?d=CVQKJ1KM"))
|
||||
.download(new DownloadListener() {
|
||||
@Override
|
||||
public boolean timer(long time) {
|
||||
System.out.println("Waiting " + time);
|
||||
return false;
|
||||
}
|
||||
}, 0);
|
||||
}
|
||||
}
|
||||
1
httpchannel-service/httpchannel-service-megaupload/src/test/resources/.gitignore
vendored
Normal file
1
httpchannel-service/httpchannel-service-megaupload/src/test/resources/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/login.properties
|
||||
@@ -0,0 +1,3 @@
|
||||
This is a simple upload test file.
|
||||
|
||||
This is for testing purposes only.
|
||||
30
httpchannel-service/pom.xml
Normal file
30
httpchannel-service/pom.xml
Normal file
@@ -0,0 +1,30 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<artifactId>httpchannel</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-service</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
<module>httpchannel-service-megaupload</module>
|
||||
<module>httpchannel-service-hotfile</module>
|
||||
</modules>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel-api</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<artifactId>httpchannel-util</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
Reference in New Issue
Block a user