|
32 | 32 | import jd.plugins.PluginForDecrypt; |
33 | 33 | import jd.plugins.hoster.DirectHTTP; |
34 | 34 |
|
35 | | -@DecrypterPlugin(revision = "$Revision: 50867 $", interfaceVersion = 3, names = {}, urls = {}) |
| 35 | +@DecrypterPlugin(revision = "$Revision: 51668 $", interfaceVersion = 3, names = {}, urls = {}) |
36 | 36 | public class CadoozVoucherCrawler extends PluginForDecrypt { |
37 | 37 | public CadoozVoucherCrawler(PluginWrapper wrapper) { |
38 | 38 | super(wrapper); |
@@ -79,51 +79,71 @@ public ArrayList<DownloadLink> decryptIt(final CryptedLink param, ProgressContro |
79 | 79 | br.getPage(contenturl); |
80 | 80 | if (br.getHttpConnection().getResponseCode() == 404) { |
81 | 81 | throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); |
82 | | - } else if (br.getRequest().getHtmlCode().length() < 200) { |
83 | | - /* |
84 | | - * E.g. plain text error |
85 | | - * "Die übergebene Ecard ist im System nicht bekannt. Bitte prüfen Sie die übergebene URL auf Vollständigkeit. Eventuell ist der Link durch einen Zeilenumbruch unbrauchbar geworden." |
| 82 | + } else if (br.getRequest().getHtmlCode().length() < 300) { |
| 83 | + /** |
| 84 | + * E.g. plain text error "Die übergebene Ecard ist im System nicht bekannt. Bitte prüfen Sie die übergebene URL auf |
| 85 | + * Vollständigkeit. Eventuell ist der Link durch einen Zeilenumbruch unbrauchbar geworden." <br> |
| 86 | + * e.g. >Leider kam es zu einem Problem beim Versuch ihren PDF Gutschein anzuzeigen. Bitte versuchen sie es später erneut. Falls |
| 87 | + * das Problem weiter besteht, wenden sie sich bitte an den cadooz Kundendienst. |
86 | 88 | */ |
87 | 89 | throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); |
88 | 90 | } |
89 | 91 | final String[] htmls = br.getRegex("<div class=\"ecard[^\"]+\">(.*?)--></div>").getColumn(0); |
90 | | - if (htmls == null || htmls.length == 0) { |
91 | | - throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); |
92 | | - } |
93 | 92 | final ArrayList<DownloadLink> ret = new ArrayList<DownloadLink>(); |
94 | 93 | String lastShopName = null; |
95 | | - int index = 0; |
96 | | - for (final String html : htmls) { |
97 | | - final String shopName = new Regex(html, "class=\"ecard-header-title\"[^>]*>([^<]+)</h3>").getMatch(0); |
98 | | - final String downloadlink = new Regex(html, "\"(https?://[^\"]+)\"[^<]+title=\"Hier PDF anzeigen").getMatch(0); |
99 | | - final String value = new Regex(html, ">\\s*Wert:\\s*</span>\\s*(\\d+,\\d{2})").getMatch(0); |
100 | | - String valueMinimal = null; |
101 | | - if (value != null) { |
102 | | - valueMinimal = value.replace(",00", ""); |
103 | | - } |
104 | | - final String validUntilDate = new Regex(html, " Gültig bis:\\s*</span>\\s*(\\d{4}\\.\\d{2}\\.\\d{2})").getMatch(0); |
105 | | - final DownloadLink link = this.createDownloadlink(DirectHTTP.createURLForThisPlugin(downloadlink)); |
106 | | - String filename = shopName + "_" + valueMinimal; |
107 | | - if (htmls.length > 1) { |
108 | | - /* Add position to filename to ensure unique filenames if we got more than 1 item. */ |
109 | | - filename += "_" + (index + 1); |
| 94 | + if (htmls != null && htmls.length > 0) { |
| 95 | + int index = 0; |
| 96 | + int skipped_un_downloadable_items = 0; |
| 97 | + for (final String html : htmls) { |
| 98 | + final String shopName = new Regex(html, "class=\"ecard-header-title\"[^>]*>([^<]+)</h3>").getMatch(0); |
| 99 | + final String download_url = new Regex(html, "\"(https?://[^\"]+)\"[^<]+title=\"Hier PDF anzeigen").getMatch(0); |
| 100 | + final String value = new Regex(html, ">\\s*Wert:\\s*</span>\\s*(\\d+,\\d{2})").getMatch(0); |
| 101 | + String valueMinimal = null; |
| 102 | + if (value != null) { |
| 103 | + valueMinimal = value.replace(",00", ""); |
| 104 | + } |
| 105 | + final String validUntilDate = new Regex(html, " Gültig bis:\\s*</span>\\s*(\\d{4}\\.\\d{2}\\.\\d{2})").getMatch(0); |
| 106 | + if (download_url == null) { |
| 107 | + skipped_un_downloadable_items++; |
| 108 | + continue; |
| 109 | + } |
| 110 | + final DownloadLink link = this.createDownloadlink(DirectHTTP.createURLForThisPlugin(download_url)); |
| 111 | + String filename = shopName + "_" + valueMinimal; |
| 112 | + if (htmls.length > 1) { |
| 113 | + /* Add position to filename to ensure unique filenames if we got more than 1 item. */ |
| 114 | + filename += "_" + (index + 1); |
| 115 | + } |
| 116 | + filename += ".pdf"; |
| 117 | + link.setFinalFileName(filename); |
| 118 | + /* Ensure that name does not change when item is reset by user. */ |
| 119 | + link.setProperty(DirectHTTP.FIXNAME, filename); |
| 120 | + /* HEAD request is not possible -> Allow only GET */ |
| 121 | + link.setProperty(DirectHTTP.PROPERTY_REQUEST_TYPE, "GET"); |
| 122 | + if (validUntilDate != null) { |
| 123 | + link.setComment("Gültig bis: " + validUntilDate); |
| 124 | + } |
| 125 | + link.setAvailable(true); |
| 126 | + ret.add(link); |
| 127 | + lastShopName = shopName; |
| 128 | + index++; |
110 | 129 | } |
111 | | - filename += ".pdf"; |
112 | | - link.setFinalFileName(filename); |
113 | | - /* Ensure that name does not change when item is reset by user. */ |
114 | | - link.setProperty(DirectHTTP.FIXNAME, filename); |
115 | | - /* HEAD request is not possible -> Allow only GET */ |
116 | | - link.setProperty(DirectHTTP.PROPERTY_REQUEST_TYPE, "GET"); |
117 | | - if (validUntilDate != null) { |
118 | | - link.setComment("Gültig bis: " + validUntilDate); |
| 130 | + } |
| 131 | + if (ret.isEmpty()) { |
| 132 | + if (!br.containsHTML("class=\"ecard-data-code lazy\"")) { |
| 133 | + throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); |
119 | 134 | } |
120 | | - link.setAvailable(true); |
121 | | - ret.add(link); |
122 | | - lastShopName = shopName; |
123 | | - index++; |
| 135 | + /* Text based vouchers -> Download html page */ |
| 136 | + final DownloadLink text = this.createDownloadlink(br.getURL() + ".jdeatme"); |
| 137 | + text.setDownloadSize(br.getRequest().getHtmlCode().getBytes("UTF-8").length); |
| 138 | + text.setAvailable(true); |
| 139 | + ret.add(text); |
124 | 140 | } |
125 | 141 | final FilePackage fp = FilePackage.getInstance(); |
126 | | - fp.setName(lastShopName); |
| 142 | + if (lastShopName != null) { |
| 143 | + fp.setName(lastShopName); |
| 144 | + } else { |
| 145 | + /* Fallback */ |
| 146 | + } |
127 | 147 | fp.setPackageKey("cadooz://ecard/" + content_id); |
128 | 148 | fp.addLinks(ret); |
129 | 149 | return ret; |
|
0 commit comments