diff --git a/pom.xml b/pom.xml index ea4a57372..3a879f6fb 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 com.tonikelope MegaBasterd - 7.46 + 7.47 jar @@ -37,7 +37,7 @@ com.fasterxml.jackson.core jackson-databind - 2.9.10.5 + 2.9.10.7 diff --git a/src/main/java/com/tonikelope/megabasterd/MainPanel.java b/src/main/java/com/tonikelope/megabasterd/MainPanel.java index 647e7892c..c27a42b3c 100644 --- a/src/main/java/com/tonikelope/megabasterd/MainPanel.java +++ b/src/main/java/com/tonikelope/megabasterd/MainPanel.java @@ -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; diff --git a/src/main/java/com/tonikelope/megabasterd/MainPanelView.java b/src/main/java/com/tonikelope/megabasterd/MainPanelView.java index 4c50c8c2c..d9fe897d6 100644 --- a/src/main/java/com/tonikelope/megabasterd/MainPanelView.java +++ b/src/main/java/com/tonikelope/megabasterd/MainPanelView.java @@ -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 urls = new HashSet(findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", link_data, 0)); + Set urls = new HashSet(findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n/]+", link_data, 0)); Set megadownloader = new HashSet(findAllRegex("mega://enc[^\r\n]+", link_data, 0)); @@ -981,17 +981,31 @@ private void new_download_menuActionPerformed(java.awt.event.ActionEvent evt) {/ Set 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 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 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) { @@ -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); diff --git a/src/main/java/com/tonikelope/megabasterd/MegaAPI.java b/src/main/java/com/tonikelope/megabasterd/MegaAPI.java index cc4ae42cf..6cf899d7f 100644 --- a/src/main/java/com/tonikelope/megabasterd/MegaAPI.java +++ b/src/main/java/com/tonikelope/megabasterd/MegaAPI.java @@ -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; @@ -991,11 +993,11 @@ public HashMap 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); } } @@ -1008,6 +1010,105 @@ public HashMap getFolderNodes(String folder_id, String folder_ke return folder_nodes; } + public ArrayList getNlinks(Set links) { + + HashMap> map = new HashMap<>(); + + ArrayList 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 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> 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 getNLinksFromFolder(String folder_id, String folder_key, ArrayList file_ids) throws Exception { + + ArrayList 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) res_map[0].get("f")) { + + HashMap node = (HashMap) 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 { diff --git a/src/main/java/com/tonikelope/megabasterd/MiscTools.java b/src/main/java/com/tonikelope/megabasterd/MiscTools.java index 213ee61b9..2ef328b61 100644 --- a/src/main/java/com/tonikelope/megabasterd/MiscTools.java +++ b/src/main/java/com/tonikelope/megabasterd/MiscTools.java @@ -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); @@ -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); } @@ -816,7 +816,7 @@ public static String extractFirstMegaLinkFromString(String data) { try { String clean_data = MiscTools.newMegaLinks2Legacy(URLDecoder.decode(data, "UTF-8")); - ArrayList links = findAllRegex("(?:https?|mega)://[^\r\n]+(#[^\r\n!]*?)?![^\r\n!]+![^\\?\r\n]+", clean_data, 0); + ArrayList 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)); @@ -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"); } diff --git a/src/main/resources/images/mbasterd_screen.png b/src/main/resources/images/mbasterd_screen.png index a7b3d0b0c..764553edd 100644 Binary files a/src/main/resources/images/mbasterd_screen.png and b/src/main/resources/images/mbasterd_screen.png differ