mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-05-21 16:57:11 +02:00
3.4
This commit is contained in:
parent
0275115f3e
commit
e4835277ec
2
pom.xml
2
pom.xml
@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.tonikelope</groupId>
|
||||
<artifactId>MegaBasterd</artifactId>
|
||||
<version>3.3</version>
|
||||
<version>3.4</version>
|
||||
<packaging>jar</packaging>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -102,24 +102,11 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
||||
String worker_url = null, current_proxy = null;;
|
||||
boolean error = false, error509 = false;
|
||||
|
||||
while (!_exit && !_download.isStopped() && (error509 || conta_error < MAX_SLOT_ERROR || _download.getMain_panel().isUse_smart_proxy())) {
|
||||
while (!_exit && !_download.isStopped() && (error509 || conta_error < MAX_SLOT_ERROR || MainPanel.isUse_smart_proxy())) {
|
||||
|
||||
if (httpclient == null || error || _download.getMain_panel().isUse_smart_proxy()) {
|
||||
if (httpclient == null || error) {
|
||||
|
||||
if (error509 && _download.getMain_panel().isUse_smart_proxy() && !_download.getMain_panel().getProxy_manager().isEnabled()) {
|
||||
_download.getMain_panel().getProxy_manager().setEnabled(true);
|
||||
}
|
||||
|
||||
if (_download.getMain_panel().isUse_smart_proxy() && _download.getMain_panel().getProxy_manager().isEnabled() && !MainPanel.isUse_proxy()) {
|
||||
|
||||
if (error && current_proxy != null) {
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker [{1}]: excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_proxy});
|
||||
|
||||
_download.getMain_panel().getProxy_manager().excludeProxy(current_proxy);
|
||||
}
|
||||
|
||||
current_proxy = _download.getMain_panel().getProxy_manager().getRandomProxy();
|
||||
if (error509 && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
|
||||
|
||||
if (httpclient != null) {
|
||||
try {
|
||||
@ -129,19 +116,30 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
||||
}
|
||||
}
|
||||
|
||||
if (error && current_proxy != null) {
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker [{1}]: excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_proxy});
|
||||
|
||||
MainPanel.getProxy_manager().excludeProxy(current_proxy);
|
||||
}
|
||||
|
||||
current_proxy = MainPanel.getProxy_manager().getRandomProxy();
|
||||
|
||||
if (current_proxy != null) {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClientSmartProxy(current_proxy);
|
||||
getDownload().getMain_panel().getView().setSmartProxy(true);
|
||||
|
||||
} else {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClient();
|
||||
_download.getMain_panel().getProxy_manager().setEnabled(false);
|
||||
getDownload().getMain_panel().getView().setSmartProxy(false);
|
||||
}
|
||||
|
||||
} else if (httpclient == null) {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClient();
|
||||
getDownload().getMain_panel().getView().setSmartProxy(false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -156,12 +154,12 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
||||
|
||||
error = false;
|
||||
|
||||
if (error509) {
|
||||
error509 = false;
|
||||
|
||||
if (getDownload().isError509()) {
|
||||
getDownload().getView().set509Error(false);
|
||||
}
|
||||
|
||||
error509 = false;
|
||||
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
|
||||
if (!_exit && !_download.isStopped()) {
|
||||
@ -179,7 +177,10 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
||||
|
||||
error509 = true;
|
||||
|
||||
getDownload().getView().set509Error(true);
|
||||
if (MainPanel.isUse_smart_proxy()) {
|
||||
getDownload().getView().set509Error(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -239,7 +240,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
||||
|
||||
_download.getView().updateSlotsStatus();
|
||||
|
||||
if (!_download.getMain_panel().isUse_smart_proxy()) {
|
||||
if (!MainPanel.isUse_smart_proxy()) {
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
|
||||
}
|
||||
|
||||
@ -285,7 +286,7 @@ public class ChunkDownloader implements Runnable, SecureSingleThreadNotifiable {
|
||||
|
||||
_download.getView().updateSlotsStatus();
|
||||
|
||||
if (!_download.getMain_panel().isUse_smart_proxy()) {
|
||||
if (!MainPanel.isUse_smart_proxy()) {
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error) * 1000);
|
||||
}
|
||||
|
||||
|
@ -380,7 +380,7 @@ public final class LinkGrabberDialog extends javax.swing.JDialog implements Clip
|
||||
|
||||
private void use_mega_account_down_comboboxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_use_mega_account_down_comboboxItemStateChanged
|
||||
|
||||
if (_selected_item == null || !((String) use_mega_account_down_combobox.getSelectedItem()).equals(_selected_item)) {
|
||||
if (_selected_item == null || !use_mega_account_down_combobox.getSelectedItem().equals(_selected_item)) {
|
||||
_selected_item = (String) use_mega_account_down_combobox.getSelectedItem();
|
||||
|
||||
if (_main_panel.isUse_mega_account_down() && !"".equals(_selected_item)) {
|
||||
|
@ -48,7 +48,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
*/
|
||||
public final class MainPanel {
|
||||
|
||||
public static final String VERSION = "3.3";
|
||||
public static final String VERSION = "3.4";
|
||||
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;
|
||||
@ -63,6 +63,9 @@ public final class MainPanel {
|
||||
private static int _proxy_port;
|
||||
private static Credentials _proxy_credentials;
|
||||
private static boolean _use_proxy;
|
||||
private static boolean _use_smart_proxy;
|
||||
private static String _smart_proxy_url;
|
||||
private static SmartMegaProxyManager _proxy_manager;
|
||||
|
||||
public static void main(String args[]) {
|
||||
|
||||
@ -88,9 +91,6 @@ public final class MainPanel {
|
||||
});
|
||||
}
|
||||
|
||||
private volatile boolean _use_smart_proxy;
|
||||
private volatile String _use_smart_proxy_url;
|
||||
private volatile SmartMegaProxyManager _proxy_manager;
|
||||
private volatile MainPanelView _view;
|
||||
private final GlobalSpeedMeter _global_dl_speed, _global_up_speed;
|
||||
private final DownloadManager _download_manager;
|
||||
@ -138,7 +138,7 @@ public final class MainPanel {
|
||||
|
||||
_use_smart_proxy = false;
|
||||
|
||||
_use_smart_proxy_url = null;
|
||||
_smart_proxy_url = null;
|
||||
|
||||
try {
|
||||
|
||||
@ -211,7 +211,7 @@ public final class MainPanel {
|
||||
|
||||
if (_use_smart_proxy) {
|
||||
|
||||
_proxy_manager = new SmartMegaProxyManager(this, _use_smart_proxy_url);
|
||||
_proxy_manager = new SmartMegaProxyManager(this, _smart_proxy_url);
|
||||
|
||||
THREAD_POOL.execute(_proxy_manager);
|
||||
}
|
||||
@ -243,8 +243,8 @@ public final class MainPanel {
|
||||
return _zoom_factor;
|
||||
}
|
||||
|
||||
public void setProxy_manager(SmartMegaProxyManager _proxy_manager) {
|
||||
this._proxy_manager = _proxy_manager;
|
||||
public void setProxy_manager(SmartMegaProxyManager proxy_manager) {
|
||||
_proxy_manager = proxy_manager;
|
||||
}
|
||||
|
||||
public static String getProxy_host() {
|
||||
@ -263,15 +263,15 @@ public final class MainPanel {
|
||||
return _use_proxy;
|
||||
}
|
||||
|
||||
public boolean isUse_smart_proxy() {
|
||||
public static boolean isUse_smart_proxy() {
|
||||
return _use_smart_proxy;
|
||||
}
|
||||
|
||||
public String getUse_smart_proxy_url() {
|
||||
return _use_smart_proxy_url;
|
||||
public static String getUse_smart_proxy_url() {
|
||||
return _smart_proxy_url;
|
||||
}
|
||||
|
||||
public SmartMegaProxyManager getProxy_manager() {
|
||||
public static SmartMegaProxyManager getProxy_manager() {
|
||||
return _proxy_manager;
|
||||
}
|
||||
|
||||
@ -633,7 +633,7 @@ public final class MainPanel {
|
||||
|
||||
if (_use_smart_proxy) {
|
||||
|
||||
_use_smart_proxy_url = selectSettingValue("smart_proxy_url");
|
||||
_smart_proxy_url = selectSettingValue("smart_proxy_url");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,7 @@ import javax.swing.JTabbedPane;
|
||||
public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
private final MainPanel _main_panel;
|
||||
private volatile boolean _smart_proxy;
|
||||
|
||||
public JLabel getKiss_server_status() {
|
||||
return kiss_server_status;
|
||||
@ -167,10 +168,35 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
|
||||
}
|
||||
|
||||
public void setSmartProxy(boolean enabled) {
|
||||
|
||||
if (_smart_proxy != enabled) {
|
||||
swingInvoke(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (!_main_panel.isLimit_download_speed()) {
|
||||
_smart_proxy = enabled;
|
||||
|
||||
if (enabled) {
|
||||
getGlobal_speed_down_label().setForeground(Color.BLACK);
|
||||
} else {
|
||||
getGlobal_speed_down_label().setForeground(new Color(0, 128, 255));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public MainPanelView(MainPanel main_panel) {
|
||||
|
||||
_main_panel = main_panel;
|
||||
|
||||
_smart_proxy = false;
|
||||
|
||||
initComponents();
|
||||
|
||||
updateFonts(getRootPane(), DEFAULT_FONT, _main_panel.getZoom_factor());
|
||||
@ -812,24 +838,24 @@ public final class MainPanelView extends javax.swing.JFrame {
|
||||
_main_panel.setMega_proxy_server(null);
|
||||
}
|
||||
|
||||
if (this.getMain_panel().isUse_smart_proxy()) {
|
||||
if (MainPanel.isUse_smart_proxy()) {
|
||||
|
||||
if (this.getMain_panel().getProxy_manager() == null) {
|
||||
if (MainPanel.getProxy_manager() == null) {
|
||||
|
||||
this.getMain_panel().setProxy_manager(new SmartMegaProxyManager(this.getMain_panel(), this.getMain_panel().getUse_smart_proxy_url()));
|
||||
this.getMain_panel().setProxy_manager(new SmartMegaProxyManager(this.getMain_panel(), MainPanel.getUse_smart_proxy_url()));
|
||||
|
||||
THREAD_POOL.execute(this.getMain_panel().getProxy_manager());
|
||||
THREAD_POOL.execute(MainPanel.getProxy_manager());
|
||||
|
||||
} else if (!this.getMain_panel().getProxy_manager().getProxy_list_url().equals(this.getMain_panel().getUse_smart_proxy_url())) {
|
||||
this.getMain_panel().getProxy_manager().setProxy_list_url(this.getMain_panel().getUse_smart_proxy_url());
|
||||
} else if (!MainPanel.getProxy_manager().getProxy_list_url().equals(MainPanel.getUse_smart_proxy_url())) {
|
||||
MainPanel.getProxy_manager().setProxy_list_url(MainPanel.getUse_smart_proxy_url());
|
||||
}
|
||||
|
||||
} else if (this.getMain_panel().getProxy_manager() != null) {
|
||||
} else if (MainPanel.getProxy_manager() != null) {
|
||||
|
||||
this.getMain_panel().getProxy_manager().setExit(true);
|
||||
MainPanel.getProxy_manager().setExit(true);
|
||||
|
||||
synchronized (this.getMain_panel().getProxy_manager().getRefresh_lock()) {
|
||||
this.getMain_panel().getProxy_manager().getRefresh_lock().notify();
|
||||
synchronized (MainPanel.getProxy_manager().getRefresh_lock()) {
|
||||
MainPanel.getProxy_manager().getRefresh_lock().notify();
|
||||
}
|
||||
|
||||
this.getMain_panel().setProxy_manager(null);
|
||||
|
@ -33,7 +33,7 @@ public final class MegaAPI {
|
||||
public static final String API_URL = "https://g.api.mega.co.nz";
|
||||
public static final String API_KEY = null;
|
||||
public static final int REQ_ID_LENGTH = 10;
|
||||
public static final Integer[] MEGA_ERROR_EXCEPTION_CODES = {-2, -8, -9, -10, -11, -12, -13, -14, -15, -16, -17};
|
||||
public static final Integer[] MEGA_ERROR_EXCEPTION_CODES = {-2, -8, -9, -10, -11, -12, -13, -14, -15, -16};
|
||||
|
||||
public static int checkMEGAError(String data) {
|
||||
String error = findFirstRegex("^\\[?(\\-[0-9]+)\\]?$", data, 1);
|
||||
@ -282,91 +282,137 @@ public final class MegaAPI {
|
||||
private String _rawRequest(String request, URL url_api) throws IOException, MegaAPIException {
|
||||
|
||||
String response = null;
|
||||
CloseableHttpClient httpclient = null;
|
||||
boolean error509 = false;
|
||||
String current_proxy = null;
|
||||
int error = 0, conta_error = 0;
|
||||
HttpPost httppost;
|
||||
|
||||
try (CloseableHttpClient httpclient = getApacheKissHttpClient()) {
|
||||
do {
|
||||
|
||||
int error, conta_error = 0;
|
||||
try {
|
||||
|
||||
HttpPost httppost;
|
||||
if (httpclient == null || (error509 && MainPanel.isUse_smart_proxy())) {
|
||||
|
||||
do {
|
||||
error = 0;
|
||||
if (error509 && !MainPanel.isUse_proxy()) {
|
||||
|
||||
try {
|
||||
|
||||
httppost = new HttpPost(url_api.toURI());
|
||||
|
||||
httppost.setHeader("Content-type", "application/json");
|
||||
|
||||
httppost.setEntity(new StringEntity(request));
|
||||
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httppost)) {
|
||||
|
||||
if (httpresponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} {1} {2}", new Object[]{Thread.currentThread().getName(), request, url_api.toString()});
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Failed : HTTP error code : {1}", new Object[]{Thread.currentThread().getName(), httpresponse.getStatusLine().getStatusCode()});
|
||||
|
||||
if (httpresponse.getStatusLine().getStatusCode() == 509) {
|
||||
|
||||
error = -17;
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
InputStream is = httpresponse.getEntity().getContent();
|
||||
|
||||
try (ByteArrayOutputStream byte_res = new ByteArrayOutputStream()) {
|
||||
|
||||
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
|
||||
|
||||
int reads;
|
||||
|
||||
while ((reads = is.read(buffer)) != -1) {
|
||||
|
||||
byte_res.write(buffer, 0, reads);
|
||||
}
|
||||
|
||||
response = new String(byte_res.toByteArray());
|
||||
|
||||
if (response.length() > 0) {
|
||||
|
||||
error = checkMEGAError(response);
|
||||
|
||||
}
|
||||
if (httpclient != null) {
|
||||
|
||||
try {
|
||||
httpclient.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (current_proxy != null) {
|
||||
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
|
||||
|
||||
MainPanel.getProxy_manager().excludeProxy(current_proxy);
|
||||
}
|
||||
|
||||
current_proxy = MainPanel.getProxy_manager().getRandomProxy();
|
||||
|
||||
if (current_proxy != null) {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClientSmartProxy(current_proxy);
|
||||
|
||||
} else {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClient();
|
||||
}
|
||||
|
||||
} else if (httpclient == null) {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClient();
|
||||
}
|
||||
}
|
||||
|
||||
error = 0;
|
||||
|
||||
error509 = false;
|
||||
|
||||
httppost = new HttpPost(url_api.toURI());
|
||||
|
||||
httppost.setHeader("Content-type", "application/json");
|
||||
|
||||
httppost.setEntity(new StringEntity(request));
|
||||
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httppost)) {
|
||||
|
||||
if (httpresponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} {1} {2}", new Object[]{Thread.currentThread().getName(), request, url_api.toString()});
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Failed : HTTP error code : {1}", new Object[]{Thread.currentThread().getName(), httpresponse.getStatusLine().getStatusCode()});
|
||||
|
||||
error509 = (httpresponse.getStatusLine().getStatusCode() == 509);;
|
||||
|
||||
} else {
|
||||
|
||||
InputStream is = httpresponse.getEntity().getContent();
|
||||
|
||||
try (ByteArrayOutputStream byte_res = new ByteArrayOutputStream()) {
|
||||
|
||||
byte[] buffer = new byte[MainPanel.DEFAULT_BYTE_BUFFER_SIZE];
|
||||
|
||||
int reads;
|
||||
|
||||
while ((reads = is.read(buffer)) != -1) {
|
||||
|
||||
byte_res.write(buffer, 0, reads);
|
||||
}
|
||||
|
||||
response = new String(byte_res.toByteArray());
|
||||
|
||||
if (response.length() > 0) {
|
||||
|
||||
error = checkMEGAError(response);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
} catch (URISyntaxException ex) {
|
||||
}
|
||||
|
||||
} catch (URISyntaxException ex) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} finally {
|
||||
|
||||
if (httpclient != null) {
|
||||
try {
|
||||
httpclient.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (error != 0 && !error509) {
|
||||
|
||||
if (Arrays.asList(MEGA_ERROR_EXCEPTION_CODES).contains(error)) {
|
||||
|
||||
throw new MegaAPIException(error);
|
||||
}
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} MegaAPI ERROR {1} Waiting for retry...", new Object[]{Thread.currentThread().getName(), String.valueOf(error)});
|
||||
|
||||
try {
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error++) * 1000);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
if (error != 0) {
|
||||
} else if (error == 0) {
|
||||
|
||||
if (Arrays.asList(MEGA_ERROR_EXCEPTION_CODES).contains(error)) {
|
||||
conta_error = 0;
|
||||
}
|
||||
|
||||
throw new MegaAPIException(error);
|
||||
}
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} MegaAPI ERROR {1} Waiting for retry...", new Object[]{Thread.currentThread().getName(), String.valueOf(error)});
|
||||
|
||||
try {
|
||||
Thread.sleep(getWaitTimeExpBackOff(conta_error++) * 1000);
|
||||
} catch (InterruptedException ex) {
|
||||
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
conta_error = 0;
|
||||
}
|
||||
|
||||
} while (error != 0);
|
||||
}
|
||||
} while (error != 0 || (error509 && MainPanel.isUse_smart_proxy()));
|
||||
|
||||
_seqno++;
|
||||
|
||||
|
@ -793,23 +793,81 @@ public final class MiscTools {
|
||||
|
||||
public static boolean checkMegaDownloadUrl(String string_url) {
|
||||
|
||||
boolean url_ok = false;
|
||||
boolean url_ok = false, error509 = false;
|
||||
|
||||
try (CloseableHttpClient httpclient = getApacheKissHttpClient()) {
|
||||
CloseableHttpClient httpclient = null;
|
||||
|
||||
HttpGet httpget = new HttpGet(new URI(string_url + "/0-0"));
|
||||
String current_proxy = null;
|
||||
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
do {
|
||||
|
||||
url_ok = (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK);
|
||||
try {
|
||||
|
||||
if (httpclient == null || !url_ok) {
|
||||
|
||||
if (error509 && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
|
||||
|
||||
if (httpclient != null) {
|
||||
|
||||
try {
|
||||
httpclient.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
if (current_proxy != null) {
|
||||
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.WARNING, "{0}: excluding proxy -> {1}", new Object[]{Thread.currentThread().getName(), current_proxy});
|
||||
|
||||
MainPanel.getProxy_manager().excludeProxy(current_proxy);
|
||||
}
|
||||
|
||||
current_proxy = MainPanel.getProxy_manager().getRandomProxy();
|
||||
|
||||
if (current_proxy != null) {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClientSmartProxy(current_proxy);
|
||||
|
||||
} else {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClient();
|
||||
}
|
||||
|
||||
} else if (httpclient == null) {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClient();
|
||||
}
|
||||
}
|
||||
|
||||
HttpGet httpget = new HttpGet(new URI(string_url + "/0-0"));
|
||||
|
||||
error509 = false;
|
||||
|
||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httpget)) {
|
||||
|
||||
url_ok = (httpresponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK);
|
||||
|
||||
error509 = (httpresponse.getStatusLine().getStatusCode() == 509);
|
||||
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
|
||||
} catch (Exception ex) {
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} finally {
|
||||
|
||||
if (httpclient != null) {
|
||||
try {
|
||||
httpclient.close();
|
||||
} catch (IOException ex) {
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (MalformedURLException ex) {
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
} catch (IOException | URISyntaxException ex) {
|
||||
|
||||
Logger.getLogger(MiscTools.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
} while (error509 && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy());
|
||||
|
||||
return url_ok;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.tonikelope.megabasterd;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@ -29,7 +28,6 @@ public class SmartMegaProxyManager implements Runnable {
|
||||
private final ConcurrentLinkedQueue<String> _proxy_list;
|
||||
private final MainPanel _main_panel;
|
||||
private volatile boolean _exit;
|
||||
private volatile boolean _enabled;
|
||||
private final Object _refresh_lock;
|
||||
|
||||
public SmartMegaProxyManager(MainPanel main_panel, String proxy_list_url) {
|
||||
@ -37,7 +35,6 @@ public class SmartMegaProxyManager implements Runnable {
|
||||
_proxy_list_url = proxy_list_url;
|
||||
_proxy_list = new ConcurrentLinkedQueue<>();
|
||||
_exit = false;
|
||||
_enabled = false;
|
||||
_refresh_lock = new Object();
|
||||
}
|
||||
|
||||
@ -45,24 +42,6 @@ public class SmartMegaProxyManager implements Runnable {
|
||||
return _proxy_list_url;
|
||||
}
|
||||
|
||||
public boolean isEnabled() {
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
public void setEnabled(boolean enabled) {
|
||||
|
||||
if (!_main_panel.isLimit_download_speed()) {
|
||||
|
||||
if (!_enabled && enabled) {
|
||||
_main_panel.getView().getGlobal_speed_down_label().setForeground(Color.BLACK);
|
||||
} else if (_enabled && !enabled) {
|
||||
_main_panel.getView().getGlobal_speed_down_label().setForeground(new Color(0, 128, 255));
|
||||
}
|
||||
}
|
||||
|
||||
_enabled = enabled;
|
||||
}
|
||||
|
||||
public void setExit(boolean exit) {
|
||||
_exit = exit;
|
||||
}
|
||||
@ -171,11 +150,6 @@ public class SmartMegaProxyManager implements Runnable {
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.INFO, "{0} Smart Proxy Manager: proxy list refreshed ({1})", new Object[]{Thread.currentThread().getName(), _proxy_list.size()});
|
||||
|
||||
if (_enabled) {
|
||||
|
||||
_enabled = false;
|
||||
}
|
||||
|
||||
_main_panel.getView().updateSmartProxyStatus("SmartProxy: " + _proxy_list.size());
|
||||
}
|
||||
|
||||
|
@ -58,22 +58,9 @@ public class StreamChunkDownloader implements Runnable {
|
||||
_chunkwriter.secureWait();
|
||||
}
|
||||
|
||||
if (httpclient == null || error || (_chunkwriter.getServer().getMain_panel().isUse_smart_proxy() && _chunkwriter.getServer().getMain_panel().getProxy_manager().isEnabled())) {
|
||||
if (httpclient == null || error) {
|
||||
|
||||
if (error509 && _chunkwriter.getServer().getMain_panel().isUse_smart_proxy() && !_chunkwriter.getServer().getMain_panel().getProxy_manager().isEnabled()) {
|
||||
_chunkwriter.getServer().getMain_panel().getProxy_manager().setEnabled(true);
|
||||
}
|
||||
|
||||
if (_chunkwriter.getServer().getMain_panel().isUse_smart_proxy() && _chunkwriter.getServer().getMain_panel().getProxy_manager().isEnabled() && !MainPanel.isUse_proxy()) {
|
||||
|
||||
if (error && current_proxy != null) {
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker [{1}]: excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_proxy});
|
||||
|
||||
_chunkwriter.getServer().getMain_panel().getProxy_manager().excludeProxy(current_proxy);
|
||||
}
|
||||
|
||||
current_proxy = _chunkwriter.getServer().getMain_panel().getProxy_manager().getFastestProxy();
|
||||
if (error509 && MainPanel.isUse_smart_proxy() && !MainPanel.isUse_proxy()) {
|
||||
|
||||
if (httpclient != null) {
|
||||
try {
|
||||
@ -83,6 +70,15 @@ public class StreamChunkDownloader implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
if (error && current_proxy != null) {
|
||||
|
||||
Logger.getLogger(getClass().getName()).log(Level.WARNING, "{0} Worker [{1}]: excluding proxy -> {2}", new Object[]{Thread.currentThread().getName(), _id, current_proxy});
|
||||
|
||||
MainPanel.getProxy_manager().excludeProxy(current_proxy);
|
||||
}
|
||||
|
||||
current_proxy = MainPanel.getProxy_manager().getFastestProxy();
|
||||
|
||||
if (current_proxy != null) {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClientSmartProxy(current_proxy);
|
||||
@ -90,7 +86,6 @@ public class StreamChunkDownloader implements Runnable {
|
||||
} else {
|
||||
|
||||
httpclient = MiscTools.getApacheKissHttpClient();
|
||||
_chunkwriter.getServer().getMain_panel().getProxy_manager().setEnabled(false);
|
||||
}
|
||||
|
||||
} else if (httpclient == null) {
|
||||
@ -138,10 +133,7 @@ public class StreamChunkDownloader implements Runnable {
|
||||
|
||||
error = true;
|
||||
|
||||
if (http_status == 509) {
|
||||
|
||||
error509 = true;
|
||||
}
|
||||
error509 = (http_status == 509);
|
||||
|
||||
} else {
|
||||
|
||||
|
@ -272,7 +272,7 @@ public final class StreamerDialog extends javax.swing.JDialog implements Clipboa
|
||||
|
||||
private void use_mega_account_down_comboboxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_use_mega_account_down_comboboxItemStateChanged
|
||||
|
||||
if (_selected_item == null || !((String) use_mega_account_down_combobox.getSelectedItem()).equals(_selected_item)) {
|
||||
if (_selected_item == null || !use_mega_account_down_combobox.getSelectedItem().equals(_selected_item)) {
|
||||
_selected_item = (String) use_mega_account_down_combobox.getSelectedItem();
|
||||
|
||||
if (_main_panel.isUse_mega_account_down() && !"".equals(_selected_item)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user