PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/src/jd/plugins/decrypter/RmFrksNt.java

https://bitbucket.org/jorgenio/jdownloader
Java | 147 lines | 121 code | 9 blank | 17 comment | 56 complexity | 8f5020a37fef9e842579086e9c2ece8d MD5 | raw file
Possible License(s): GPL-2.0, AGPL-1.0, MPL-2.0-no-copyleft-exception, Apache-2.0, BSD-3-Clause, LGPL-2.1, LGPL-2.0, GPL-3.0
  1. // jDownloader - Downloadmanager
  2. // Copyright (C) 2009 JD-Team support@jdownloader.org
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. package jd.plugins.decrypter;
  17. import java.awt.Point;
  18. import java.io.File;
  19. import java.util.ArrayList;
  20. import jd.PluginWrapper;
  21. import jd.controlling.ProgressController;
  22. import jd.http.Browser;
  23. import jd.parser.html.Form;
  24. import jd.plugins.CryptedLink;
  25. import jd.plugins.DecrypterException;
  26. import jd.plugins.DecrypterPlugin;
  27. import jd.plugins.DownloadLink;
  28. import jd.plugins.FilePackage;
  29. import jd.plugins.LinkStatus;
  30. import jd.plugins.PluginException;
  31. import jd.plugins.PluginForDecrypt;
  32. @DecrypterPlugin(revision = "$Revision: 13930 $", interfaceVersion = 2, names = { "rom-freaks.net" }, urls = { "http://[\\w\\.]*?rom-freaks\\.net/(download-[0-9]+-file-.+|link-[0-9]-[0-9]+-file-.+|.+desc-name.+)\\.html" }, flags = { 0 })
  33. public class RmFrksNt extends PluginForDecrypt {
  34. public RmFrksNt(PluginWrapper wrapper) {
  35. super(wrapper);
  36. }
  37. @Override
  38. public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress) throws Exception {
  39. ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
  40. String parameter = param.toString();
  41. br.setFollowRedirects(true);
  42. parameter = parameter.replaceAll("(/download-|/link-1-)", "/download-");
  43. br.getPage(parameter);
  44. if (parameter.contains("desc-name")) {
  45. String[] thelinks = br.getRegex("\"(link-[0-9]+-[0-9]+-file-.*?\\.html)\"").getColumn(0);
  46. if (thelinks == null || thelinks.length == 0) return null;
  47. for (String link : thelinks) {
  48. decryptedLinks.add(createDownloadlink("http://www.rom-freaks.net/" + link));
  49. }
  50. } else {
  51. String fpName = br.getRegex("<title>Download - NDS ROMs \\- \\d+(.*?)</title>").getMatch(0);
  52. if (fpName == null) fpName = br.getRegex("<td width=\"100%\" class=\"aligncenter\" colspan=\"2\">[\t\n\r ]+\\d+ \\- (.*?)</td>").getMatch(0);
  53. String fastWay = br.getRegex("<p align=\"center\"><b><a href=\"(.*?)\"").getMatch(0);
  54. if (fastWay == null) fastWay = br.getRegex("<p align=\"center\"><b><a href=\"(.*?)\"").getMatch(0);
  55. if (fastWay != null) {
  56. br.getPage("http://www.rom-freaks.net/" + fastWay);
  57. String finallink = br.getRegex("http-equiv=\"refresh\" content=\"\\d+ url=(http://.*?)\">").getMatch(0);
  58. if (finallink == null) {
  59. logger.warning("finallink is null, tried to go the fastWay, link: " + parameter);
  60. return null;
  61. }
  62. decryptedLinks.add(createDownloadlink(finallink));
  63. } else {
  64. String dlink = br.getRegex("\"(gotodownload\\-\\d+\\.html)\"").getMatch(0);
  65. if (dlink == null) throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
  66. dlink = "http://www.rom-freaks.net/" + dlink;
  67. br.getPage(dlink);
  68. /* captcha handling */
  69. String captchaurl = null;
  70. if (br.containsHTML("/captcha/go")) {
  71. captchaurl = "http://www.rom-freaks.net/captcha/go.php";
  72. }
  73. if (captchaurl == null) return null;
  74. Form captchaForm = br.getFormbyProperty("name", "form1");
  75. if (captchaForm == null) return null;
  76. String downlink = null;
  77. for (int i = 0; i <= 3; i++) {
  78. File file = this.getLocalCaptchaFile();
  79. Browser.download(file, br.cloneBrowser().openGetConnection("http://www.rom-freaks.net/captcha/go.php"));
  80. String code = getCaptchaCode(file, param);
  81. if (code == null) continue;
  82. String[] codep = code.split(":");
  83. Point p = new Point(Integer.parseInt(codep[0]), Integer.parseInt(codep[1]));
  84. captchaForm.put("button.x", p.x + "");
  85. captchaForm.put("button.y", p.y + "");
  86. br.submitForm(captchaForm);
  87. downlink = br.getRegex("\"(http://www\\.rom-freaks\\.net/down-.*?\\.html)\"").getMatch(0);
  88. String[] links = br.getRegex("<FORM ACTION=\"(.*?)\"").getColumn(0);
  89. if (links != null && links.length != 0 && downlink == null) {
  90. progress.setRange(links.length);
  91. for (String link : links) {
  92. decryptedLinks.add(createDownloadlink(link));
  93. progress.increase(1);
  94. }
  95. if (fpName != null) {
  96. FilePackage fp = FilePackage.getInstance();
  97. fp.setName(fpName.trim());
  98. fp.addLinks(decryptedLinks);
  99. }
  100. return decryptedLinks;
  101. }
  102. if (downlink != null) break;
  103. }
  104. if (downlink == null && br.containsHTML("/captcha/go")) throw new DecrypterException(DecrypterException.CAPTCHA);
  105. if (downlink == null) return null;
  106. br.getPage(downlink);
  107. // Last change was here
  108. String gotu = br.getRegex("\"(http://www\\.rom-freaks\\.net/got.*?_[a-zA-Z0-9]+.*?\\.html)\"").getMatch(0);
  109. if (gotu == null && br.containsHTML("http-equiv=\"refresh\"")) {
  110. logger.warning("Found one non-working link, link = " + dlink);
  111. }
  112. if (gotu == null) return null;
  113. br.getPage(gotu);
  114. String frameto = br.getRegex("\"(http://www.rom-freaks\\.net/frameto-.*?\\.html)\"").getMatch(0);
  115. if (frameto == null) return null;
  116. br.getPage(frameto);
  117. String[] links0 = br.getRegex("<iframe src=\"(.*?)\"").getColumn(0);
  118. if (links0 == null || links0.length == 0) {
  119. logger.warning("links0 equals null");
  120. logger.warning("This link failed: " + parameter);
  121. logger.warning(br.toString());
  122. return null;
  123. }
  124. progress.setRange(links0.length);
  125. for (String link : links0) {
  126. decryptedLinks.add(createDownloadlink(link));
  127. progress.increase(1);
  128. }
  129. }
  130. if (fpName != null) {
  131. FilePackage fp = FilePackage.getInstance();
  132. fp.setName(fpName.trim());
  133. fp.addLinks(decryptedLinks);
  134. }
  135. }
  136. return decryptedLinks;
  137. }
  138. }