1
0
mirror of https://github.com/Rogiel/httpchannel synced 2025-12-05 23:22:51 +00:00

Implements a new, more clean and robust HTML parser

This commit is contained in:
2012-05-06 16:04:56 -03:00
parent 4a9da1708e
commit 0386906356
33 changed files with 1619 additions and 981 deletions

View File

@@ -51,7 +51,7 @@ import com.rogiel.httpchannel.service.exception.DownloadNotAuthorizedException;
import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
import com.rogiel.httpchannel.service.exception.NoCaptchaServiceException;
import com.rogiel.httpchannel.util.ExceptionUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
/**
* This service handles uploads to TwoShared.
@@ -165,7 +165,7 @@ public class TwoSharedService extends AbstractHttpService implements Service,
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
private Future<HTMLPage> uploadFuture;
private Future<Page> uploadFuture;
private String uploadID;
public UploaderImpl(String filename, long filesize,
@@ -176,12 +176,12 @@ public class TwoSharedService extends AbstractHttpService implements Service,
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to TwoShared");
final HTMLPage page = get("http://www.2shared.com/").asPage();
final Page page = get("http://www.2shared.com/").asPage();
// locate upload uri
final String uri = page.findFormAction(UPLOAD_URL_PATTERN);
final String mainDC = page.getInputValue("mainDC");
uploadID = page.find(UPLOAD_ID_PATTERN, 1);
final String uri = page.form(UPLOAD_URL_PATTERN).asString();
final String mainDC = page.inputByName("mainDC").asString();
uploadID = page.search(UPLOAD_ID_PATTERN).asString(1);
logger.debug("Upload URI: {}, DC: {}", uri, mainDC);
@@ -198,10 +198,10 @@ public class TwoSharedService extends AbstractHttpService implements Service,
public String finish() throws IOException {
try {
uploadFuture.get();
final HTMLPage page = get(
final Page page = get(
"http://www.2shared.com/uploadComplete.jsp?sId="
+ uploadID).asPage();
return page.getTextareaValueById("downloadLink");
return page.textareaByID("downloadLink").asString();
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
@@ -232,9 +232,9 @@ public class TwoSharedService extends AbstractHttpService implements Service,
DownloadLinkNotFoundException, DownloadLimitExceededException,
DownloadNotAuthorizedException, DownloadNotResumableException,
UnsolvableCaptchaServiceException, NoCaptchaServiceException {
final HTMLPage page = get(uri).asPage();
final String downloadUri = page.findScript(
DIRECT_DOWNLOAD_URL_PATTERN, 0);
final Page page = get(uri).asPage();
final String downloadUri = page.script(
DIRECT_DOWNLOAD_URL_PATTERN).asString();
return download(get(downloadUri));
}
}

View File

@@ -30,6 +30,9 @@ import com.rogiel.httpchannel.service.AbstractAuthenticator;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.DiskQuotaAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.FilesizeLimitAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -42,9 +45,6 @@ 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.AccountDetails.DiskQuotaAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.FilesizeLimitAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
@@ -52,7 +52,7 @@ import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.service.exception.ChannelServiceException;
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
/**
* This service handles uploads to 4shared.com.
@@ -168,7 +168,7 @@ public class FourSharedService extends AbstractHttpService implements Service,
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
private Future<HTMLPage> uploadFuture;
private Future<Page> uploadFuture;
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
@@ -210,8 +210,8 @@ public class FourSharedService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
final long linkID = Long.parseLong(uploadFuture.get()
.getInputValueById("uploadedFileId"));
final long linkID = uploadFuture.get()
.inputByID("uploadedFileId").asLong();
return api.getFileDownloadLink(account.getUsername(),
getPassword(), linkID);
} catch (InterruptedException e) {

View File

@@ -48,7 +48,7 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadCh
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
/**
* This service handles uploads to UploadKing.com.
@@ -147,9 +147,10 @@ public class DepositFilesService extends AbstractHttpService implements
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
return new CapabilityMatrix<AuthenticatorCapability>(
AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
@@ -159,7 +160,7 @@ public class DepositFilesService extends AbstractHttpService implements
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
private Future<HTMLPage> uploadFuture;
private Future<Page> uploadFuture;
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
@@ -169,11 +170,13 @@ public class DepositFilesService extends AbstractHttpService implements
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to depositfiles.com");
final HTMLPage page = get("http://www.depositfiles.com/").asPage();
final Page page = get("http://www.depositfiles.com/").asPage();
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
final String maxFileSize = page.getInputValue("MAX_FILE_SIZE");
final String uri = page.form(UPLOAD_URI_PATTERN).asString();
final String uploadID = page.inputByName("UPLOAD_IDENTIFIER")
.asString();
final String maxFileSize = page.formByName("MAX_FILE_SIZE")
.asString();
logger.debug("Upload URI: {}, ID: {}", uri, uploadID);
@@ -189,8 +192,8 @@ public class DepositFilesService extends AbstractHttpService implements
@Override
public String finish() throws IOException {
try {
final String link = uploadFuture.get().findScript(
DOWNLOAD_URI_PATTERN, 0);
final String link = uploadFuture.get()
.script(DOWNLOAD_URI_PATTERN).asString();
if (link == null)
return null;
return link;
@@ -213,7 +216,7 @@ public class DepositFilesService extends AbstractHttpService implements
@Override
public AccountDetails login() throws IOException {
logger.debug("Authenticating into depositfiles.com");
HTMLPage page = post("http://depositfiles.com/login.php?return=%2F")
Page page = post("http://depositfiles.com/login.php?return=%2F")
.parameter("go", true)
.parameter("login", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
@@ -239,9 +242,10 @@ public class DepositFilesService extends AbstractHttpService implements
throw new UnsolvableCaptchaServiceException();
} else {
captchaService.valid(captcha);
if (!page.contains(VALID_LOGIN_REDIRECT))
if (!page.search(VALID_LOGIN_REDIRECT).hasResults())
throw new AuthenticationInvalidCredentialException();
return (account = new AccountDetailsImpl(credential.getUsername()));
return (account = new AccountDetailsImpl(
credential.getUsername()));
}
}

View File

@@ -25,7 +25,6 @@ import java.util.concurrent.Future;
import java.util.regex.Pattern;
import org.apache.http.client.ClientProtocolException;
import org.htmlparser.Tag;
import com.rogiel.httpchannel.service.AbstractAccountDetails;
import com.rogiel.httpchannel.service.AbstractAuthenticator;
@@ -33,6 +32,9 @@ import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.HotLinkingAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.ReferralAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -50,14 +52,15 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
import com.rogiel.httpchannel.service.config.NullDownloaderConfiguration;
import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.Filesizes;
import com.rogiel.httpchannel.util.html.Page;
import com.rogiel.httpchannel.util.html.SearchResults;
/**
* This service handles login, upload and download to HotFile.com.
@@ -75,17 +78,31 @@ public class HotFileService extends AbstractHttpService implements Service,
public static final ServiceID SERVICE_ID = ServiceID.create("hotfile");
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://u[0-9]*\\.hotfile\\.com/upload\\.cgi\\?[0-9]*");
.compile("http[s]?://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]*)/(.*)");
.compile("http[s]?://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_URI_PATTERN = Pattern
.compile("http://hotfile\\.com/dl/([0-9]*)/([A-Za-z0-9]*)/(.*)");
.compile("http[s]?://hotfile\\.com/dl/([0-9]+)/([A-Za-z0-9]+)/(.+)");
// account
private static final Pattern ACCOUNT_NAME_PATTERN = Pattern
.compile("User: ([^\\|]+)");
private static final Pattern ACCOUNT_TYPE_PATTERN = Pattern
.compile("Account: Free");
private static final Pattern HOTLINK_TRAFFIC_PATTERN = Pattern.compile(
"Hotlink traffic left: ([0-9]+(\\.[0-9]+))(K|M|G)b",
Pattern.CASE_INSENSITIVE);
private static final Pattern REFERRAL_URL_PATTERN = Pattern
.compile("http[s]?://hotfile\\.com/register\\.html\\?reff=[0-9]+");
@Override
public ServiceID getServiceID() {
@@ -189,9 +206,10 @@ public class HotFileService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
return new CapabilityMatrix<AuthenticatorCapability>(
AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
@@ -201,7 +219,7 @@ public class HotFileService extends AbstractHttpService implements Service,
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
private Future<HTMLPage> uploadFuture;
private Future<Page> uploadFuture;
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
@@ -211,8 +229,8 @@ public class HotFileService extends AbstractHttpService implements Service,
@Override
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_URI_PATTERN);
final Page page = get("http://www.hotfile.com/").asPage();
final String action = page.form(UPLOAD_URI_PATTERN).asString();
logger.debug("Upload URI is {}", action);
@@ -226,7 +244,8 @@ public class HotFileService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return uploadFuture.get().getInputValue(DOWNLOAD_URI_PATTERN);
return uploadFuture.get().input(DOWNLOAD_URI_PATTERN)
.asString();
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
@@ -245,7 +264,7 @@ public class HotFileService extends AbstractHttpService implements Service,
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
logger.debug("Downloading {} from hotfile.com", uri);
final HTMLPage page = get(uri).asPage();
final Page page = get(uri).asPage();
// // try to find timer
// final String stringTimer = PatternUtils.find(DOWNLOAD_TIMER,
@@ -259,8 +278,8 @@ public class HotFileService extends AbstractHttpService implements Service,
// + " milliseconds");
// }
final String downloadUrl = page
.findLink(DOWNLOAD_DIRECT_LINK_PATTERN);
final String downloadUrl = page.link(DOWNLOAD_DIRECT_LINK_PATTERN)
.asString();
logger.debug("Download link is {}", downloadUrl);
// final String tmHash = PatternUtils.find(DOWNLOAD_TMHASH_PATTERN,
// content);F
@@ -284,15 +303,32 @@ public class HotFileService extends AbstractHttpService implements Service,
public AccountDetails login() throws ClientProtocolException,
IOException {
logger.debug("Authenticating hotfile.com");
HTMLPage page = post("http://www.hotfile.com/login.php")
Page page = post("http://www.hotfile.com/login.php")
.parameter("returnto", "/index.php")
.parameter("user", credential.getUsername())
.parameter("pass", credential.getPassword()).asPage();
final Tag accountTag = page.getTagByID("account");
if (accountTag == null)
page = get("http://www.hotfile.com/myreferals.html?lang=en")
.asPage();
final SearchResults usernameResults = page
.search(ACCOUNT_NAME_PATTERN);
if (!usernameResults.hasResults())
throw new AuthenticationInvalidCredentialException();
return (account = new AccountDetailsImpl(credential.getUsername()));
final String username = usernameResults.asString(1);
final String type = page.search(ACCOUNT_TYPE_PATTERN).asString();
final SearchResults trafficResults = page
.search(HOTLINK_TRAFFIC_PATTERN);
final long hotlinkTraffic = Filesizes.auto(
trafficResults.asDouble(1), trafficResults.asString(3));
final String referralURL = page.search(REFERRAL_URL_PATTERN)
.asString();
return (account = new AccountDetailsImpl(username, type == null,
hotlinkTraffic, referralURL));
}
@Override
@@ -304,19 +340,48 @@ public class HotFileService extends AbstractHttpService implements Service,
}
private class AccountDetailsImpl extends AbstractAccountDetails implements
PremiumAccountDetails {
PremiumAccountDetails, ReferralAccountDetails,
HotLinkingAccountDetails {
private final boolean premium;
private final long hotlinkTraffic;
private final String referralURL;
/**
* @param username
* the username
* @param premium
* whether the account is premium
* @param hotlinkTraffic
* the available hotlink traffic
* @param referralURL
* the referral url
*/
public AccountDetailsImpl(String username) {
public AccountDetailsImpl(String username, boolean premium,
long hotlinkTraffic, String referralURL) {
super(HotFileService.this, username);
this.premium = premium;
this.hotlinkTraffic = hotlinkTraffic;
this.referralURL = referralURL;
}
@Override
public boolean isPremium() {
// TODO implement this
return false;
return premium;
}
@Override
public long getHotlinkTraffic() {
return hotlinkTraffic;
}
@Override
public int getMembersReferred() {
return -1;
}
@Override
public String getReferralURL() {
return referralURL;
}
}

View File

@@ -36,7 +36,7 @@ import com.rogiel.httpchannel.service.UploaderCapability;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullUploaderConfiguration;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
/**
* This service handles login, upload and download to HotFile.com.
@@ -115,7 +115,7 @@ public class IFileService extends AbstractHttpService implements Service,
AbstractUploader<NullUploaderConfiguration> implements
Uploader<NullUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
private Future<HTMLPage> uploadFuture;
private Future<Page> uploadFuture;
public UploaderImpl(String filename, long filesize,
NullUploaderConfiguration configuration) {
@@ -125,9 +125,9 @@ public class IFileService extends AbstractHttpService implements Service,
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to ifile.it");
final HTMLPage page = get("http://ifile.it/upload-classic.html")
final Page page = get("http://ifile.it/upload-classic.html")
.asPage();
final String action = page.findFormAction(UPLOAD_URI_PATTERN);
final String action = page.form(UPLOAD_URI_PATTERN).asString();
logger.debug("Upload URI is {}", action);
@@ -141,7 +141,7 @@ public class IFileService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return uploadFuture.get().getInputValue(DOWNLOAD_URI_PATTERN);
return uploadFuture.get().input(DOWNLOAD_URI_PATTERN).asString();
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {

View File

@@ -34,6 +34,7 @@ import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -51,7 +52,6 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
@@ -60,7 +60,7 @@ import com.rogiel.httpchannel.service.exception.DownloadLimitExceededException;
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
import com.rogiel.httpchannel.util.HttpClientUtils;
import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
/**
* This service handles login, upload and download to MegaUpload.com.
@@ -223,9 +223,9 @@ public class MegaUploadService extends AbstractHttpService implements Service,
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to megaupload.com");
final HTMLPage page = get("http://www.megaupload.com/multiupload/")
final Page page = get("http://www.megaupload.com/multiupload/")
.asPage();
final String uri = page.findFormAction(UPLOAD_URL_PATTERN);
final String uri = page.form(UPLOAD_URL_PATTERN).asString();
logger.debug("Upload URI is {}", uri);
final LinkedUploadChannel channel = createLinkedChannel(this);
@@ -279,16 +279,16 @@ public class MegaUploadService extends AbstractHttpService implements Service,
response = get(uri).request();
}
final HTMLPage page = HttpClientUtils.toPage(response);
final Page page = HttpClientUtils.toPage(response);
// try to find timer
int timer = page.findScriptAsInt(DOWNLOAD_TIMER, 1);
int timer = page.script(DOWNLOAD_TIMER).asInteger(1);
if (timer > 0 && configuration.getRespectWaitTime()) {
logger.debug("");
timer(listener, timer * 1000);
}
final String downloadUrl = page
.findLink(DOWNLOAD_DIRECT_LINK_PATTERN);
.link(DOWNLOAD_DIRECT_LINK_PATTERN).asString();
if (downloadUrl != null && downloadUrl.length() > 0) {
final HttpResponse downloadResponse = get(downloadUrl)
.position(position).request();
@@ -322,12 +322,12 @@ public class MegaUploadService extends AbstractHttpService implements Service,
@Override
public AccountDetails login() throws IOException {
logger.debug("Starting login to megaupload.com");
final HTMLPage page = post("http://www.megaupload.com/?c=login")
final Page page = post("http://www.megaupload.com/?c=login")
.parameter("login", true)
.parameter("username", credential.getUsername())
.parameter("", credential.getPassword()).asPage();
String username = page.findScript(LOGIN_USERNAME_PATTERN, 1);
String username = page.script(LOGIN_USERNAME_PATTERN).asString(1);
if (username == null)
throw new AuthenticationInvalidCredentialException();
return (account = new AccountDetailsImpl(credential.getUsername()));

View File

@@ -31,6 +31,7 @@ import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -48,7 +49,6 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
@@ -60,8 +60,7 @@ import com.rogiel.httpchannel.service.exception.DownloadNotAuthorizedException;
import com.rogiel.httpchannel.service.exception.DownloadNotResumableException;
import com.rogiel.httpchannel.service.multiupload.MultiUploadUploaderConfiguration.MultiUploadMirrorService;
import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
/**
* This service handles uploads to MultiUpload.nl.
@@ -196,9 +195,10 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public CapabilityMatrix<AuthenticatorCapability> getAuthenticationCapability() {
return new CapabilityMatrix<AuthenticatorCapability>(AuthenticatorCapability.ACCOUNT_DETAILS);
return new CapabilityMatrix<AuthenticatorCapability>(
AuthenticatorCapability.ACCOUNT_DETAILS);
}
@Override
public AccountDetails getAccountDetails() {
return account;
@@ -219,7 +219,7 @@ public class MultiUploadService extends AbstractHttpService implements Service,
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to multiupload.nl");
final String uri = get("http://www.multiupload.nl/").asPage()
.findFormAction(UPLOAD_URI_PATTERN);
.form(UPLOAD_URI_PATTERN).asString();
logger.debug("Upload URI is {}", uri);
final LinkedUploadChannel channel = createLinkedChannel(this);
@@ -273,8 +273,9 @@ public class MultiUploadService extends AbstractHttpService implements Service,
long position) throws IOException,
DownloadLinkNotFoundException, DownloadLimitExceededException,
DownloadNotAuthorizedException, DownloadNotResumableException {
final HTMLPage page = get(uri).asPage();
final String link = page.findLink(DIRECT_DOWNLOAD_LINK_PATTERN);
final Page page = get(uri).asPage();
final String link = page.link(DIRECT_DOWNLOAD_LINK_PATTERN)
.asString();
logger.debug("Direct download link is {}", link);
if (link == null)
throw new DownloadLinkNotFoundException();
@@ -292,11 +293,13 @@ public class MultiUploadService extends AbstractHttpService implements Service,
@Override
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.multiupload.nl/login")
final Page page = post("http://www.multiupload.nl/login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (!page.containsIgnoreCase(credential.getUsername()))
if (page.search(Pattern.compile(
Pattern.quote(credential.getUsername()),
Pattern.CASE_INSENSITIVE)) != null)
throw new AuthenticationInvalidCredentialException();
return (account = new AccountDetailsImpl(credential.getUsername()));
}

View File

@@ -32,6 +32,7 @@ import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -49,7 +50,6 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
@@ -59,7 +59,7 @@ import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialE
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
import com.rogiel.httpchannel.service.exception.InvalidCaptchaException;
import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
/**
* This service handles uploads to UploadKing.com.
@@ -215,11 +215,11 @@ public class UploadHereService extends AbstractHttpService implements Service,
@Override
public UploadChannel openChannel() throws IOException {
final HTMLPage page = get("http://www.uploadhere.com/").asPage();
final Page page = get("http://www.uploadhere.com/").asPage();
final String userCookie = page.getInputValueById("usercookie");
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
final String userCookie = page.inputByID("usercookie").asString();
final String uri = page.form(UPLOAD_URI_PATTERN).asString();
final String uploadID = page.inputByName("UPLOAD_IDENTIFIER").asString();
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
new Object[] { uri, userCookie, uploadID });
@@ -262,9 +262,9 @@ public class UploadHereService extends AbstractHttpService implements Service,
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
HTMLPage page = get(uri).asPage();
Page page = get(uri).asPage();
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
final int waitTime = page.script(TIMER_PATTERN).asInteger(1) * 1000;
logger.debug("Wait time is {}", waitTime);
timer(listener, waitTime);
@@ -309,11 +309,11 @@ public class UploadHereService extends AbstractHttpService implements Service,
@Override
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.uploadhere.com/login")
final Page page = post("http://www.uploadhere.com/login")
.parameter("do", "login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
if (page.searchFirst(INVALID_LOGIN_STRING).hasResults())
throw new AuthenticationInvalidCredentialException();
return (account = new AccountDetailsImpl(credential.getUsername()));
}

View File

@@ -32,6 +32,7 @@ import com.rogiel.httpchannel.service.AbstractHttpDownloader;
import com.rogiel.httpchannel.service.AbstractHttpService;
import com.rogiel.httpchannel.service.AbstractUploader;
import com.rogiel.httpchannel.service.AccountDetails;
import com.rogiel.httpchannel.service.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.AuthenticationService;
import com.rogiel.httpchannel.service.Authenticator;
import com.rogiel.httpchannel.service.AuthenticatorCapability;
@@ -49,7 +50,6 @@ 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.AccountDetails.PremiumAccountDetails;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel;
import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadChannelCloseCallback;
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
@@ -59,7 +59,7 @@ import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialE
import com.rogiel.httpchannel.service.exception.DownloadLinkNotFoundException;
import com.rogiel.httpchannel.service.exception.InvalidCaptchaException;
import com.rogiel.httpchannel.util.PatternUtils;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
/**
* This service handles uploads to zshare.net.
@@ -215,11 +215,11 @@ public class UploadKingService extends AbstractHttpService implements Service,
@Override
public UploadChannel openChannel() throws IOException {
final HTMLPage page = get("http://www.uploadking.com/").asPage();
final Page page = get("http://www.uploadking.com/").asPage();
final String userCookie = page.getInputValueById("usercookie");
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
final String userCookie = page.inputByID("usercookie").asString();
final String uri = page.form(UPLOAD_URI_PATTERN).asString();
final String uploadID = page.inputByName("UPLOAD_IDENTIFIER").asString();
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
new Object[] { uri, userCookie, uploadID });
@@ -259,9 +259,9 @@ public class UploadKingService extends AbstractHttpService implements Service,
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
HTMLPage page = get(uri).asPage();
Page page = get(uri).asPage();
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
final int waitTime = page.script(TIMER_PATTERN).asInteger(1) * 1000;
logger.debug("Wait time is {}", waitTime);
timer(listener, waitTime);
@@ -306,11 +306,11 @@ public class UploadKingService extends AbstractHttpService implements Service,
@Override
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://www.uploadking.com/login")
final Page page = post("http://www.uploadking.com/login")
.parameter("do", "login")
.parameter("username", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
if (page.contains(INVALID_LOGIN_STRING))
if (page.searchFirst(INVALID_LOGIN_STRING).hasResults())
throw new AuthenticationInvalidCredentialException();
return (account = new AccountDetailsImpl(credential.getUsername()));
}

View File

@@ -50,7 +50,8 @@ import com.rogiel.httpchannel.service.channel.LinkedUploadChannel.LinkedUploadCh
import com.rogiel.httpchannel.service.config.NullAuthenticatorConfiguration;
import com.rogiel.httpchannel.service.exception.AuthenticationInvalidCredentialException;
import com.rogiel.httpchannel.util.Filesizes;
import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
import com.rogiel.httpchannel.util.html.Page;
import com.rogiel.httpchannel.util.html.SearchResults;
/**
* This service handles login, upload and download to uptobox.com.
@@ -59,7 +60,7 @@ import com.rogiel.httpchannel.util.htmlparser.HTMLPage;
* @since 1.0
*/
public class UptoboxService extends AbstractHttpService implements Service,
UploadService<UptoboxConfiguration>,
UploadService<UptoboxUploaderConfiguration>,
AuthenticationService<NullAuthenticatorConfiguration> {
/**
* This service ID
@@ -97,20 +98,20 @@ public class UptoboxService extends AbstractHttpService implements Service,
}
@Override
public Uploader<UptoboxConfiguration> getUploader(String filename,
long filesize, UptoboxConfiguration configuration) {
public Uploader<UptoboxUploaderConfiguration> getUploader(String filename,
long filesize, UptoboxUploaderConfiguration configuration) {
return new UploaderImpl(filename, filesize, configuration);
}
@Override
public Uploader<UptoboxConfiguration> getUploader(String filename,
public Uploader<UptoboxUploaderConfiguration> getUploader(String filename,
long filesize) {
return getUploader(filename, filesize, newUploaderConfiguration());
}
@Override
public UptoboxConfiguration newUploaderConfiguration() {
return new UptoboxConfiguration();
public UptoboxUploaderConfiguration newUploaderConfiguration() {
return new UptoboxUploaderConfiguration();
}
@Override
@@ -164,28 +165,29 @@ public class UptoboxService extends AbstractHttpService implements Service,
return account;
}
protected class UploaderImpl extends AbstractUploader<UptoboxConfiguration>
implements Uploader<UptoboxConfiguration>,
protected class UploaderImpl extends
AbstractUploader<UptoboxUploaderConfiguration> implements
Uploader<UptoboxUploaderConfiguration>,
LinkedUploadChannelCloseCallback {
private Future<HTMLPage> uploadFuture;
private Future<Page> uploadFuture;
public UploaderImpl(String filename, long filesize,
UptoboxConfiguration configuration) {
UptoboxUploaderConfiguration configuration) {
super(UptoboxService.this, filename, filesize, configuration);
}
@Override
public UploadChannel openChannel() throws IOException {
logger.debug("Starting upload to ifile.it");
final HTMLPage page = get("http://uptobox.com/").asPage();
String action = page.findFormAction(UPLOAD_URI_PATTERN);
final String srvTmpUrl = page.getInputValue("srv_tmp_url");
logger.debug("Starting upload to uptobox.com");
final Page page = get("http://uptobox.com/").asPage();
String action = page.form(UPLOAD_URI_PATTERN).asString();
final String srvTmpUrl = page.inputByName("srv_tmp_url").asString();
if (account != null) {
action += "&type=reg";
}
final String sessionID = page.getInputValue("sess_id");
final String sessionID = page.inputByName("sess_id").asString();
logger.debug("Upload URI is {}", action);
@@ -202,7 +204,7 @@ public class UptoboxService extends AbstractHttpService implements Service,
@Override
public String finish() throws IOException {
try {
return uploadFuture.get().findLink(DOWNLOAD_URI_PATTERN);
return uploadFuture.get().link(DOWNLOAD_URI_PATTERN).asString();
} catch (InterruptedException e) {
return null;
} catch (ExecutionException e) {
@@ -221,37 +223,42 @@ public class UptoboxService extends AbstractHttpService implements Service,
@Override
public AccountDetails login() throws IOException {
final HTMLPage page = post("http://uptobox.com/")
final Page page = post("http://uptobox.com/")
.parameter("op", "login")
.parameter("redirect", "http://uptobox.com/?op=my_account")
.parameter("login", credential.getUsername())
.parameter("password", credential.getPassword()).asPage();
final String username = page.findPlain(
Pattern.compile("Username:(.+) Apply"), 1);
final SearchResults results = page.search(Pattern
.compile("Username:(.+) Apply"));
if (!results.hasResults())
throw new AuthenticationInvalidCredentialException();
final String username = results.asString(1);
if (username == null)
throw new AuthenticationInvalidCredentialException();
final boolean premium = !page.containsPlain(Pattern.compile(
"Account type Free member", Pattern.MULTILINE));
final int points = page.findIntPlain(
Pattern.compile("You have collected:([0-9])+"), 1);
final int referrals = page.findIntPlain(
Pattern.compile("My referrals:([0-9])+"), 1);
final String referralURL = page.findLink(Pattern
.compile("http://uptobox\\.com/affiliate/[0-9]+"));
final boolean premium = !page.search(
Pattern.compile("Account type Free member",
Pattern.MULTILINE)).hasResults();
final int points = page.search(
Pattern.compile("You have collected:([0-9])+"))
.asInteger(1);
final int referrals = page.search(
Pattern.compile("My referrals:([0-9])+")).asInteger(1);
final String referralURL = page.link(
Pattern.compile("http://uptobox\\.com/affiliate/[0-9]+"))
.asString();
final HTMLPage index = get("http://uptobox.com/").asPage();
final int maximumFileSize = index.findIntPlain(
Pattern.compile("Up to ([0-9]*) Mb"), 1);
final Page index = get("http://uptobox.com/").asPage();
final int maximumFileSize = index.search(
Pattern.compile("Up to ([0-9]*) Mb")).asInteger(1);
final HTMLPage disk = get("http://uptobox.com/?op=my_files")
.asPage();
final double usedDiskSpace = disk.findDoublePlain(
DISK_USAGE_PATTERN, 1);
final String usedDiskSpaceUnit = disk.findPlain(DISK_USAGE_PATTERN,
3);
final double maximumDiskSpace = disk.findDoublePlain(
DISK_USAGE_PATTERN, 4);
final Page disk = get("http://uptobox.com/?op=my_files").asPage();
final double usedDiskSpace = disk.search(DISK_USAGE_PATTERN)
.asDouble(1);
final String usedDiskSpaceUnit = disk.search(DISK_USAGE_PATTERN)
.asString(3);
final double maximumDiskSpace = disk.search(DISK_USAGE_PATTERN)
.asDouble(4);
return (account = new AccountDetailsImpl(username, premium,
Filesizes.mb(maximumFileSize),

View File

@@ -28,7 +28,7 @@ import com.rogiel.httpchannel.service.uptobox.UptoboxService.UploaderImpl;
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public class UptoboxConfiguration extends
public class UptoboxUploaderConfiguration extends
AbstractUploaderConfiguration implements UploaderConfiguration,
DescriptionableUploaderConfiguration {
/**
@@ -42,7 +42,7 @@ public class UptoboxConfiguration extends
}
@Override
public UptoboxConfiguration description(String description) {
public UptoboxUploaderConfiguration description(String description) {
this.description = description;
return this;
}