mirror of
https://github.com/Rogiel/httpchannel
synced 2025-12-06 07:32:50 +00:00
Adds -SNAPSHOT to Maven version parameter and few modifications to API
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
<parent>
|
||||
<artifactId>httpchannel-service</artifactId>
|
||||
<groupId>com.rogiel.httpchannel</groupId>
|
||||
<version>1.0.0</version>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<relativePath>..</relativePath>
|
||||
</parent>
|
||||
<artifactId>httpchannel-service-uploadhere</artifactId>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.rogiel.httpchannel.service.impl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.regex.Pattern;
|
||||
@@ -54,21 +54,21 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
*/
|
||||
public static final ServiceID SERVICE_ID = ServiceID.create("uploadhere");
|
||||
|
||||
private static final Pattern UPLOAD_URL_PATTERN = Pattern
|
||||
private static final Pattern UPLOAD_URI_PATTERN = Pattern
|
||||
.compile("http://www([0-9]*)\\.uploadhere\\.com/upload/\\?UPLOAD_IDENTIFIER=[0-9]*");
|
||||
private static final Pattern DOWNLOAD_ID_PATTERN = Pattern
|
||||
.compile("\"downloadid\":\"([0-9a-zA-Z]*)\"");
|
||||
private static final Pattern DOWNLOAD_URL_PATTERN = Pattern
|
||||
private static final Pattern DOWNLOAD_URI_PATTERN = Pattern
|
||||
.compile("http://(www\\.)?uploadhere.\\com/[0-9A-z]*");
|
||||
private static final Pattern TIMER_PATTERN = Pattern.compile(
|
||||
"count = ([0-9]*);", Pattern.COMMENTS);
|
||||
private static final Pattern DIERCT_DOWNLOAD_URL_PATTERN = Pattern
|
||||
private static final Pattern DIERCT_DOWNLOAD_URI_PATTERN = Pattern
|
||||
.compile("(http:\\\\/\\\\/www[0-9]*\\.uploadhere\\.com(:[0-9]*)?\\\\/files\\\\/([0-9A-z]*)\\\\/(.*))\"");
|
||||
|
||||
private static final String INVALID_LOGIN_STRING = "Incorrect username and/or password. Please try again!";
|
||||
|
||||
@Override
|
||||
public ServiceID getID() {
|
||||
public ServiceID getServiceID() {
|
||||
return SERVICE_ID;
|
||||
}
|
||||
|
||||
@@ -118,14 +118,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
}
|
||||
|
||||
@Override
|
||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url,
|
||||
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri,
|
||||
NullDownloaderConfiguration configuration) {
|
||||
return new DownloaderImpl(url, configuration);
|
||||
return new DownloaderImpl(uri, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Downloader<NullDownloaderConfiguration> getDownloader(URL url) {
|
||||
return getDownloader(url, newDownloaderConfiguration());
|
||||
public Downloader<NullDownloaderConfiguration> getDownloader(URI uri) {
|
||||
return getDownloader(uri, newDownloaderConfiguration());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -134,8 +134,8 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matchURL(URL url) {
|
||||
return DOWNLOAD_URL_PATTERN.matcher(url.toString()).matches();
|
||||
public boolean matchURI(URI uri) {
|
||||
return DOWNLOAD_URI_PATTERN.matcher(uri.toString()).matches();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -185,14 +185,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
final HTMLPage page = get("http://www.uploadhere.com/").asPage();
|
||||
|
||||
final String userCookie = page.getInputValueById("usercookie");
|
||||
final String url = page.findFormAction(UPLOAD_URL_PATTERN);
|
||||
final String uri = page.findFormAction(UPLOAD_URI_PATTERN);
|
||||
final String uploadID = page.getInputValue("UPLOAD_IDENTIFIER");
|
||||
|
||||
logger.debug("Upload URL: {}, UserCookie: {}, UploadID: {}",
|
||||
new Object[] { url, userCookie, uploadID });
|
||||
logger.debug("Upload URI: {}, UserCookie: {}, UploadID: {}",
|
||||
new Object[] { uri, userCookie, uploadID });
|
||||
|
||||
final LinkedUploadChannel channel = createLinkedChannel(this);
|
||||
uploadFuture = multipartPost(url).parameter("file_0", channel)
|
||||
uploadFuture = multipartPost(uri).parameter("file_0", channel)
|
||||
.parameter("u", userCookie)
|
||||
.parameter("UPLOAD_IDENTIFIER", uploadID).asStringAsync();
|
||||
return waitChannelLink(channel, uploadFuture);
|
||||
@@ -222,14 +222,14 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
protected class DownloaderImpl extends
|
||||
AbstractHttpDownloader<NullDownloaderConfiguration> implements
|
||||
Downloader<NullDownloaderConfiguration> {
|
||||
public DownloaderImpl(URL url, NullDownloaderConfiguration configuration) {
|
||||
super(url, configuration);
|
||||
public DownloaderImpl(URI uri, NullDownloaderConfiguration configuration) {
|
||||
super(uri, configuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DownloadChannel openChannel(DownloadListener listener,
|
||||
long position) throws IOException {
|
||||
HTMLPage page = get(url).asPage();
|
||||
HTMLPage page = get(uri).asPage();
|
||||
|
||||
final int waitTime = page.findScriptAsInt(TIMER_PATTERN, 1) * 1000;
|
||||
logger.debug("Wait time is {}", waitTime);
|
||||
@@ -251,12 +251,12 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
logger.debug("CAPTCHA solving took longer than timer, skipping it");
|
||||
}
|
||||
|
||||
String content = post(url)
|
||||
String content = post(uri)
|
||||
.parameter("recaptcha_challenge_field", captcha.getID())
|
||||
.parameter("recaptcha_response_field",
|
||||
captcha.getAnswer()).asString();
|
||||
String downloadLink = PatternUtils.find(
|
||||
DIERCT_DOWNLOAD_URL_PATTERN, content, 1);
|
||||
DIERCT_DOWNLOAD_URI_PATTERN, content, 1);
|
||||
if (downloadLink == null) {
|
||||
captchaService.invalid(captcha);
|
||||
throw new InvalidCaptchaException();
|
||||
@@ -265,7 +265,7 @@ public class UploadHereService extends AbstractHttpService implements Service,
|
||||
}
|
||||
downloadLink = downloadLink.replaceAll(Pattern.quote("\\/"),
|
||||
"/");
|
||||
logger.debug("Direct download URL is {}", downloadLink);
|
||||
logger.debug("Direct download URI is {}", downloadLink);
|
||||
return download(get(downloadLink).position(position));
|
||||
}
|
||||
throw new DownloadLinkNotFoundException();
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.rogiel.httpchannel.service.impl;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URI;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
@@ -31,10 +31,10 @@ public class UploadHereServiceTest {
|
||||
UploaderCapability.UNAUTHENTICATED_UPLOAD));
|
||||
|
||||
final Path path = Paths.get("src/test/resources/upload-test-file.txt");
|
||||
final URL url = ChannelUtils.upload(service, path);
|
||||
final URI uri = ChannelUtils.upload(service, path);
|
||||
|
||||
Assert.assertNotNull(url);
|
||||
System.out.println(url);
|
||||
Assert.assertNotNull(uri);
|
||||
System.out.println(uri);
|
||||
}
|
||||
|
||||
// @Test
|
||||
@@ -43,7 +43,7 @@ public class UploadHereServiceTest {
|
||||
// @Override
|
||||
// public boolean resolve(Captcha rawCaptcha) {
|
||||
// final ImageCaptcha captcha = (ImageCaptcha) rawCaptcha;
|
||||
// System.out.println(captcha.getImageURL());
|
||||
// System.out.println(captcha.getImageURI());
|
||||
// try {
|
||||
// captcha.setAnswer(new BufferedReader(new InputStreamReader(
|
||||
// System.in)).readLine());
|
||||
@@ -56,7 +56,7 @@ public class UploadHereServiceTest {
|
||||
// });
|
||||
//
|
||||
// final DownloadChannel channel = service.getDownloader(
|
||||
// new URL("http://www.uploadhere.com/9WCEQF1Q07")).openChannel();
|
||||
// new URI("http://www.uploadhere.com/9WCEQF1Q07")).openChannel();
|
||||
// System.out.println(new String(ChannelUtils.toByteArray(channel)));
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user