Skip to content

Commit

Permalink
7.47
Browse files Browse the repository at this point in the history
Fix #360
  • Loading branch information
tonikelope committed Oct 31, 2021
1 parent 43518ea commit a1ea38c
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.tonikelope</groupId>
<artifactId>MegaBasterd</artifactId>
<version>7.46</version>
<version>7.47</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
Expand Down Expand Up @@ -37,7 +37,7 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.10.5</version>
<version>2.9.10.7</version>
</dependency>
</dependencies>
<properties>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/tonikelope/megabasterd/MainPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
*/
public final class MainPanel {

public static final String VERSION = "7.46";
public static final String VERSION = "7.47";
public static final boolean FORCE_SMART_PROXY = false; //TRUE FOR DEBUGING SMART PROXY
public static final int THROTTLE_SLICE_SIZE = 16 * 1024;
public static final int DEFAULT_BYTE_BUFFER_SIZE = 16 * 1024;
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/com/tonikelope/megabasterd/MainPanelView.java
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ private void new_download_menuActionPerformed(java.awt.event.ActionEvent evt) {/
//Convert to legacy link format
String link_data = MiscTools.newMegaLinks2Legacy(dialog.getLinks_textarea().getText());

Set<String> urls = new HashSet(findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", link_data, 0));
Set<String> urls = new HashSet(findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n/]+", link_data, 0));

Set<String> megadownloader = new HashSet(findAllRegex("mega://enc[^\r\n]+", link_data, 0));

Expand Down Expand Up @@ -981,17 +981,31 @@ private void new_download_menuActionPerformed(java.awt.event.ActionEvent evt) {/
Set<String> dlc = new HashSet(findAllRegex("dlc://([^\r\n]+)", link_data, 1));

dlc.stream().map((d) -> CryptTools.decryptDLC(d, _main_panel)).forEachOrdered((links) -> {
links.stream().filter((link) -> (findFirstRegex("(?:https?|mega)://[^\r\n](#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", link, 0) != null)).forEachOrdered((link) -> {
links.stream().filter((link) -> (findFirstRegex("(?:https?|mega)://[^\r\n](#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n/]+", link, 0) != null)).forEachOrdered((link) -> {
urls.add(link);
});
});

if (!urls.isEmpty()) {

Set<String> folder_file_links = new HashSet(findAllRegex("(?:https?|mega)://[^\r\n]+#F\\*[^\r\n!]*?![^\r\n!]+![^\\?\r\n/]+", link_data, 0));

if (!folder_file_links.isEmpty()) {
ArrayList<String> nlinks = ma.getNlinks(folder_file_links);

urls.removeAll(folder_file_links);

urls.addAll(nlinks);
}

getMain_panel().getDownload_manager().getTransference_preprocess_global_queue().addAll(urls);

getMain_panel().getDownload_manager().secureNotify();

MiscTools.GUIRun(() -> {
new_download_menu.setEnabled(true);
});

boolean link_warning;

for (String url : urls) {
Expand Down Expand Up @@ -1114,8 +1128,6 @@ private void new_download_menuActionPerformed(java.awt.event.ActionEvent evt) {/

getMain_panel().getDownload_manager().secureNotify();

new_download_menu.setEnabled(true);

} else {

new_download_menu.setEnabled(true);
Expand Down
105 changes: 103 additions & 2 deletions src/main/java/com/tonikelope/megabasterd/MegaAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.HttpsURLConnection;
Expand Down Expand Up @@ -991,11 +993,11 @@ public HashMap<String, Object> getFolderNodes(String folder_id, String folder_ke
folder_nodes.put((String) node.get("h"), the_node);

} catch (Exception e) {
LOG.log(Level.WARNING, "WARNING: node key is not valid " + (String) node.get("k"));
LOG.log(Level.WARNING, "WARNING: node key is not valid " + (String) node.get("k") + " " + folder_key);
}

} else {
LOG.log(Level.WARNING, "WARNING: node key is not valid " + (String) node.get("k"));
LOG.log(Level.WARNING, "WARNING: node key is not valid " + (String) node.get("k") + " " + folder_key);
}

}
Expand All @@ -1008,6 +1010,105 @@ public HashMap<String, Object> getFolderNodes(String folder_id, String folder_ke
return folder_nodes;
}

public ArrayList<String> getNlinks(Set<String> links) {

HashMap<String, ArrayList<String>> map = new HashMap<>();

ArrayList<String> nlinks = new ArrayList<>();

for (String link : links) {

String folder_id = findFirstRegex("#F\\*[^!]+!([^!]+)", link, 1);

String folder_key = findFirstRegex("#F\\*[^!]+![^!]+!([^!]+)", link, 1);

String file_id = findFirstRegex("#F\\*([^!]+)", link, 1);

if (!map.containsKey(folder_id + ":" + folder_key)) {

ArrayList<String> lista = new ArrayList<>();

lista.add(file_id);

map.put(folder_id + ":" + folder_key, lista);

} else {

map.get(folder_id + ":" + folder_key).add(file_id);

}
}

for (Map.Entry<String, ArrayList<String>> entry : map.entrySet()) {

String[] folder_parts = entry.getKey().split(":");

try {
nlinks.addAll(getNLinksFromFolder(folder_parts[0], folder_parts[1], entry.getValue()));
} catch (Exception ex) {
Logger.getLogger(MegaAPI.class.getName()).log(Level.SEVERE, null, ex);
}

}

return nlinks;

}

public ArrayList<String> getNLinksFromFolder(String folder_id, String folder_key, ArrayList<String> file_ids) throws Exception {

ArrayList<String> nlinks = new ArrayList<>();

String request = "[{\"a\":\"f\", \"c\":\"1\", \"r\":\"1\"}]";

URL url_api = new URL(API_URL + "/cs?id=" + String.valueOf(_seqno) + (API_KEY != null ? "&ak=" + API_KEY : "") + "&n=" + folder_id);

String res = _rawRequest(request, url_api);

if (res != null) {

ObjectMapper objectMapper = new ObjectMapper();

HashMap[] res_map = objectMapper.readValue(res, HashMap[].class);

for (Object o : (Iterable<? extends Object>) res_map[0].get("f")) {

HashMap<String, Object> node = (HashMap<String, Object>) o;

String[] node_k = ((String) node.get("k")).split(":");

if (node_k.length == 2 && node_k[0] != "" && node_k[1] != "") {

try {

String dec_node_k = Bin2UrlBASE64(decryptKey(UrlBASE642Bin(node_k[1]), _urlBase64KeyDecode(folder_key)));

if (file_ids.contains((String) node.get("h"))) {

//Este es el que queremos
nlinks.add("https://mega.nz/#N!" + ((String) node.get("h")) + "!" + dec_node_k + "###n=" + folder_id);

}

} catch (Exception e) {
LOG.log(Level.WARNING, "WARNING: node key is not valid " + (String) node.get("k") + " " + folder_key);
}

} else {
LOG.log(Level.WARNING, "WARNING: node key is not valid " + (String) node.get("k") + " " + folder_key);
}

}

} else {

throw new Exception();
}

return nlinks;

}

private byte[] _urlBase64KeyDecode(String key) {

try {
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/tonikelope/megabasterd/MiscTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ public static String extractMegaLinksFromString(String data) {

String clean_data = MiscTools.newMegaLinks2Legacy(new String(Base64.getDecoder().decode(chunk)));

String decoded = MiscTools.findFirstRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", clean_data, 0);
String decoded = MiscTools.findFirstRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n/]+", clean_data, 0);

if (decoded != null) {
links.add(decoded);
Expand All @@ -799,7 +799,7 @@ public static String extractMegaLinksFromString(String data) {
url_decoded = data;
}
String clean_data = MiscTools.newMegaLinks2Legacy(url_decoded);
links.addAll(findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", clean_data, 0));
links.addAll(findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n/]+", clean_data, 0));
links.addAll(findAllRegex("mega://e(n|l)c[^\r\n]+", clean_data, 0));
res = links.stream().map((s) -> s + "\n").reduce(res, String::concat);
}
Expand All @@ -816,7 +816,7 @@ public static String extractFirstMegaLinkFromString(String data) {
try {
String clean_data = MiscTools.newMegaLinks2Legacy(URLDecoder.decode(data, "UTF-8"));

ArrayList<String> links = findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", clean_data, 0);
ArrayList<String> links = findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n/]+", clean_data, 0);

links.addAll(findAllRegex("mega://e(n|l)c[^\r\n]+", clean_data, 0));

Expand Down Expand Up @@ -1404,6 +1404,8 @@ public static String newMegaLinks2Legacy(String data) {

data = MiscTools.addBackSlashToLinks(MiscTools.addHTTPSToMegaLinks(data));

data = data.replaceAll("(?:https://)?mega(?:\\.co)?\\.nz/folder/([^#]+)#([^\r\n/]+)/file/([^\r\n/]+)", "https://mega.nz/#F*$3!$1!$2");

return data.replaceAll("(?:https://)?mega(?:\\.co)?\\.nz/folder/([^#]+)#([^\r\n]+)", "https://mega.nz/#F!$1!$2").replaceAll("(?:https://)?mega(?:\\.co)?\\.nz/file/([^#]+)#([^\r\n]+)", "https://mega.nz/#!$1!$2");
}

Expand Down
Binary file modified src/main/resources/images/mbasterd_screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a1ea38c

Please sign in to comment.