private void processPhotoSet( final ArrayList<DownloadLink> decryptedLinks, final Browser br, final String puid, final String fpname, final String hashTagsStr) throws Exception { final String gc = getGoogleCarousel(br); if (gc != null) { FilePackage fp = null; final String JSON = new Regex(gc, "<script type=\"application/ld\\+json\">(.*?)</script>").getMatch(0); final Map<String, Object> json = JavaScriptEngineFactory.jsonToJavaMap(JSON); final String articleBody = (String) json.get("articleBody"); final String fpName = articleBody != null ? articleBody.replaceAll("[\r\n]+", "").trim() : fpname; if (fpName != null) { fp = FilePackage.getInstance(); fp.setName(fpName); } // single entry objects are not in 'list' ArrayList<Object> results = null; try { results = (ArrayList<Object>) JavaScriptEngineFactory.walkJson(json, "image/@list"); } catch (Throwable t) { // single entry ? final String[] a = new String[] {(String) json.get("image")}; results = new ArrayList<Object>(Arrays.asList(a)); } if (results != null) { int count = 1; final DecimalFormat df = new DecimalFormat(results.size() < 100 ? "00" : "000"); for (final Object result : results) { final String url = (String) result; final DownloadLink dl = createDownloadlink("directhttp://" + url); if (fp != null) { fp.add(dl); } // cleanup... final String filename = setFileName(cleanupName(df.format(count) + " - " + fpName), puid) + getFileNameExtensionFromString(url); if (!useOriginalFilename) { dl.setFinalFileName(filename); } dl.setAvailable(true); setMD5Hash(dl, url); setImageLinkID(dl, url, puid); if (hashTagsStr != null) { dl.setProperty(PROPERTY_TAGS, hashTagsStr); } dl.setComment(hashTagsStr); decryptedLinks.add(dl); count++; } } } }
@SuppressWarnings({"unchecked"}) private void decryptUserLoggedIn() throws Exception { final int limit = 10; int offset = 0; boolean decryptSingle = parameter.matches("/page/\\d+"); /* Access url for logged-out-users first because if we don't we cannot see whether a password is needed or not! */ final String url_for_logged_out_users = convertUserUrlToLoggedOutUser(); this.br.setFollowRedirects(false); this.br.getPage(url_for_logged_out_users); br.followRedirect(true); if (this.handlePassword()) { /* Bullshit - if a blog is password protected we can only display it in the "logged out" mode ... */ decryptUser(); return; } if (br.containsHTML(GENERALOFFLINE) || this.br.getHttpConnection().getResponseCode() == 404) { logger.info("Link offline: " + parameter); return; } handlePassword(); final FilePackage fp = FilePackage.getInstance(); final String username = getUsername(this.parameter); String fpName = username; fp.setName(fpName); LinkedHashMap<String, Object> entries = null; ArrayList<Object> ressourcelist = null; do { if (this.isAbort()) { logger.info("Decryption aborted by user"); return; } br.getHeaders().put("Accept", "application/json, text/javascript, */*; q=0.01"); br.getHeaders().put("X-Requested-With", "XMLHttpRequest"); /* Not needed! */ // br.getHeaders().put("X-tumblr-form-key", "blaTest"); br.getPage( "//www.tumblr.com/svc/indash_blog/posts?tumblelog_name_or_id=" + username + "&post_id=&limit=" + limit + "&offset=" + offset); entries = (LinkedHashMap<String, Object>) JavaScriptEngineFactory.jsonToJavaObject(br.toString()); ressourcelist = (ArrayList<Object>) JavaScriptEngineFactory.walkJson(entries, "response/posts"); for (final Object posto : ressourcelist) { entries = (LinkedHashMap<String, Object>) posto; final String type = (String) entries.get("type"); final String post_url = (String) entries.get("post_url"); String directlink = null; String extension = null; String extensionFallback = null; if (type.equalsIgnoreCase("photo")) { directlink = (String) JavaScriptEngineFactory.walkJson(entries, "photos/{0}/original_size/url"); extensionFallback = ".jpg"; } else if (type.equalsIgnoreCase("video")) { directlink = (String) entries.get("video_url"); final String url_hd = convertDirectVideoUrltoHD(directlink); if (url_hd != null) { directlink = url_hd; } extensionFallback = ".mp4"; } else { /* There is type "text", "answer" and there might be type other types too! */ logger.info("Unsupported or un-downloadable tumblr-post-type: " + type); } if (directlink != null) { extension = getFileNameExtensionFromURL(directlink); if (extension == null) { extension = extensionFallback; } String filename = getFileNameFromURL(new URL(directlink)); if (filename != null && !filename.endsWith(extension)) { filename += extension; } final DownloadLink dl = this.createDownloadlink("directhttp://" + directlink); if (this.passCode != null) { dl.setDownloadPassword(this.passCode); } dl.setAvailable(true); if (post_url != null) { dl.setContentUrl(post_url); } if (filename != null && !useOriginalFilename) { dl.setName(filename); } fp.add(dl); decryptedLinks.add(dl); distribute(dl); } offset++; } if (decryptSingle) { break; } } while (ressourcelist.size() >= limit); logger.info("Decryption done"); }