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

Adds -SNAPSHOT to Maven version parameter and few modifications to API

This commit is contained in:
2012-01-17 17:07:48 -02:00
parent 08d22a12fe
commit 673bfc6639
56 changed files with 536 additions and 399 deletions

View File

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

View File

@@ -1,7 +1,7 @@
package com.rogiel.httpchannel.service.impl;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
@@ -54,21 +54,21 @@ public class UploadKingService extends AbstractHttpService implements Service,
*/
public static final ServiceID SERVICE_ID = ServiceID.create("uploadking");
private static final Pattern UPLOAD_URL_PATTERN = Pattern
private static final Pattern UPLOAD_URI_PATTERN = Pattern
.compile("http://www([0-9]*)\\.uploadking\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
.compile("http://(www\\.)?uploadking.\\com/[0-9A-z]*");
private static final Pattern TIMER_PATTERN = Pattern.compile(
"count = ([0-9]*);", Pattern.COMMENTS);
private static final Pattern DIERCT_DOWNLOAD_URL_PATTERN = Pattern
private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
.compile("(http:\\\\/\\\\/www[0-9]*\\.uploadking\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
@Override
public ServiceID getID() {
public ServiceID getServiceID() {
return SERVICE_ID;
}
@@ -118,14 +118,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
NullDownloaderConfiguration configuration) {
return new DownloaderImpl(url, configuration);
return new DownloaderImpl(uri, configuration);
}
@Override
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
return getDownloader(url, newDownloaderConfiguration());
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
return getDownloader(uri, newDownloaderConfiguration());
}
@Override
@@ -134,8 +134,8 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
@Override
public boolean matchURL(URL url) {
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
public boolean matchURI(URI uri) {
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
}
@Override
@@ -185,14 +185,14 @@ public class UploadKingService extends AbstractHttpService implements Service,
final HTMLPage page = get("http://www.uploadking.com/").asPage();
final String userCookie = page.getInputValueById("usercookie");
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
new Object[] { url, userCookie, uploadID });
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
new Object[] { uri, userCookie, uploadID });
final LinkedUploadChannel channel = createLinkedChannel(this);
uploadFuture = multipartPost(url).parameter("file", channel)
uploadFuture = multipartPost(uri).parameter("file", channel)
.parameter("u", userCookie)
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
return waitChannelLink(channel, uploadFuture);
@@ -219,15 +219,15 @@ public class UploadKingService extends AbstractHttpService implements Service,
protected class DownloaderImpl extends
AbstractHttpDownloader<NullDownloaderConfiguration> implements
Downloader<NullDownloaderConfiguration> {
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
super(url, configuration);
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
super(uri, configuration);
}
@Override
public DownloadChannel openChannel(DownloadListener listener,
long position) throws IOException {
logger.debug("Downloading {} with uploadking.com");
HTMLPage page = get(url).asPage();
HTMLPage page = get(uri).asPage();
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
logger.debug("Wait time is {}", waitTime);
@@ -250,12 +250,12 @@ public class UploadKingService extends AbstractHttpService implements Service,
logger.debug("CAPTCHA solving took longer than timer, skipping it");
}
String content = post(url)
String content = post(uri)
.parameter("recaptcha_challenge_field", captcha.getID())
.parameter("recaptcha_response_field",
captcha.getAnswer()).asString();
String downloadLink = PatternUtils.find(
DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
if (downloadLink == null) {
captchaService.invalid(captcha);
throw new InvalidCaptchaException();
@@ -264,7 +264,7 @@ public class UploadKingService extends AbstractHttpService implements Service,
}
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
"/");
logger.debug("Direct download URL is {}", downloadLink);
logger.debug("Direct download URI is {}", downloadLink);
return download(get(downloadLink).position(position));
}
throw new DownloadLinkNotFoundException();

View File

@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -37,10 +37,10 @@ public class UploadKingServiceTest {
UploaderCapability.UNAUTHENTICATED_UPLOAD));
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
final URL url = ChannelUtils.upload(service, path);
final URI uri = ChannelUtils.upload(service, path);
Assert.assertNotNull(url);
System.out.println(url);
Assert.assertNotNull(uri);
System.out.println(uri);
}
@Test
@@ -55,7 +55,8 @@ public class UploadKingServiceTest {
service.setCaptchaService(s);
final DownloadChannel channel = service.getDownloader(
new URL("http://www.uploadking.com/WM3PHD9JAY")).openChannel(0);
URI.create("http://www.uploadking.com/WM3PHD9JAY"))
.openChannel(0);
System.out.println(new String(ChannelUtils.toByteArray(channel)));
}
}