mirror of
https://github.com/tonikelope/megabasterd.git
synced 2025-05-30 21:40:15 +02:00
2.06
-Mega API fatal error codes
This commit is contained in:
parent
fd66676587
commit
a3e4831bd7
@ -19,6 +19,7 @@ import java.security.InvalidKeyException;
|
|||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.concurrent.ConcurrentLinkedQueue;
|
import java.util.concurrent.ConcurrentLinkedQueue;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import static java.util.concurrent.Executors.newCachedThreadPool;
|
import static java.util.concurrent.Executors.newCachedThreadPool;
|
||||||
@ -800,6 +801,8 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
|
|||||||
|
|
||||||
if (!_provision_ok) {
|
if (!_provision_ok) {
|
||||||
|
|
||||||
|
_status_error = true;
|
||||||
|
|
||||||
getView().hideAllExceptStatus();
|
getView().hideAllExceptStatus();
|
||||||
|
|
||||||
if (_fatal_error != null) {
|
if (_fatal_error != null) {
|
||||||
@ -1192,58 +1195,66 @@ public final class Download implements Transference, Runnable, SecureSingleThrea
|
|||||||
|
|
||||||
error_code = parseInt(ex.getMessage());
|
error_code = parseInt(ex.getMessage());
|
||||||
|
|
||||||
switch (error_code) {
|
if (Arrays.asList(FATAL_ERROR_API_CODES).contains(error_code)) {
|
||||||
case -2:
|
|
||||||
emergencyStopDownloader("Mega link is not valid! " + MiscTools.truncateText(link, 80));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case -14:
|
switch (error_code) {
|
||||||
emergencyStopDownloader("Mega link is not valid! " + MiscTools.truncateText(link, 80));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 22:
|
case -2:
|
||||||
emergencyStopDownloader("MegaCrypter link is not valid! " + MiscTools.truncateText(link, 80));
|
emergencyStopDownloader("Mega link is not valid! " + MiscTools.truncateText(link, 80));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 23:
|
case -14:
|
||||||
emergencyStopDownloader("MegaCrypter link is blocked! " + MiscTools.truncateText(link, 80));
|
emergencyStopDownloader("Mega link is not valid! " + MiscTools.truncateText(link, 80));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 24:
|
case 22:
|
||||||
emergencyStopDownloader("MegaCrypter link has expired! " + MiscTools.truncateText(link, 80));
|
emergencyStopDownloader("MegaCrypter link is not valid! " + MiscTools.truncateText(link, 80));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 25:
|
case 23:
|
||||||
emergencyStopDownloader("MegaCrypter link pass error! " + MiscTools.truncateText(link, 80));
|
emergencyStopDownloader("MegaCrypter link is blocked! " + MiscTools.truncateText(link, 80));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
case 24:
|
||||||
|
emergencyStopDownloader("MegaCrypter link has expired! " + MiscTools.truncateText(link, 80));
|
||||||
|
break;
|
||||||
|
|
||||||
if (!retry_request) {
|
case 25:
|
||||||
|
emergencyStopDownloader("MegaCrypter link pass error! " + MiscTools.truncateText(link, 80));
|
||||||
|
break;
|
||||||
|
|
||||||
throw ex;
|
default:
|
||||||
|
emergencyStopDownloader("MEGA/MC API FATAL ERROR: " + ex.getMessage() + " " + MiscTools.truncateText(link, 80));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
|
||||||
|
if (!retry_request) {
|
||||||
|
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
_retrying_request = true;
|
||||||
|
|
||||||
|
swingReflectionInvoke("setEnabled", getMain_panel().getView().getNew_download_menu(), true);
|
||||||
|
|
||||||
|
swingReflectionInvoke("setVisible", getView().getStop_button(), true);
|
||||||
|
|
||||||
|
swingReflectionInvoke("setText", getView().getStop_button(), "CANCEL RETRY");
|
||||||
|
|
||||||
|
for (long i = getWaitTimeExpBackOff(retry++); i > 0 && !_exit; i--) {
|
||||||
|
if (error_code == -18) {
|
||||||
|
getView().printStatusError("File temporarily unavailable! (Retrying in " + i + " secs...)");
|
||||||
|
} else {
|
||||||
|
getView().printStatusError("Mega/MC APIException error " + ex.getMessage() + " (Retrying in " + i + " secs...)");
|
||||||
}
|
}
|
||||||
|
|
||||||
_retrying_request = true;
|
try {
|
||||||
|
sleep(1000);
|
||||||
swingReflectionInvoke("setEnabled", getMain_panel().getView().getNew_download_menu(), true);
|
} catch (InterruptedException ex2) {
|
||||||
|
|
||||||
swingReflectionInvoke("setVisible", getView().getStop_button(), true);
|
|
||||||
|
|
||||||
swingReflectionInvoke("setText", getView().getStop_button(), "CANCEL RETRY");
|
|
||||||
|
|
||||||
for (long i = getWaitTimeExpBackOff(retry++); i > 0 && !_exit; i--) {
|
|
||||||
if (error_code == -18) {
|
|
||||||
getView().printStatusError("File temporarily unavailable! (Retrying in " + i + " secs...)");
|
|
||||||
} else {
|
|
||||||
getView().printStatusError("Mega/MC APIException error " + ex.getMessage() + " (Retrying in " + i + " secs...)");
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
sleep(1000);
|
|
||||||
} catch (InterruptedException ex2) {
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
|
@ -30,10 +30,10 @@ public final class DownloadManager extends TransferenceManager {
|
|||||||
|
|
||||||
getTransference_finished_queue().remove(d);
|
getTransference_finished_queue().remove(d);
|
||||||
|
|
||||||
_total_transferences_size -= d.getFile_size();
|
|
||||||
|
|
||||||
if (((Download) d).isProvision_ok()) {
|
if (((Download) d).isProvision_ok()) {
|
||||||
|
|
||||||
|
_total_transferences_size -= d.getFile_size();
|
||||||
|
|
||||||
delete_down.add(((Download) d).getUrl());
|
delete_down.add(((Download) d).getUrl());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ import org.apache.http.auth.UsernamePasswordCredentials;
|
|||||||
*/
|
*/
|
||||||
public final class MainPanel {
|
public final class MainPanel {
|
||||||
|
|
||||||
public static final String VERSION = "2.05";
|
public static final String VERSION = "2.06";
|
||||||
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
|
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
|
||||||
public static final int STREAMER_PORT = 1337;
|
public static final int STREAMER_PORT = 1337;
|
||||||
public static final int WATCHDOG_PORT = 1338;
|
public static final int WATCHDOG_PORT = 1338;
|
||||||
|
@ -38,6 +38,7 @@ public final class MegaAPI {
|
|||||||
public static final String API_URL = "https://g.api.mega.co.nz";
|
public static final String API_URL = "https://g.api.mega.co.nz";
|
||||||
public static final String API_KEY = null;
|
public static final String API_KEY = null;
|
||||||
public static final int REQ_ID_LENGTH = 10;
|
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};
|
||||||
|
|
||||||
public static int checkMEGAError(String data) {
|
public static int checkMEGAError(String data) {
|
||||||
String error = findFirstRegex("^\\[?(\\-[0-9]+)\\]?$", data, 1);
|
String error = findFirstRegex("^\\[?(\\-[0-9]+)\\]?$", data, 1);
|
||||||
@ -277,14 +278,12 @@ public final class MegaAPI {
|
|||||||
|
|
||||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||||
|
|
||||||
boolean error;
|
int error, conta_error = 0;
|
||||||
|
|
||||||
int conta_error = 0;
|
|
||||||
|
|
||||||
HttpPost httppost;
|
HttpPost httppost;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
error = true;
|
error = 0;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
@ -318,9 +317,8 @@ public final class MegaAPI {
|
|||||||
|
|
||||||
if (response.length() > 0) {
|
if (response.length() > 0) {
|
||||||
|
|
||||||
if (checkMEGAError(response) == 0) {
|
error = checkMEGAError(response);
|
||||||
error = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -332,9 +330,14 @@ public final class MegaAPI {
|
|||||||
Logger.getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
if (error != 0) {
|
||||||
|
|
||||||
System.out.println("MegaAPI ERROR. Waiting for retry...");
|
if (Arrays.asList(MEGA_ERROR_EXCEPTION_CODES).contains(error)) {
|
||||||
|
|
||||||
|
throw new MegaAPIException(String.valueOf(error));
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("MegaAPI ERROR " + String.valueOf(error) + " Waiting for retry...");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(getWaitTimeExpBackOff(conta_error++) * 1000);
|
Thread.sleep(getWaitTimeExpBackOff(conta_error++) * 1000);
|
||||||
@ -347,8 +350,11 @@ public final class MegaAPI {
|
|||||||
conta_error = 0;
|
conta_error = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} while (error);
|
} while (error != 0);
|
||||||
|
|
||||||
|
} catch (MegaAPIException | IOException exception) {
|
||||||
|
|
||||||
|
throw exception;
|
||||||
}
|
}
|
||||||
|
|
||||||
_seqno++;
|
_seqno++;
|
||||||
|
@ -13,7 +13,6 @@ import java.util.LinkedList;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import static java.util.logging.Logger.getLogger;
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import static megabasterd.MiscTools.BASE642Bin;
|
import static megabasterd.MiscTools.BASE642Bin;
|
||||||
@ -22,7 +21,6 @@ import static megabasterd.MiscTools.Bin2UrlBASE64;
|
|||||||
import static megabasterd.MiscTools.cleanFilePath;
|
import static megabasterd.MiscTools.cleanFilePath;
|
||||||
import static megabasterd.MiscTools.cleanFilename;
|
import static megabasterd.MiscTools.cleanFilename;
|
||||||
import static megabasterd.MiscTools.findFirstRegex;
|
import static megabasterd.MiscTools.findFirstRegex;
|
||||||
import static megabasterd.MiscTools.getWaitTimeExpBackOff;
|
|
||||||
import org.apache.http.HttpStatus;
|
import org.apache.http.HttpStatus;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
@ -44,82 +42,57 @@ public final class MegaCrypterAPI {
|
|||||||
String response = null;
|
String response = null;
|
||||||
|
|
||||||
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
try (CloseableHttpClient httpclient = MiscTools.getApacheKissHttpClient()) {
|
||||||
boolean error;
|
|
||||||
|
|
||||||
int conta_error = 0;
|
|
||||||
|
|
||||||
HttpPost httppost;
|
HttpPost httppost;
|
||||||
|
|
||||||
do {
|
try {
|
||||||
|
httppost = new HttpPost(url_api.toURI());
|
||||||
|
|
||||||
error = true;
|
httppost.setHeader("Content-type", "application/json");
|
||||||
|
|
||||||
try {
|
httppost.setHeader("Custom-User-Agent", MainPanel.DEFAULT_USER_AGENT);
|
||||||
httppost = new HttpPost(url_api.toURI());
|
|
||||||
|
|
||||||
httppost.setHeader("Content-type", "application/json");
|
httppost.setEntity(new StringEntity(request));
|
||||||
|
|
||||||
httppost.setHeader("Custom-User-Agent", MainPanel.DEFAULT_USER_AGENT);
|
try (CloseableHttpResponse httpresponse = httpclient.execute(httppost)) {
|
||||||
|
|
||||||
httppost.setEntity(new StringEntity(request));
|
if (httpresponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
||||||
|
System.out.println("Failed : HTTP error code : " + httpresponse.getStatusLine().getStatusCode());
|
||||||
|
|
||||||
try (CloseableHttpResponse httpresponse = httpclient.execute(httppost)) {
|
} else {
|
||||||
|
|
||||||
if (httpresponse.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
|
InputStream is = httpresponse.getEntity().getContent();
|
||||||
System.out.println("Failed : HTTP error code : " + httpresponse.getStatusLine().getStatusCode());
|
|
||||||
|
|
||||||
} else {
|
try (ByteArrayOutputStream byte_res = new ByteArrayOutputStream()) {
|
||||||
|
|
||||||
InputStream is = httpresponse.getEntity().getContent();
|
byte[] buffer = new byte[16 * 1024];
|
||||||
|
|
||||||
try (ByteArrayOutputStream byte_res = new ByteArrayOutputStream()) {
|
int reads;
|
||||||
|
|
||||||
byte[] buffer = new byte[16 * 1024];
|
while ((reads = is.read(buffer)) != -1) {
|
||||||
|
|
||||||
int reads;
|
byte_res.write(buffer, 0, reads);
|
||||||
|
}
|
||||||
|
|
||||||
while ((reads = is.read(buffer)) != -1) {
|
response = new String(byte_res.toByteArray());
|
||||||
|
|
||||||
byte_res.write(buffer, 0, reads);
|
if (response.length() > 0) {
|
||||||
}
|
|
||||||
|
|
||||||
response = new String(byte_res.toByteArray());
|
int mc_error;
|
||||||
|
|
||||||
if (response.length() > 0) {
|
if ((mc_error = MegaCrypterAPI.checkMCError(response)) != 0) {
|
||||||
|
throw new MegaCrypterAPIException(String.valueOf(mc_error));
|
||||||
|
|
||||||
int mc_error;
|
|
||||||
|
|
||||||
if ((mc_error = MegaCrypterAPI.checkMCError(response)) != 0) {
|
|
||||||
throw new MegaCrypterAPIException(String.valueOf(mc_error));
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
error = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (URISyntaxException ex) {
|
|
||||||
Logger.getLogger(MegaCrypterAPI.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (error) {
|
} catch (URISyntaxException ex) {
|
||||||
|
Logger.getLogger(MegaCrypterAPI.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
}
|
||||||
|
|
||||||
System.out.println("MegaAPI ERROR. Waiting for retry...");
|
|
||||||
|
|
||||||
try {
|
|
||||||
Thread.sleep(getWaitTimeExpBackOff(conta_error++) * 1000);
|
|
||||||
} catch (InterruptedException ex) {
|
|
||||||
getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
|
|
||||||
conta_error = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
} while (error);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
@ -15,6 +15,7 @@ public interface Transference {
|
|||||||
boolean LIMIT_TRANSFERENCE_SPEED_DEFAULT = false;
|
boolean LIMIT_TRANSFERENCE_SPEED_DEFAULT = false;
|
||||||
int MAX_TRANSFERENCE_SPEED_DEFAULT = 5;
|
int MAX_TRANSFERENCE_SPEED_DEFAULT = 5;
|
||||||
int MAX_WAIT_WORKERS_SHUTDOWN = 15;
|
int MAX_WAIT_WORKERS_SHUTDOWN = 15;
|
||||||
|
Integer[] FATAL_ERROR_API_CODES = {-2, -8, -9, -10, -11, -12, -13, -14, -15, -16, 22, 23, 24, 25};
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
|
|
||||||
|
@ -419,6 +419,8 @@ public final class Upload implements Transference, Runnable, SecureSingleThreadN
|
|||||||
|
|
||||||
if (!_provision_ok) {
|
if (!_provision_ok) {
|
||||||
|
|
||||||
|
_status_error = true;
|
||||||
|
|
||||||
getView().hideAllExceptStatus();
|
getView().hideAllExceptStatus();
|
||||||
|
|
||||||
if (_fatal_error != null) {
|
if (_fatal_error != null) {
|
||||||
|
@ -73,10 +73,10 @@ public final class UploadManager extends TransferenceManager {
|
|||||||
|
|
||||||
getTransference_finished_queue().remove(u);
|
getTransference_finished_queue().remove(u);
|
||||||
|
|
||||||
_total_transferences_size -= u.getFile_size();
|
|
||||||
|
|
||||||
if (((Upload) u).isProvision_ok()) {
|
if (((Upload) u).isProvision_ok()) {
|
||||||
|
|
||||||
|
_total_transferences_size -= u.getFile_size();
|
||||||
|
|
||||||
delete_up.add(new String[]{u.getFile_name(), ((Upload) u).getMa().getEmail()});
|
delete_up.add(new String[]{u.getFile_name(), ((Upload) u).getMa().getEmail()});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user