public static final HashSet<String> handleBase64Decode(final String b64) { if (b64 == null) { return null; } final HashSet<String> results = new HashSet<String>(); String finallink = b64; int i = 0; // this covers nested encoding. while (i < 20 && finallink != null && !new Regex(finallink, "(?:ftp|https?)://.+").matches()) { i++; // cleanup crap after padding. this can break subsequent tries finallink = Encoding.Base64Decode(finallink.replaceFirst("(={1,2})[\\w\\+]+$", "$1")); // urldecode if (finallink != null && new Regex(finallink, "%[0-9A-Fa-f]{2}").matches()) { finallink = Encoding.urlDecode(finallink, false); } // whitespace cleanup finallink = StringUtils.trim(finallink); } // determine multi or single result? final String[] multi = new Regex(finallink, "(?:https?|ftp)://").getColumn(-1); if (multi != null && multi.length > 1) { // because links might not be separated or deliminated, its best to use htmlparser final String[] links = HTMLParser.getHttpLinks(finallink, ""); if (links != null) { for (final String link : links) { results.add(link); } } } else { results.add(finallink); } return results; }
@Override public void handleFree(final DownloadLink downloadLink) throws Exception, PluginException { requestFileInformation(downloadLink); String dllink = checkDirectLink(downloadLink, "directlink"); if (dllink == null) { dllink = this.br.getRegex("(https?://[^<>\"]+/get/[^<>\"]+)").getMatch(0); if (dllink == null) { /* 2016-10-24 */ dllink = this.br.getRegex("Core\\.InitializeStream\\s*?\\(\\'([^<>\"]+)\\'").getMatch(0); if (dllink != null) { dllink = Encoding.Base64Decode(dllink); dllink = Encoding.unescape(dllink); dllink = new Regex(dllink, "(https?://[^<>\"]+/get/[^<>\"]+)").getMatch(0); } } if (dllink == null) { final String hash = br.getRegex("type=\"hidden\" name=\"hash\" value=\"([^<>\"]*?)\"").getMatch(0); final String expires = br.getRegex("type=\"hidden\" name=\"expires\" value=\"([^<>\"]*?)\"").getMatch(0); final String timestamp = br.getRegex("type=\"hidden\" name=\"timestamp\" value=\"([^<>\"]*?)\"").getMatch(0); if (hash == null || timestamp == null) { throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); } String postData = "hash=" + hash + "×tamp=" + timestamp; if (expires != null) { postData += "&expires=" + expires; } br.postPage(br.getURL(), postData); dllink = br.getRegex("class=\"stream\\-content\" data\\-url=\"(http[^<>\"]*?)\"").getMatch(0); if (dllink == null) { throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); } } } try { final Browser brc = br.cloneBrowser(); brc.getHeaders().put("Accept", "*/*"); brc.getHeaders().put("X-Requested-With", "XMLHttpRequest"); brc.getHeaders().put("", ""); brc.postPage( "http://" + domain + "/request", "action=view&abs=false&hash=" + new Regex(downloadLink.getDownloadURL(), "([a-z0-9]+)$").getMatch(0)); } catch (final Throwable e) { } dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, dllink, true, 1); if (dl.getConnection().getContentType().contains("html")) { br.followConnection(); throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); } downloadLink.setProperty("directlink", dllink); dl.startDownload(); }
private void getDllink(final String linkPart) throws IOException { final String vkey = new Regex(Encoding.htmlDecode(linkPart), "vkey=([0-9a-f]+)").getMatch(0); br.getPage( "http://www.nuvid.com" + Encoding.htmlDecode(linkPart) + "&pkey=" + JDHash.getMD5(vkey + Encoding.Base64Decode("aHlyMTRUaTFBYVB0OHhS"))); dllink = br.getRegex("<video_file>(http://.*?)</video_file>").getMatch(0); if (dllink == null) { dllink = br.getRegex("<video_file><\\!\\[CDATA\\[(http://.*?)\\]\\]></video_file>").getMatch(0); } }
private boolean getUserLogin() throws Exception { /* * we have to load the plugins first! we must not reference a plugin class without loading it before */ final PluginForHost hosterPlugin = JDUtilities.getPluginForHost("mediafire.com"); final Account aa = AccountController.getInstance().getValidAccount(hosterPlugin); if (aa != null) { // Try to re-use session token as long as possible (it's valid for 10 minutes) final String savedusername = this.getPluginConfig().getStringProperty("username"); final String savedpassword = this.getPluginConfig().getStringProperty("password"); final String sessiontokenCreateDateObject = this.getPluginConfig().getStringProperty("sessiontokencreated2"); long sessiontokenCreateDate = -1; if (sessiontokenCreateDateObject != null && sessiontokenCreateDateObject.length() > 0) { sessiontokenCreateDate = Long.parseLong(sessiontokenCreateDateObject); } if ((savedusername != null && savedusername.matches(aa.getUser())) && (savedpassword != null && savedpassword.matches(aa.getPass())) && System.currentTimeMillis() - sessiontokenCreateDate < 600000) { SESSIONTOKEN = this.getPluginConfig().getStringProperty("sessiontoken"); } else { // Get token for user account apiRequest( br, "https://www.mediafire.com/api/user/get_session_token.php", "?email=" + Encoding.urlEncode(aa.getUser()) + "&password="******"&application_id=" + MdfrFldr.APPLICATIONID + "&signature=" + JDHash.getSHA1( aa.getUser() + aa.getPass() + MdfrFldr.APPLICATIONID + Encoding.Base64Decode(MdfrFldr.APIKEY)) + "&version=1"); SESSIONTOKEN = getXML("session_token", br.toString()); this.getPluginConfig().setProperty("username", aa.getUser()); this.getPluginConfig().setProperty("password", aa.getPass()); this.getPluginConfig().setProperty("sessiontoken", SESSIONTOKEN); this.getPluginConfig().setProperty("sessiontokencreated2", "" + System.currentTimeMillis()); this.getPluginConfig().save(); } } return false; }
private String convertToMediaVaultUrl(String url) { final Browser getTime = br.cloneBrowser(); String time = null; try { getTime.getPage("http://assets.delvenetworks.com/time.php"); time = getTime.getRegex("(\\d+)").getMatch(0); } catch (final Throwable e) { } if (time == null) { return null; } final int e = (int) Math.floor(Double.parseDouble(time) + 1500); url = url + "?e=" + e; final String h = JDHash.getMD5(Encoding.Base64Decode("Z0RuU1lzQ0pTUkpOaVdIUGh6dkhGU0RqTFBoMTRtUWc=") + url); url = url + "&h=" + h; return url; }
public static String getFileNameFromDispositionHeader(String header) { // http://greenbytes.de/tech/tc2231/ if (header == null) { return null; } final String orgheader = header; String contentdisposition = header; String filename = null; for (int i = 0; i < 2; i++) { if (contentdisposition.contains("filename*")) { /* Codierung default */ /* * Content-Disposition: attachment;filename==?UTF-8?B? * RGF2aWQgR3VldHRhIC0gSnVzdCBBIExpdHRsZSBNb3JlIExvdmUgW2FMYnlsb3ZlciBYLUNsdXNpdiBSZW1peF0uTVAz * ?= */ contentdisposition = contentdisposition.replaceAll("filename\\*", "filename"); final String format = new Regex(contentdisposition, ".*?=[ \"']*(.+)''").getMatch(0); if (format == null) { Plugin.logger.severe("Content-Disposition: invalid format: " + header); filename = null; return filename; } contentdisposition = contentdisposition.replaceAll(format + "''", ""); filename = new Regex(contentdisposition, "filename.*?=[ ]*\"(.+)\"").getMatch(0); if (filename == null) { filename = new Regex(contentdisposition, "filename.*?=[ ]*'(.+)'").getMatch(0); } if (filename == null) { header = header.replaceAll("=", "=\"") + "\""; header = header.replaceAll(";\"", "\""); contentdisposition = header; } else { try { filename = URLDecoder.decode(filename, format); } catch (final Exception e) { Plugin.logger.severe("Content-Disposition: could not decode filename: " + header); filename = null; return filename; } } } else if (new Regex(contentdisposition, "=\\?.*?\\?.*?\\?.*?\\?=").matches()) { /* * Codierung Encoded Words, TODO: Q-Encoding und mehrfach * tokens, aber noch nicht in freier Wildbahn gesehen */ final String tokens[][] = new Regex(contentdisposition, "=\\?(.*?)\\?(.*?)\\?(.*?)\\?=").getMatches(); if (tokens.length == 1 && tokens[0].length == 3 && tokens[0][1].trim().equalsIgnoreCase("B")) { /* Base64 Encoded */ try { filename = URLDecoder.decode(Encoding.Base64Decode(tokens[0][2].trim()), tokens[0][0].trim()); } catch (final Exception e) { Plugin.logger.severe("Content-Disposition: could not decode filename: " + header); filename = null; return filename; } } } else if (new Regex(contentdisposition, "=\\?.*?\\?.*?\\?=").matches()) { /* Unicode Format wie es 4Shared nutzt */ final String tokens[][] = new Regex(contentdisposition, "=\\?(.*?)\\?(.*?)\\?=").getMatches(); if (tokens.length == 1 && tokens[0].length == 2) { try { contentdisposition = new String(tokens[0][1].trim().getBytes("ISO-8859-1"), tokens[0][0].trim()); continue; } catch (final Exception e) { Plugin.logger.severe("Content-Disposition: could not decode filename: " + header); filename = null; return filename; } } } else { /* ohne Codierung */ filename = new Regex(contentdisposition, "filename.*?=[ ]*\"(.+)\"").getMatch(0); if (filename == null) { filename = new Regex(contentdisposition, "filename.*?=[ ]*'(.+)'").getMatch(0); } if (filename == null) { header = header.replaceAll("=", "=\"") + "\""; header = header.replaceAll(";\"", "\""); contentdisposition = header; } } if (filename != null) { break; } } if (filename != null) { filename = filename.trim(); if (filename.startsWith("\"")) { Plugin.logger.info("Using Workaround for broken filename header!"); filename = filename.substring(1); } } if (filename == null) { Plugin.logger.severe("Content-Disposition: could not parse header: " + orgheader); } return filename; }
private String checkMD2(final String time) { return JDHash.getMD5(time + Encoding.Base64Decode(AHV)); }
private String checkMD(final String videoUrl, final String time) { return JDHash.getMD5(videoUrl + time + Encoding.Base64Decode(AHV)); }
@Override public void handleFree(DownloadLink downloadLink) throws Exception { checkShowFreeDialog(); requestFileInformation(downloadLink); br.setFollowRedirects(true); if (server != -1) { synchronized (noFreeSlot) { Long ret = noFreeSlot.get(server); if (ret != null) { if (System.currentTimeMillis() - ret < waitNoFreeSlot) { if (downloadLink.getLinkStatus().getRetryCount() >= 5) { /* * reset counter this error does not cause plugin to stop */ downloadLink.getLinkStatus().setRetryCount(0); } throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, JDL.L( "plugins.hoster.shareonlinebiz.errors.servernotavailable3", "No free Free-User Slots! Get PremiumAccount or wait!"), waitNoFreeSlot); } else { noFreeSlot.remove(server); } } } synchronized (overloadedServer) { Long ret = overloadedServer.get(server); if (ret != null) { if (System.currentTimeMillis() - ret < waitOverloadedServer) { if (downloadLink.getLinkStatus().getRetryCount() >= 5) { /* * reset counter this error does not cause plugin to stop */ downloadLink.getLinkStatus().setRetryCount(0); } throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server overloaded", waitNoFreeSlot); } else { overloadedServer.remove(server); } } } } this.setBrowserExclusive(); br.getHeaders().put("User-Agent", UA.toString()); br.getHeaders() .put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); br.getHeaders().put("Accept-Language", "en-us,de;q=0.7,en;q=0.3"); br.getHeaders().put("Pragma", null); br.getHeaders().put("Cache-Control", null); br.setCookie("http://www.share-online.biz", "page_language", "english"); // redirects! try { br.getPage(downloadLink.getDownloadURL().replace("https://", "http://")); } catch (final BrowserException e) { if (br.getRequest().getHttpConnection().getResponseCode() == 502) { throw new PluginException( LinkStatus.ERROR_HOSTER_TEMPORARILY_UNAVAILABLE, JDL.L("plugins.hoster.shareonlinebiz.errors.maintenance", "Server maintenance"), 30 * 60 * 1000l); } throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, JDL.L("plugins.hoster.shareonlinebiz.errors.unknownservererror", "Unknown server error"), 1 * 60 * 60 * 1000l); } if (br.getURL().contains("/failure/proxy/1")) { throw new PluginException(LinkStatus.ERROR_FATAL, "Proxy error"); } final Browser brc = br.cloneBrowser(); try { brc.openGetConnection("/template/images/corp/uploadking.php?show=last"); } finally { try { brc.getHttpConnection().disconnect(); } catch (final Throwable e) { } } errorHandling(br, downloadLink, null, null); if (!br.containsHTML(">>> continue for free <<<")) { throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); } String ID = getID(downloadLink); br.postPage("/dl/" + ID + "/free/", "dl_free=1"); errorHandling(br, downloadLink, null, null); String wait = br.getRegex("var wait=(\\d+)").getMatch(0); boolean captcha = br.containsHTML("RECAPTCHA active"); long startWait = 0; if (captcha == true) { startWait = System.currentTimeMillis(); } else { if (wait != null) { this.sleep(Integer.parseInt(wait) * 1000l, downloadLink); } } String dlINFO = br.getRegex("var dl=\"(.*?)\"").getMatch(0); String url = Encoding.Base64Decode(dlINFO); if (captcha) { /* recaptcha handling */ PluginForHost recplug = JDUtilities.getPluginForHost("DirectHTTP"); jd.plugins.hoster.DirectHTTP.Recaptcha rc = ((DirectHTTP) recplug).getReCaptcha(br); rc.setId("6LdatrsSAAAAAHZrB70txiV5p-8Iv8BtVxlTtjKX"); rc.load(); File cf = rc.downloadCaptcha(getLocalCaptchaFile()); String c = getCaptchaCode("recaptcha", cf, downloadLink); if (wait != null) { long gotWait = Integer.parseInt(wait) * 500l; long waited = System.currentTimeMillis() - startWait; gotWait -= waited; if (gotWait > 0) { this.sleep(gotWait, downloadLink); } } br.postPage( "/dl/" + ID + "/free/captcha/" + System.currentTimeMillis(), "dl_free=1&recaptcha_response_field=" + Encoding.urlEncode(c) + "&recaptcha_challenge_field=" + rc.getChallenge()); url = br.getRegex("([a-zA-Z0-9/=]+)").getMatch(0); if ("0".equals(url)) { throw new PluginException(LinkStatus.ERROR_CAPTCHA); } url = Encoding.Base64Decode(url); if (url == null || !url.startsWith("http")) { url = null; } if (wait != null) { this.sleep(Integer.parseInt(wait) * 1000l, downloadLink); } } br.setFollowRedirects(true); /* Datei herunterladen */ if (url != null && url.trim().length() == 0) { throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "ServerError", 5 * 60 * 1000l); } if (br.containsHTML(">Proxy\\-Download not supported for free access")) { throw new PluginException( LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Proxy download not supported for free access", 5 * 60 * 1000l); } if (url == null || !url.startsWith("http")) { logger.info("share-online.biz: Unknown error"); int timesFailed = downloadLink.getIntegerProperty("timesfailedshareonlinebiz_unknown", 0); if (timesFailed <= 2) { timesFailed++; downloadLink.setProperty("timesfailedshareonlinebiz_unknown", timesFailed); throw new PluginException(LinkStatus.ERROR_RETRY, "Unknown error"); } else { downloadLink.setProperty("timesfailedshareonlinebiz_unknown", Property.NULL); logger.info("share-online.biz: Unknown error - Plugin broken!"); throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); } } dl = jd.plugins.BrowserAdapter.openDownload(br, downloadLink, url); if (dl.getConnection().isContentDisposition() || (dl.getConnection().getContentType() != null && dl.getConnection().getContentType().contains("octet-stream"))) { try { validateLastChallengeResponse(); } catch (final Throwable e) { } dl.startDownload(); } else { try { invalidateLastChallengeResponse(); } catch (final Throwable e) { } br.followConnection(); errorHandling(br, downloadLink, null, null); throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); } }