|
| 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 | + |
| 18 | +import java.util.ArrayList; |
| 19 | +import java.util.List; |
| 20 | +import java.util.Map; |
| 21 | + |
| 22 | +import org.appwork.storage.TypeRef; |
| 23 | +import org.appwork.utils.DebugMode; |
| 24 | +import org.appwork.utils.StringUtils; |
| 25 | +import org.appwork.utils.parser.UrlQuery; |
| 26 | +import org.jdownloader.captcha.v2.challenge.recaptcha.v2.CaptchaHelperCrawlerPluginRecaptchaV2; |
| 27 | +import org.jdownloader.scripting.JavaScriptEngineFactory; |
| 28 | + |
| 29 | +import jd.PluginWrapper; |
| 30 | +import jd.controlling.ProgressController; |
| 31 | +import jd.http.Browser; |
| 32 | +import jd.nutils.encoding.Encoding; |
| 33 | +import jd.plugins.Account; |
| 34 | +import jd.plugins.AccountRequiredException; |
| 35 | +import jd.plugins.CryptedLink; |
| 36 | +import jd.plugins.DecrypterPlugin; |
| 37 | +import jd.plugins.DownloadLink; |
| 38 | +import jd.plugins.FilePackage; |
| 39 | +import jd.plugins.LinkStatus; |
| 40 | +import jd.plugins.PluginDependencies; |
| 41 | +import jd.plugins.PluginException; |
| 42 | +import jd.plugins.PluginForDecrypt; |
| 43 | +import jd.plugins.hoster.HanimeTv; |
| 44 | + |
| 45 | +@DecrypterPlugin(revision = "$Revision: 51302 $", interfaceVersion = 3, names = {}, urls = {}) |
| 46 | +@PluginDependencies(dependencies = { HanimeTv.class }) |
| 47 | +public class HanimeTvCrawler extends PluginForDecrypt { |
| 48 | + public HanimeTvCrawler(PluginWrapper wrapper) { |
| 49 | + super(wrapper); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public Browser createNewBrowserInstance() { |
| 54 | + final Browser br = super.createNewBrowserInstance(); |
| 55 | + br.setFollowRedirects(true); |
| 56 | + return br; |
| 57 | + } |
| 58 | + |
| 59 | + public static List<String[]> getPluginDomains() { |
| 60 | + return HanimeTv.getPluginDomains(); |
| 61 | + } |
| 62 | + |
| 63 | + public static String[] getAnnotationNames() { |
| 64 | + return buildAnnotationNames(getPluginDomains()); |
| 65 | + } |
| 66 | + |
| 67 | + @Override |
| 68 | + public String[] siteSupportedNames() { |
| 69 | + return buildSupportedNames(getPluginDomains()); |
| 70 | + } |
| 71 | + |
| 72 | + public static String[] getAnnotationUrls() { |
| 73 | + return buildAnnotationUrls(getPluginDomains()); |
| 74 | + } |
| 75 | + |
| 76 | + public static String[] buildAnnotationUrls(final List<String[]> pluginDomains) { |
| 77 | + final List<String> ret = new ArrayList<String>(); |
| 78 | + for (final String[] domains : pluginDomains) { |
| 79 | + // See: https://svn.jdownloader.org/issues/89919 |
| 80 | + if (DebugMode.TRUE_IN_IDE_ELSE_FALSE) { |
| 81 | + ret.add("https?://(?:www\\.)?" + buildHostsPatternPart(domains) + "/videos/hentai/([a-z0-9\\-]+)"); |
| 82 | + } else { |
| 83 | + ret.add("https?://(?:www\\.)?" + buildHostsPatternPart(domains) + "/videos/hentai_TODO_UNFINISHED_PLUGIN/([a-z0-9\\-]+)"); |
| 84 | + } |
| 85 | + } |
| 86 | + return ret.toArray(new String[0]); |
| 87 | + } |
| 88 | + |
| 89 | + public ArrayList<DownloadLink> decryptIt(final CryptedLink param, ProgressController progress) throws Exception { |
| 90 | + if (!DebugMode.TRUE_IN_IDE_ELSE_FALSE) { |
| 91 | + throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT); |
| 92 | + } |
| 93 | + br.getPage(param.getCryptedUrl()); |
| 94 | + if (br.getHttpConnection().getResponseCode() == 404) { |
| 95 | + throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND); |
| 96 | + } |
| 97 | + final String json = br.getRegex("window\\.__NUXT__=(.*?);</script>").getMatch(0); |
| 98 | + final Map<String, Object> entries = restoreFromString(json, TypeRef.MAP); |
| 99 | + final Map<String, Object> video = (Map<String, Object>) JavaScriptEngineFactory.walkJson(entries, "state/data/video"); |
| 100 | + final Map<String, Object> hentai_video = (Map<String, Object>) video.get("hentai_video"); |
| 101 | + final String title = hentai_video.get("name").toString(); |
| 102 | + final String slug = hentai_video.get("slug").toString(); |
| 103 | + final String slug_base64_encoded = Encoding.Base64Encode(slug); |
| 104 | + final String description = hentai_video.get("description").toString(); |
| 105 | + final FilePackage fp = FilePackage.getInstance(); |
| 106 | + fp.setName(Encoding.htmlDecode(title).trim()); |
| 107 | + fp.setComment(description); |
| 108 | + final String downloadlink = "/downloads/" + slug_base64_encoded; |
| 109 | + br.getPage(downloadlink); |
| 110 | + final String recaptchaV2Response = new CaptchaHelperCrawlerPluginRecaptchaV2(this, br, "6Lcs0SUUAAAAALB-B0yj9Bw0DQFSn0te4l72YrtV").getToken(); |
| 111 | + /* TODO: Implement signature verification */ |
| 112 | + final UrlQuery query = new UrlQuery(); |
| 113 | + query.appendEncoded("id", slug_base64_encoded); |
| 114 | + query.appendEncoded("kind", "requestlinks"); |
| 115 | + query.appendEncoded("captcha_kind", "recaptcha"); |
| 116 | + query.appendEncoded("captcha_token", recaptchaV2Response); |
| 117 | + query.appendEncoded("captcha_expires", ""); |
| 118 | + query.appendEncoded("loc", "https://hanime.tv"); |
| 119 | + br.getHeaders().put("Accept", "application/json, text/plain, */*"); |
| 120 | + br.getHeaders().put("Origin", "https://" + br.getHost()); |
| 121 | + br.getHeaders().put("x-session-token", ""); |
| 122 | + br.getHeaders().put("x-signature", "TODO"); |
| 123 | + br.getHeaders().put("x-signature-version", "web2"); |
| 124 | + br.getHeaders().put("x-time", Long.toString(System.currentTimeMillis())); |
| 125 | + br.getHeaders().put("x-token", "null"); |
| 126 | + br.getPage("https://h.freeanimehentai.net/rapi/v7/downloads?" + query.toString()); |
| 127 | + final Map<String, Object> entries2 = restoreFromString(br.getRequest().getHtmlCode(), TypeRef.MAP); |
| 128 | + if (entries2.get("is_downloads_enabled") != Boolean.TRUE) { |
| 129 | + throw new AccountRequiredException(); |
| 130 | + } |
| 131 | + final ArrayList<DownloadLink> ret = new ArrayList<DownloadLink>(); |
| 132 | + int numberofDownloadableItemsGuest = 0; |
| 133 | + // int numberofDownloadableItemsMember = 0; |
| 134 | + final Map<String, Object> videos_manifest = (Map<String, Object>) entries2.get("videos_manifest"); |
| 135 | + final List<Map<String, Object>> servers = (List<Map<String, Object>>) videos_manifest.get("servers"); |
| 136 | + for (final Map<String, Object> server : servers) { |
| 137 | + final List<Map<String, Object>> streams = (List<Map<String, Object>>) server.get("streams"); |
| 138 | + for (final Map<String, Object> stream : streams) { |
| 139 | + if (stream.get("is_downloadable") != Boolean.TRUE) { |
| 140 | + logger.info("Skipping undownloadable item: " + stream.get("id")); |
| 141 | + continue; |
| 142 | + } else if (stream.get("is_guest_allowed") != Boolean.TRUE) { |
| 143 | + logger.info("Skipping undownloadable item: " + stream.get("id")); |
| 144 | + continue; |
| 145 | + } |
| 146 | + numberofDownloadableItemsGuest++; |
| 147 | + final String url = stream.get("url").toString(); |
| 148 | + final String filename = stream.get("filename").toString(); |
| 149 | + final long filesize_mbs = ((Number) stream.get("filesize_mbs")).longValue(); |
| 150 | + final DownloadLink link = this.createDownloadlink(url); |
| 151 | + link.setName(filename); |
| 152 | + link.setDownloadSize(filesize_mbs * 1024 * 1024 * 1024); |
| 153 | + if (StringUtils.containsIgnoreCase(url, "highwinds-cdn.com")) { |
| 154 | + /* Direct downloadable URL */ |
| 155 | + link.setAvailable(true); |
| 156 | + } |
| 157 | + link._setFilePackage(fp); |
| 158 | + ret.add(link); |
| 159 | + } |
| 160 | + } |
| 161 | + if (numberofDownloadableItemsGuest == 0) { |
| 162 | + throw new AccountRequiredException(); |
| 163 | + } |
| 164 | + return ret; |
| 165 | + } |
| 166 | + |
| 167 | + @Override |
| 168 | + public boolean hasCaptcha(CryptedLink link, Account acc) { |
| 169 | + return false; |
| 170 | + } |
| 171 | +} |
0 commit comments