|
42 | 42 | import jd.plugins.PluginForDecrypt; |
43 | 43 | import jd.plugins.hoster.GigafileNu; |
44 | 44 |
|
45 | | -@DecrypterPlugin(revision = "$Revision: 51770 $", interfaceVersion = 3, names = {}, urls = {}) |
| 45 | +@DecrypterPlugin(revision = "$Revision: 51775 $", interfaceVersion = 3, names = {}, urls = {}) |
46 | 46 | public class GigafileNuFolderCrawler extends PluginForDecrypt { |
47 | 47 | public GigafileNuFolderCrawler(PluginWrapper wrapper) { |
48 | 48 | super(wrapper); |
@@ -107,136 +107,121 @@ public ArrayList<DownloadLink> decryptIt(final CryptedLink param, ProgressContro |
107 | 107 | /* There is no specific single file URL -> set "folder" URL as contenturl. */ |
108 | 108 | link.setContentUrl(contenturl); |
109 | 109 | String filename = matomete_file_names != null && matomete_file_names.length == ressourcelist.size() ? matomete_file_names[i] : null; |
110 | | - String censoredExtension = null; |
111 | | - if (filename != null && filename.matches("^\\.[a-z0-9]{2,4}$")) { |
112 | | - censoredExtension = filename; |
113 | | - filename = null; |
114 | | - } |
115 | | - /* |
116 | | - * If this is set to true, this means that no usable filename was found here and it will need to be fetched by the hoster |
117 | | - * plugin during linkcheck. |
118 | | - */ |
119 | | - boolean prefer_report_api = false; |
120 | 110 | if (!GigafileNu.isFilename(filename)) { |
121 | | - prefer_report_api = StringUtils.isNotEmpty(filename); |
122 | 111 | filename = br.getRegex("download\\('" + Pattern.quote(fileID) + "[^>]*>\\s*(.*?)\\s*<").getMatch(0); |
123 | 112 | } |
124 | 113 | if (!GigafileNu.isFilename(filename)) { |
125 | | - prefer_report_api = prefer_report_api || StringUtils.isNotEmpty(filename); |
126 | 114 | filename = null; |
127 | 115 | } |
128 | 116 | if (StringUtils.isNotEmpty(filename)) { |
129 | | - prefer_report_api = false; |
130 | 117 | filename = Encoding.htmlDecode(filename).trim(); |
131 | 118 | link.setName(filename); |
132 | 119 | link.setProperty(GigafileNu.PROPERTY_FILE_NAME_FROM_CRAWLER, filename); |
133 | 120 | link.setAvailableStatus(AvailableStatus.TRUE); |
134 | 121 | } else { |
135 | 122 | /* Fallback: Set dummy filename to avoid all results having the same file name. */ |
136 | | - link.setName(fileID + StringUtils.valueOrEmpty(censoredExtension)); |
| 123 | + link.setName(fileID); |
137 | 124 | /* Do not set online status here so that hoster plugin can find the real filenames. */ |
138 | 125 | link.setAvailableStatus(AvailableStatus.UNCHECKED); |
139 | 126 | } |
140 | 127 | link.setVerifiedFileSize(filesize); |
141 | | - if (prefer_report_api) { |
142 | | - link.setProperty(GigafileNu.REPORT_WORKAROUND_PROPERTY, Boolean.TRUE); |
143 | | - } |
144 | 128 | link.setProperty(GigafileNu.PROPERTY_FILE_ID, fileID); |
145 | 129 | totalFilesize += filesize; |
146 | 130 | if (!filesFolders.containsKey(fileID)) { |
147 | 131 | filesFolders.put(fileID, link); |
148 | 132 | } |
149 | 133 | } |
150 | 134 | } |
151 | | - DownloadLink singleZipOrFile = null; |
| 135 | + DownloadLink combinedZipOrFile = null; |
| 136 | + boolean singleFileIsCombinedZip = false; |
152 | 137 | final String singleFileID = br.getRegex("var file = \"([^\"]+)").getMatch(0); |
153 | 138 | if (singleFileID != null && !filesFolders.containsKey(singleFileID)) { |
154 | | - singleZipOrFile = this.createDownloadlink(contenturl); |
155 | | - singleZipOrFile.setDefaultPlugin(hosterplugin); |
156 | | - singleZipOrFile.setHost(this.getHost()); |
| 139 | + combinedZipOrFile = this.createDownloadlink(contenturl); |
| 140 | + combinedZipOrFile.setDefaultPlugin(hosterplugin); |
| 141 | + combinedZipOrFile.setHost(this.getHost()); |
157 | 142 | /* There is no specific single file URL -> set "folder" URL as contenturl. */ |
158 | | - singleZipOrFile.setContentUrl(contenturl); |
| 143 | + combinedZipOrFile.setContentUrl(contenturl); |
159 | 144 | String filename = br.getRegex("matomete_zip_filename\"[^>]*>\\s*(.*?)\\s*<").getMatch(0); |
160 | 145 | /* |
161 | 146 | * If this is set to true, this means that no usable filename was found here and it will need to be fetched by the hoster plugin |
162 | 147 | * during linkcheck. |
163 | 148 | */ |
164 | | - boolean prefer_report_api = false; |
165 | 149 | if (!GigafileNu.isFilename(filename)) { |
166 | | - prefer_report_api = StringUtils.isNotEmpty(filename); |
167 | 150 | filename = br.getRegex("download\\('" + Pattern.quote(singleFileID) + "[^>]*>\\s*(.*?)\\s*<").getMatch(0); |
168 | 151 | } |
169 | 152 | if (!GigafileNu.isFilename(filename)) { |
170 | | - prefer_report_api = prefer_report_api || StringUtils.isNotEmpty(filename); |
171 | 153 | filename = null; |
172 | 154 | } |
173 | | - String extensionForSingleFile = null;// TODO |
174 | 155 | if (StringUtils.isNotEmpty(filename)) { |
175 | | - prefer_report_api = false; |
176 | 156 | filename = Encoding.htmlDecode(filename).trim(); |
177 | | - singleZipOrFile.setName(filename); |
178 | | - singleZipOrFile.setProperty(GigafileNu.PROPERTY_FILE_NAME_FROM_CRAWLER, filename); |
179 | | - singleZipOrFile.setAvailableStatus(AvailableStatus.TRUE); |
180 | | - } else if (extensionForSingleFile != null) { |
181 | | - /* We do not know a filename but we know the file extension */ |
182 | | - singleZipOrFile.setName(singleFileID + extensionForSingleFile); |
183 | | - /* Do not set online status here so that hoster plugin can find the real filenames. */ |
184 | | - singleZipOrFile.setAvailableStatus(AvailableStatus.UNCHECKED); |
| 157 | + combinedZipOrFile.setName(filename); |
| 158 | + combinedZipOrFile.setProperty(GigafileNu.PROPERTY_FILE_NAME_FROM_CRAWLER, filename); |
| 159 | + combinedZipOrFile.setAvailableStatus(AvailableStatus.TRUE); |
185 | 160 | } else { |
186 | 161 | /* Fallback */ |
187 | 162 | /* Set .zip extension as we just assume that this is the .zip file containing all other files. */ |
188 | | - singleZipOrFile.setName(singleFileID + ".zip"); |
| 163 | + combinedZipOrFile.setName(singleFileID + ".zip"); |
189 | 164 | /* Do not set online status here so that hoster plugin can find the real filenames. */ |
190 | | - singleZipOrFile.setAvailableStatus(AvailableStatus.UNCHECKED); |
| 165 | + combinedZipOrFile.setAvailableStatus(AvailableStatus.UNCHECKED); |
191 | 166 | } |
192 | 167 | final String fileSizeBytesStr = br.getRegex("var size = (\\d+);").getMatch(0); |
193 | 168 | if (fileSizeBytesStr != null) { |
194 | | - singleZipOrFile.setVerifiedFileSize(Long.parseLong(fileSizeBytesStr)); |
| 169 | + combinedZipOrFile.setVerifiedFileSize(Long.parseLong(fileSizeBytesStr)); |
195 | 170 | } else if (totalFilesize > 0) { |
196 | 171 | /* |
197 | 172 | * Use total size of all other files as fallback value -> Assume that this is the .zip file containing all other files. |
198 | 173 | */ |
199 | | - singleZipOrFile.setDownloadSize(totalFilesize); |
| 174 | + combinedZipOrFile.setDownloadSize(totalFilesize); |
200 | 175 | } else { |
201 | 176 | logger.warning("Failed to find size of single file in html code"); |
202 | 177 | } |
203 | | - if (prefer_report_api) { |
204 | | - singleZipOrFile.setProperty(GigafileNu.REPORT_WORKAROUND_PROPERTY, Boolean.TRUE); |
| 178 | + combinedZipOrFile.setProperty(GigafileNu.PROPERTY_FILE_ID, singleFileID); |
| 179 | + if (GigafileNu.isCombinedZipDownload(br, singleFileID)) { |
| 180 | + singleFileIsCombinedZip = true; |
| 181 | + combinedZipOrFile.setProperty(GigafileNu.REPORT_IS_COMPLETE_ZIP, true); |
205 | 182 | } |
206 | | - singleZipOrFile.setProperty(GigafileNu.PROPERTY_FILE_ID, singleFileID); |
207 | 183 | } |
208 | | - final CrawlMode crawlMode = PluginJsonConfig.get(getConfigInterface()).getCrawlMode().getMode(); |
209 | 184 | final ArrayList<DownloadLink> ret = new ArrayList<DownloadLink>(); |
210 | | - switch (crawlMode) { |
211 | | - case ALL: |
212 | | - ret.addAll(filesFolders.values()); |
213 | | - if (singleZipOrFile != null) { |
214 | | - ret.add(singleZipOrFile); |
215 | | - } |
216 | | - break; |
217 | | - case FILES_FOLDERS: |
| 185 | + if (filesFolders.size() == 1 && singleFileIsCombinedZip) { |
| 186 | + /* |
| 187 | + * "smart" optimization: if there is only one single file and the .zip containing that same file, return only that single file |
| 188 | + * regardless of the users' settings |
| 189 | + */ |
| 190 | + logger.info("Single file and combined .zip"); |
218 | 191 | ret.addAll(filesFolders.values()); |
219 | | - if (ret.size() == 0 && singleZipOrFile != null) { |
220 | | - // add zip because it's the only file |
221 | | - ret.add(singleZipOrFile); |
222 | | - } |
223 | | - break; |
224 | | - case ZIP: |
225 | | - if (singleZipOrFile != null) { |
226 | | - ret.add(singleZipOrFile); |
| 192 | + } else { |
| 193 | + final CrawlMode crawlMode = PluginJsonConfig.get(getConfigInterface()).getCrawlMode().getMode(); |
| 194 | + switch (crawlMode) { |
| 195 | + case ALL: |
| 196 | + ret.addAll(filesFolders.values()); |
| 197 | + if (combinedZipOrFile != null) { |
| 198 | + ret.add(combinedZipOrFile); |
| 199 | + } |
| 200 | + break; |
| 201 | + case FILES_FOLDERS: |
| 202 | + ret.addAll(filesFolders.values()); |
| 203 | + if (ret.size() == 0 && combinedZipOrFile != null) { |
| 204 | + // add zip because it's the only file |
| 205 | + ret.add(combinedZipOrFile); |
| 206 | + } |
| 207 | + break; |
| 208 | + case ZIP: |
| 209 | + if (combinedZipOrFile != null) { |
| 210 | + ret.add(combinedZipOrFile); |
| 211 | + } |
| 212 | + break; |
| 213 | + default: |
| 214 | + /* Developer mistake */ |
| 215 | + throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT, "Unsupported CrawlMode:" + crawlMode); |
227 | 216 | } |
228 | | - break; |
229 | | - default: |
230 | | - /* Developer mistake */ |
231 | | - throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT, "Unsupported CrawlMode:" + crawlMode); |
232 | | - } |
233 | | - if (ret.isEmpty()) { |
234 | | - if (!br.containsHTML("download\\('" + content_id_from_url) && !GigafileNu.isSingleZipDownload(br, content_id_from_url)) { |
235 | | - /* Assume that item is offline */ |
236 | | - throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); |
237 | | - } else { |
238 | | - /* Unknown state */ |
239 | | - throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); |
| 217 | + if (ret.isEmpty()) { |
| 218 | + if (!br.containsHTML("download\\('" + content_id_from_url) && !GigafileNu.isCombinedZipDownload(br, content_id_from_url)) { |
| 219 | + /* Assume that item is offline */ |
| 220 | + throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); |
| 221 | + } else { |
| 222 | + /* Unknown state */ |
| 223 | + throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); |
| 224 | + } |
240 | 225 | } |
241 | 226 | } |
242 | 227 | final FilePackage fp = FilePackage.getInstance(); |
|
0 commit comments