mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Implements SeekableDownloadChannel
The SeekableDownloadChannel implements SeekableByteChannel and allows to set the position of the channel and read data from that point onward. The SeekableDownloadChannel implementation, creates a new internal DownloadChannel at every call to position(long), that will create a resume channel onto that point, thus, not all service implementations are supported.
This commit is contained in:
@@ -18,6 +18,7 @@ import com.rogiel.httpchannel.service.CapabilityMatrix;
|
||||
import com.rogiel.httpchannel.service.Credential;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceID;
|
||||
import com.rogiel.httpchannel.service.ServiceMode;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
@@ -66,6 +67,12 @@ public class DepositFilesService extends AbstractHttpService implements
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> getUploader(String filename,
|
||||
long filesize, NullUploaderConfiguration configuration) {
|
||||
@@ -131,7 +138,7 @@ public class DepositFilesService extends AbstractHttpService implements
|
||||
|
||||
public UploaderImpl(String filename, long filesize,
|
||||
NullUploaderConfiguration configuration) {
|
||||
super(filename, filesize, configuration);
|
||||
super(DepositFilesService.this, filename, filesize, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -209,6 +216,7 @@ public class DepositFilesService extends AbstractHttpService implements
|
||||
captchaService.valid(captcha);
|
||||
if (!page.contains(VALID_LOGIN_REDIRECT))
|
||||
throw new AuthenticationInvalidCredentialException();
|
||||
serviceMode = ServiceMode.NON_PREMIUM;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import com.rogiel.httpchannel.service.CapabilityMatrix;
|
||||
import com.rogiel.httpchannel.service.Credential;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceID;
|
||||
import com.rogiel.httpchannel.service.ServiceMode;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
@@ -81,6 +82,12 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> getUploader(String filename,
|
||||
long filesize, NullUploaderConfiguration configuration) {
|
||||
@@ -149,7 +156,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
||||
|
||||
public UploaderImpl(String filename, long filesize,
|
||||
NullUploaderConfiguration configuration) {
|
||||
super(filename, filesize, configuration);
|
||||
super(FileSonicService.this, filename, filesize, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -186,6 +193,7 @@ public class FileSonicService extends AbstractHttpService implements Service,
|
||||
public void login() throws IOException {
|
||||
logger.debug("Logging to filesonic.com");
|
||||
api.login(credential.getUsername(), credential.getPassword());
|
||||
serviceMode = ServiceMode.NON_PREMIUM;
|
||||
// if (username == null)
|
||||
// throw new AuthenticationInvalidCredentialException();
|
||||
}
|
||||
|
||||
@@ -22,8 +22,6 @@ 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.htmlparser.Tag;
|
||||
|
||||
@@ -43,11 +41,11 @@ import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.DownloaderCapability;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceID;
|
||||
import com.rogiel.httpchannel.service.ServiceMode;
|
||||
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.config.NullAuthenticatorConfiguration;
|
||||
@@ -99,6 +97,12 @@ public class HotFileService extends AbstractHttpService implements Service,
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> getUploader(String filename,
|
||||
long filesize, NullUploaderConfiguration configuration) {
|
||||
@@ -191,7 +195,7 @@ public class HotFileService extends AbstractHttpService implements Service,
|
||||
|
||||
public UploaderImpl(String filename, long filesize,
|
||||
NullUploaderConfiguration configuration) {
|
||||
super(filename, filesize, configuration);
|
||||
super(HotFileService.this, filename, filesize, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -224,7 +228,7 @@ public class HotFileService extends AbstractHttpService implements Service,
|
||||
protected class DownloaderImpl extends
|
||||
AbstractHttpDownloader<NullDownloaderConfiguration> {
|
||||
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
|
||||
super(uri, configuration);
|
||||
super(HotFileService.this, uri, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -251,14 +255,7 @@ public class HotFileService extends AbstractHttpService implements Service,
|
||||
// final String tmHash = PatternUtils.find(DOWNLOAD_TMHASH_PATTERN,
|
||||
// content);F
|
||||
if (downloadUrl != null && downloadUrl.length() > 0) {
|
||||
final HttpResponse downloadResponse = get(downloadUrl)
|
||||
.request();
|
||||
|
||||
final String filename = FilenameUtils.getName(downloadUrl);
|
||||
long contentLength = getContentLength(downloadResponse);
|
||||
|
||||
return new InputStreamDownloadChannel(downloadResponse
|
||||
.getEntity().getContent(), contentLength, filename);
|
||||
return download(get(downloadUrl));
|
||||
} else {
|
||||
throw new IOException("Download link not found");
|
||||
}
|
||||
@@ -284,6 +281,7 @@ public class HotFileService extends AbstractHttpService implements Service,
|
||||
final Tag accountTag = page.getTagByID("account");
|
||||
if (accountTag == null)
|
||||
throw new AuthenticationInvalidCredentialException();
|
||||
serviceMode = ServiceMode.NON_PREMIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,6 +42,7 @@ import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.DownloaderCapability;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceID;
|
||||
import com.rogiel.httpchannel.service.ServiceMode;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
@@ -102,6 +103,12 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<MegaUploadUploaderConfiguration> getUploader(
|
||||
String filename, long filesize,
|
||||
@@ -200,7 +207,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
||||
|
||||
public UploaderImpl(String filename, long filesize,
|
||||
MegaUploadUploaderConfiguration configuration) {
|
||||
super(filename, filesize, configuration);
|
||||
super(MegaUploadService.this, filename, filesize, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,7 +217,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
||||
.asPage();
|
||||
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
|
||||
logger.debug("Upload URI is {}", uri);
|
||||
|
||||
|
||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||
uploadFuture = multipartPost(uri)
|
||||
.parameter("multimessage_0", configuration.description())
|
||||
@@ -236,7 +243,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
||||
Downloader<MegaUploadDownloaderConfiguration> {
|
||||
public DownloaderImpl(URI uri,
|
||||
MegaUploadDownloaderConfiguration configuration) {
|
||||
super(uri, configuration);
|
||||
super(MegaUploadService.this, uri, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -313,6 +320,7 @@ public class MegaUploadService extends AbstractHttpService implements Service,
|
||||
String username = page.findScript(LOGIN_USERNAME_PATTERN, 1);
|
||||
if (username == null)
|
||||
throw new AuthenticationInvalidCredentialException();
|
||||
serviceMode = ServiceMode.NON_PREMIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.DownloaderCapability;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceID;
|
||||
import com.rogiel.httpchannel.service.ServiceMode;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
@@ -80,6 +81,12 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<MultiUploadUploaderConfiguration> getUploader(
|
||||
String filename, long filesize,
|
||||
@@ -178,7 +185,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
||||
|
||||
public UploaderImpl(String filename, long filesize,
|
||||
MultiUploadUploaderConfiguration configuration) {
|
||||
super(filename, filesize, configuration);
|
||||
super(MultiUploadService.this, filename, filesize, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -225,7 +232,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
||||
Downloader<NullDownloaderConfiguration> {
|
||||
protected DownloaderImpl(URI uri,
|
||||
NullDownloaderConfiguration configuration) {
|
||||
super(uri, configuration);
|
||||
super(MultiUploadService.this, uri, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -258,6 +265,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
|
||||
|
||||
if (!page.containsIgnoreCase(credential.getUsername()))
|
||||
throw new AuthenticationInvalidCredentialException();
|
||||
serviceMode = ServiceMode.NON_PREMIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.DownloaderCapability;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceID;
|
||||
import com.rogiel.httpchannel.service.ServiceMode;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
@@ -82,6 +83,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> getUploader(String filename,
|
||||
long filesize, NullUploaderConfiguration configuration) {
|
||||
@@ -177,7 +184,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
|
||||
public UploaderImpl(String filename, long filesize,
|
||||
NullUploaderConfiguration configuration) {
|
||||
super(filename, filesize, configuration);
|
||||
super(UploadHereService.this, filename, filesize, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -223,7 +230,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
||||
Downloader<NullDownloaderConfiguration> {
|
||||
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
|
||||
super(uri, configuration);
|
||||
super(UploadHereService.this, uri, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -288,6 +295,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
.parameter("password", credential.getPassword()).asPage();
|
||||
if (page.contains(INVALID_LOGIN_STRING))
|
||||
throw new AuthenticationInvalidCredentialException();
|
||||
serviceMode = ServiceMode.NON_PREMIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -24,6 +24,7 @@ import com.rogiel.httpchannel.service.Downloader;
|
||||
import com.rogiel.httpchannel.service.DownloaderCapability;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceID;
|
||||
import com.rogiel.httpchannel.service.ServiceMode;
|
||||
import com.rogiel.httpchannel.service.UploadChannel;
|
||||
import com.rogiel.httpchannel.service.UploadService;
|
||||
import com.rogiel.httpchannel.service.Uploader;
|
||||
@@ -82,6 +83,12 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>(ServiceMode.UNAUTHENTICATED,
|
||||
ServiceMode.NON_PREMIUM, ServiceMode.PREMIUM);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uploader<NullUploaderConfiguration> getUploader(String filename,
|
||||
long filesize, NullUploaderConfiguration configuration) {
|
||||
@@ -177,7 +184,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
||||
|
||||
public UploaderImpl(String filename, long filesize,
|
||||
NullUploaderConfiguration configuration) {
|
||||
super(filename, filesize, configuration);
|
||||
super(UploadKingService.this, filename, filesize, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -220,7 +227,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
||||
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
||||
Downloader<NullDownloaderConfiguration> {
|
||||
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
|
||||
super(uri, configuration);
|
||||
super(UploadKingService.this, uri, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -287,6 +294,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
|
||||
.parameter("password", credential.getPassword()).asPage();
|
||||
if (page.contains(INVALID_LOGIN_STRING))
|
||||
throw new AuthenticationInvalidCredentialException();
|
||||
serviceMode = ServiceMode.NON_PREMIUM;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import com.rogiel.httpchannel.service.AbstractHttpService;
|
||||
import com.rogiel.httpchannel.service.CapabilityMatrix;
|
||||
import com.rogiel.httpchannel.service.Service;
|
||||
import com.rogiel.httpchannel.service.ServiceID;
|
||||
import com.rogiel.httpchannel.service.ServiceMode;
|
||||
|
||||
/**
|
||||
* This service handles uploads to UploadKing.com.
|
||||
@@ -35,14 +37,15 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
||||
// Pattern.CASE_INSENSITIVE);
|
||||
// private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
||||
// .compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
||||
// 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_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!";
|
||||
// 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_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 getServiceID() {
|
||||
@@ -59,6 +62,16 @@ public class ZShareService extends AbstractHttpService implements Service/*
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ServiceMode getServiceMode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CapabilityMatrix<ServiceMode> getPossibleServiceModes() {
|
||||
return new CapabilityMatrix<ServiceMode>();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public Uploader<ZShareUploaderConfiguration> getUploader(String filename,
|
||||
// long filesize, ZShareUploaderConfiguration configuration) {
|
||||
|
||||
Reference in New Issue
Block a user