This commit is contained in:
tonikelope 2018-07-26 19:08:39 +02:00
parent a87d43fd85
commit c5abbe4467
6 changed files with 103 additions and 62 deletions

View File

@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>5.4</version>
<version>5.5</version>
<packaging>jar</packaging>
<dependencies>
<dependency>

View File

@ -103,17 +103,11 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
String worker_url = null, current_proxy = null;
boolean error = false, error509 = false;
boolean error = false, error509 = false, error403 = false;
while (!_exit && !_download.isStopped() && (error509 || conta_error < MAX_SLOT_ERROR || MainPanel.isUse_smart_proxy())) {
if (MainPanel.isUse_smart_proxy() && _proxy_manager == null) {
_proxy_manager = new SmartMegaProxyManager(MainPanel.getUse_smart_proxy_url());
}
if (worker_url == null || error) {
if (worker_url == null || error403) {
worker_url = _download.getDownloadUrlForWorker();
}
@ -124,9 +118,17 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
if (error509 && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
if (error && current_proxy != null) {
if (MainPanel.isUse_smart_proxy() && _proxy_manager == null) {
_proxy_manager = new SmartMegaProxyManager(null);
}
if (error && !error403 && current_proxy != null) {
_proxy_manager.blockProxy(current_proxy);
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
}
current_proxy = _proxy_manager.getFastestProxy();
@ -185,6 +187,8 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
error = false;
error403 = false;
error509 = false;
if (getDownload().isError509()) {
@ -195,25 +199,29 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
if (!_exit && !_download.isStopped()) {
try (InputStream is = new ThrottledInputStream(con.getInputStream(), _download.getMain_panel().getStream_supervisor())) {
int http_status = con.getResponseCode();
int http_status = con.getResponseCode();
if (http_status != 200) {
if (http_status != 200) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Failed : HTTP error code : {1}", new Object[]{Thread.currentThread().getName(), http_status});
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Failed : HTTP error code : {1}", new Object[]{Thread.currentThread().getName(), http_status});
error = true;
error = true;
if (http_status == 509) {
if (http_status == 509) {
error509 = true;
error509 = true;
if (MainPanel.isUse_smart_proxy()) {
getDownload().getView().set509Error(true);
}
if (MainPanel.isUse_smart_proxy()) {
getDownload().getView().set509Error(true);
}
} else if (http_status == 403) {
} else {
error403 = true;
}
} else {
try (InputStream is = new ThrottledInputStream(con.getInputStream(), _download.getMain_panel().getStream_supervisor())) {
byte[] buffer = new byte[DEFAULT_BYTE_BUFFER_SIZE];
@ -242,20 +250,19 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
secureWait();
}
}
}
}
if (chunk.getOutputStream().size() < chunk.getSize()) {
if (chunk.getOutputStream().size() > 0) {
_download.getPartialProgressQueue().add(-1 * chunk.getOutputStream().size());
_download.getProgress_meter().secureNotify();
}
if (chunk.getOutputStream().size() < chunk.getSize()) {
if (chunk.getOutputStream().size() > 0) {
_download.getPartialProgressQueue().add(-1 * chunk.getOutputStream().size());
_download.getProgress_meter().secureNotify();
}
error = true;
}
error = true;
}
if (error && !_download.isStopped()) {

View File

@ -32,7 +32,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
String worker_url = null;
int conta_error = 0, http_status = 200;
boolean error = false, error509 = false;
boolean error = false, error509 = false, error403 = false;
getDownload().getView().set509Error(false);
@ -40,7 +40,7 @@ public class ChunkDownloaderMono extends ChunkDownloader {
while (!isExit() && !getDownload().isStopped() && (error509 || conta_error < MAX_SLOT_ERROR)) {
if (worker_url == null || error) {
if (worker_url == null || error403) {
worker_url = getDownload().getDownloadUrlForWorker();
}
@ -79,13 +79,14 @@ public class ChunkDownloaderMono extends ChunkDownloader {
error = false;
if (error509) {
getDownload().getView().set509Error(false);
}
error403 = false;
error509 = false;
if (getDownload().isError509()) {
getDownload().getView().set509Error(false);
}
if (http_status != 200) {
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Failed : HTTP error code : {1}", new Object[]{Thread.currentThread().getName(), http_status});
@ -97,6 +98,8 @@ public class ChunkDownloaderMono extends ChunkDownloader {
error509 = true;
getDownload().getView().set509Error(true);
} else if (http_status == 403) {
error403 = true;
}
getDownload().rejectChunkId(chunk.getId());

View File

@ -47,7 +47,7 @@ import java.io.File;
*/
public final class MainPanel {
public static final String VERSION = "5.4";
public static final String VERSION = "5.5";
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
public static final int STREAMER_PORT = 1337;

View File

@ -735,10 +735,14 @@ public final class MiscTools {
public static boolean checkMegaDownloadUrl(String string_url) {
boolean url_ok = false, error509 = false;
boolean url_ok = false;
HttpURLConnection con = null;
boolean error = false, error509 = false, error403 = false;
SmartMegaProxyManager proxy_manager = null;
String current_proxy = null;
do {
@ -747,18 +751,24 @@ public final class MiscTools {
URL url = new URL(string_url + "/0-0");
if (con == null || !url_ok) {
if (con == null || error) {
if (error509 && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
if (current_proxy != null) {
if (MainPanel.isUse_smart_proxy() && proxy_manager == null) {
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
proxy_manager = MainPanel.getProxy_manager();
MainPanel.getProxy_manager().blockProxy(current_proxy);
}
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
if (error && !error403 && current_proxy != null) {
proxy_manager.blockProxy(current_proxy);
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
}
current_proxy = proxy_manager.getFastestProxy();
if (current_proxy != null) {
@ -770,11 +780,21 @@ public final class MiscTools {
} else {
con = (HttpURLConnection) url.openConnection();
if (MainPanel.isUse_proxy()) {
con = (HttpURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(MainPanel.getProxy_host(), MainPanel.getProxy_port())));
if (MainPanel.getProxy_user() != null && !"".equals(MainPanel.getProxy_user())) {
con.setRequestProperty("Proxy-Authorization", "Basic " + MiscTools.Bin2BASE64((MainPanel.getProxy_user() + ":" + MainPanel.getProxy_pass()).getBytes()));
}
} else {
con = (HttpURLConnection) url.openConnection();
}
}
}
{
} else {
if (MainPanel.isUse_proxy()) {
@ -789,31 +809,33 @@ public final class MiscTools {
con = (HttpURLConnection) url.openConnection();
}
}
}
error509 = false;
con.setConnectTimeout(Transference.HTTP_TIMEOUT);
try {
con.setReadTimeout(Transference.HTTP_TIMEOUT);
url_ok = (con.getResponseCode() == 200);
con.setRequestProperty("User-Agent", MainPanel.DEFAULT_USER_AGENT);
error509 = (con.getResponseCode() == 509);
int http_status = con.getResponseCode();
if (http_status != 403) {
url_ok = true;
} catch (IOException ex) {
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
}
} catch (Exception ex) {
} catch (IOException ex) {
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if (con != null) {
con.disconnect();
con = null;
}
}
} while (error509 && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy());
} while (error509);
return url_ok;
}

View File

@ -44,7 +44,7 @@ public class StreamChunkDownloader implements Runnable {
String url = _chunkwriter.getUrl();
boolean error = false, error509 = false;
boolean error = false, error509 = false, error403 = false;
String current_proxy = null;
@ -69,7 +69,7 @@ public class StreamChunkDownloader implements Runnable {
offset = _chunkwriter.nextOffset();
} else {
} else if (error403) {
url = _chunkwriter.getUrl();
}
@ -141,12 +141,12 @@ public class StreamChunkDownloader implements Runnable {
error509 = false;
error403 = false;
try {
if (!_exit) {
InputStream is = con.getInputStream();
http_status = con.getResponseCode();
if (http_status != 200) {
@ -155,10 +155,19 @@ public class StreamChunkDownloader implements Runnable {
error = true;
error509 = (http_status == 509);
if (http_status == 509) {
error509 = true;
} else if (http_status == 403) {
error403 = true;
}
} else {
InputStream is = con.getInputStream();
while (!_exit && !_chunkwriter.isExit() && (reads = is.read(buffer)) != -1) {
chunk_stream.getOutputStream().write(buffer, 0, reads);