mirror of
https://github.com/mirror/jdownloader.git
synced 2024-11-27 05:50:51 +00:00
*General*
- DownloadLink: fixed NPE in my new handling hm null should not be returned by 'getFilenameAndPathCharacterReplaceMap' refs #83699 *Plugins: Fixes/Changes/Maintenance* - Plugins: minor refactoring refs #83699 *Plugins: New plugins* - added small helper crawler for special archive.org wayback machine links RE forum 94028 git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@48103 ebf7c1c2-ba36-0410-9fe8-c592906822b4 Former-commit-id: c6599b549174c11326092001f363428082ac218f
This commit is contained in:
parent
b2c40a541e
commit
0d83efb930
@ -1562,11 +1562,15 @@ public class DownloadLink extends Property implements Serializable, AbstractPack
|
||||
newfinalFileName = newfinalFileName.substring(0, newfinalFileName.length() - toRemove.length());
|
||||
}
|
||||
if (DebugMode.TRUE_IN_IDE_ELSE_FALSE) {
|
||||
// 2023-08-04: TODO, see https://svn.jdownloader.org/issues/83699
|
||||
// TODO: This should never be null ?!
|
||||
final Map<String, String> forbiddenCharacterReplaceMap = JsonConfig.create(GeneralSettings.class).getFilenameAndPathCharacterReplaceMap();
|
||||
final Iterator<Entry<String, String>> iterator = forbiddenCharacterReplaceMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Entry<String, String> entry = iterator.next();
|
||||
newfinalFileName = newfinalFileName.replace(entry.getKey(), entry.getValue());
|
||||
if (forbiddenCharacterReplaceMap != null && !forbiddenCharacterReplaceMap.isEmpty()) {
|
||||
final Iterator<Entry<String, String>> iterator = forbiddenCharacterReplaceMap.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Entry<String, String> entry = iterator.next();
|
||||
newfinalFileName = newfinalFileName.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
newfinalFileName = CrossSystem.alleviatePathParts(newfinalFileName);
|
||||
|
@ -16,33 +16,39 @@
|
||||
package jd.plugins.decrypter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.jdownloader.plugins.controller.LazyPlugin;
|
||||
|
||||
import jd.PluginWrapper;
|
||||
import jd.controlling.ProgressController;
|
||||
import jd.http.Browser;
|
||||
import jd.nutils.encoding.Encoding;
|
||||
import jd.parser.Regex;
|
||||
import jd.plugins.CryptedLink;
|
||||
import jd.plugins.DecrypterPlugin;
|
||||
import jd.plugins.DownloadLink;
|
||||
import jd.plugins.FilePackage;
|
||||
import jd.plugins.LinkStatus;
|
||||
import jd.plugins.PluginException;
|
||||
import jd.plugins.PluginForDecrypt;
|
||||
import jd.plugins.PluginForHost;
|
||||
import jd.utils.JDUtilities;
|
||||
|
||||
@DecrypterPlugin(revision = "$Revision$", interfaceVersion = 3, names = { "animegalleries.net" }, urls = { "https?://(?:www\\.)?animegalleries\\.net/album/\\d+" })
|
||||
public class AnimegalleriesNet extends PluginForDecrypt {
|
||||
public AnimegalleriesNet(PluginWrapper wrapper) {
|
||||
public class AnimegalleriesNetCrawler extends PluginForDecrypt {
|
||||
public AnimegalleriesNetCrawler(PluginWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
public ArrayList<DownloadLink> decryptIt(CryptedLink param, ProgressController progress) throws Exception {
|
||||
ArrayList<DownloadLink> decryptedLinks = new ArrayList<DownloadLink>();
|
||||
final String parameter = param.toString();
|
||||
getPage(parameter);
|
||||
@Override
|
||||
public LazyPlugin.FEATURE[] getFeatures() {
|
||||
return new LazyPlugin.FEATURE[] { LazyPlugin.FEATURE.XXX, LazyPlugin.FEATURE.IMAGE_GALLERY, LazyPlugin.FEATURE.IMAGE_HOST };
|
||||
}
|
||||
|
||||
public ArrayList<DownloadLink> decryptIt(final CryptedLink param, ProgressController progress) throws Exception {
|
||||
final ArrayList<DownloadLink> ret = new ArrayList<DownloadLink>();
|
||||
final String parameter = param.getCryptedUrl();
|
||||
br.getPage(parameter);
|
||||
if (br.getHttpConnection().getResponseCode() == 404) {
|
||||
decryptedLinks.add(this.createOfflinelink(parameter));
|
||||
return decryptedLinks;
|
||||
throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
String fpName = br.getRegex("\">([^<>\"]+)</h2>").getMatch(0);
|
||||
if (fpName == null) {
|
||||
@ -51,51 +57,46 @@ public class AnimegalleriesNet extends PluginForDecrypt {
|
||||
}
|
||||
String next = null;
|
||||
final FilePackage fp = FilePackage.getInstance();
|
||||
fp.setName(Encoding.htmlDecode(fpName.trim()));
|
||||
fp.addLinks(decryptedLinks);
|
||||
fp.setName(Encoding.htmlDecode(fpName).trim());
|
||||
fp.addLinks(ret);
|
||||
int page = 0;
|
||||
final HashSet<String> dupes = new HashSet<String>();
|
||||
do {
|
||||
if (this.isAbort()) {
|
||||
return decryptedLinks;
|
||||
}
|
||||
page++;
|
||||
if (next != null) {
|
||||
getPage(next);
|
||||
br.getPage(next);
|
||||
}
|
||||
final String[] linkids = br.getRegex("\"/img/(\\d+)\"").getColumn(0);
|
||||
if (linkids == null || linkids.length == 0) {
|
||||
break;
|
||||
}
|
||||
for (String linkid : linkids) {
|
||||
final String singleLink = "http://www.animegalleries.net/img/" + linkid;
|
||||
int newItemsOnThisPage = 0;
|
||||
for (final String contentID : linkids) {
|
||||
if (!dupes.add(contentID)) {
|
||||
continue;
|
||||
}
|
||||
final String singleLink = "http://www.animegalleries.net/img/" + contentID;
|
||||
final DownloadLink dl = createDownloadlink(singleLink);
|
||||
dl._setFilePackage(fp);
|
||||
dl.setAvailable(true);
|
||||
dl.setName(linkid + ".jpg");
|
||||
decryptedLinks.add(dl);
|
||||
dl.setName(contentID + ".jpg");
|
||||
ret.add(dl);
|
||||
distribute(dl);
|
||||
newItemsOnThisPage++;
|
||||
}
|
||||
logger.info("Crawled page" + page + "| New items on this page: " + newItemsOnThisPage + " | Total so far: " + ret.size());
|
||||
next = this.br.getRegex("class=\"tableb_compact\".*?class=\"navmenu\"><a href=\"(/album/\\d+/page/\\d+)\"").getMatch(0);
|
||||
} while (next != null);
|
||||
return decryptedLinks;
|
||||
}
|
||||
|
||||
private PluginForHost plugin = null;
|
||||
|
||||
private void getPage(final String parameter) throws Exception {
|
||||
getPage(br, parameter);
|
||||
}
|
||||
|
||||
private void getPage(final Browser br, final String parameter) throws Exception {
|
||||
loadPlugin();
|
||||
((jd.plugins.hoster.AnimegalleriesNet) plugin).setBrowser(br);
|
||||
((jd.plugins.hoster.AnimegalleriesNet) plugin).getPage(parameter);
|
||||
}
|
||||
|
||||
public void loadPlugin() {
|
||||
if (plugin == null) {
|
||||
plugin = JDUtilities.getPluginForHost("animegalleries.net");
|
||||
if (plugin == null) {
|
||||
throw new IllegalStateException(getHost() + " hoster plugin not found!");
|
||||
if (this.isAbort()) {
|
||||
logger.info("Stopping because: Aborted by user");
|
||||
return ret;
|
||||
} else if (newItemsOnThisPage == 0) {
|
||||
logger.info("Stopping becaused: Failed to find any new items on current page: " + page);
|
||||
break;
|
||||
} else if (next == null) {
|
||||
logger.info("Stopping because: Failed to find next page -> Reached end?");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} while (next != null);
|
||||
return ret;
|
||||
}
|
||||
}
|
96
src/jd/plugins/decrypter/ArchiveOrgWaybackMachine.java
Normal file
96
src/jd/plugins/decrypter/ArchiveOrgWaybackMachine.java
Normal file
@ -0,0 +1,96 @@
|
||||
//jDownloader - Downloadmanager
|
||||
//Copyright (C) 2009 JD-Team support@jdownloader.org
|
||||
//
|
||||
//This program is free software: you can redistribute it and/or modify
|
||||
//it under the terms of the GNU General Public License as published by
|
||||
//the Free Software Foundation, either version 3 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//This program is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
//GNU General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU General Public License
|
||||
//along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package jd.plugins.decrypter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jd.PluginWrapper;
|
||||
import jd.controlling.ProgressController;
|
||||
import jd.http.URLConnectionAdapter;
|
||||
import jd.http.requests.GetRequest;
|
||||
import jd.plugins.CryptedLink;
|
||||
import jd.plugins.DecrypterPlugin;
|
||||
import jd.plugins.DownloadLink;
|
||||
import jd.plugins.LinkStatus;
|
||||
import jd.plugins.PluginException;
|
||||
import jd.plugins.PluginForDecrypt;
|
||||
import jd.plugins.hoster.DirectHTTP;
|
||||
|
||||
@DecrypterPlugin(revision = "$Revision$", interfaceVersion = 3, names = {}, urls = {})
|
||||
public class ArchiveOrgWaybackMachine extends PluginForDecrypt {
|
||||
public ArchiveOrgWaybackMachine(PluginWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
public static List<String[]> getPluginDomains() {
|
||||
final List<String[]> ret = new ArrayList<String[]>();
|
||||
// each entry in List<String[]> will result in one PluginForDecrypt, Plugin.getHost() will return String[0]->main domain
|
||||
ret.add(new String[] { "web.archive.org" });
|
||||
return ret;
|
||||
}
|
||||
|
||||
public static String[] getAnnotationNames() {
|
||||
return buildAnnotationNames(getPluginDomains());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] siteSupportedNames() {
|
||||
return buildSupportedNames(getPluginDomains());
|
||||
}
|
||||
|
||||
public static String[] getAnnotationUrls() {
|
||||
return buildAnnotationUrls(getPluginDomains());
|
||||
}
|
||||
|
||||
public static String[] buildAnnotationUrls(final List<String[]> pluginDomains) {
|
||||
final List<String> ret = new ArrayList<String>();
|
||||
for (final String[] domains : pluginDomains) {
|
||||
ret.add("https?://" + buildHostsPatternPart(domains) + "/web/(\\d+)/.+");
|
||||
}
|
||||
return ret.toArray(new String[0]);
|
||||
}
|
||||
|
||||
public ArrayList<DownloadLink> decryptIt(final CryptedLink param, ProgressController progress) throws Exception {
|
||||
final ArrayList<DownloadLink> ret = new ArrayList<DownloadLink>();
|
||||
br.setFollowRedirects(true);
|
||||
/* First check if maybe the user has added a directURL. */
|
||||
final GetRequest getRequest = br.createGetRequest(param.getCryptedUrl());
|
||||
final URLConnectionAdapter con = this.br.openRequestConnection(getRequest);
|
||||
try {
|
||||
if (this.looksLikeDownloadableContent(con)) {
|
||||
final DownloadLink direct = getCrawler().createDirectHTTPDownloadLink(getRequest, con);
|
||||
ret.add(direct);
|
||||
} else {
|
||||
br.followConnection();
|
||||
if (br.getHttpConnection().getResponseCode() == 404) {
|
||||
throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
/* E.g. embedded PDF */
|
||||
final String directurl = br.getRegex("<iframe id=\"playback\"[^>]*src=\"(https?://[^\"]+)").getMatch(0);
|
||||
if (directurl == null) {
|
||||
logger.info("URL is not supported or content is offline");
|
||||
throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
|
||||
} else {
|
||||
ret.add(this.createDownloadlink(DirectHTTP.createURLForThisPlugin(directurl)));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
con.disconnect();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -15,7 +15,14 @@
|
||||
//along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package jd.plugins.hoster;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.appwork.utils.StringUtils;
|
||||
import org.appwork.utils.formatter.SizeFormatter;
|
||||
import org.jdownloader.plugins.controller.LazyPlugin;
|
||||
|
||||
import jd.PluginWrapper;
|
||||
import jd.http.Browser;
|
||||
import jd.http.URLConnectionAdapter;
|
||||
import jd.nutils.encoding.Encoding;
|
||||
import jd.parser.Regex;
|
||||
@ -23,16 +30,21 @@ import jd.plugins.DownloadLink;
|
||||
import jd.plugins.DownloadLink.AvailableStatus;
|
||||
import jd.plugins.HostPlugin;
|
||||
import jd.plugins.LinkStatus;
|
||||
import jd.plugins.Plugin;
|
||||
import jd.plugins.PluginException;
|
||||
|
||||
import org.jdownloader.plugins.components.antiDDoSForHost;
|
||||
import jd.plugins.PluginForHost;
|
||||
|
||||
@HostPlugin(revision = "$Revision$", interfaceVersion = 3, names = { "animegalleries.net" }, urls = { "https?://(?:www\\.)?animegalleries\\.net/img/(\\d+)" })
|
||||
public class AnimegalleriesNet extends antiDDoSForHost {
|
||||
public class AnimegalleriesNet extends PluginForHost {
|
||||
public AnimegalleriesNet(PluginWrapper wrapper) {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LazyPlugin.FEATURE[] getFeatures() {
|
||||
return new LazyPlugin.FEATURE[] { LazyPlugin.FEATURE.XXX, LazyPlugin.FEATURE.IMAGE_GALLERY, LazyPlugin.FEATURE.IMAGE_HOST };
|
||||
}
|
||||
|
||||
/* DEV NOTES */
|
||||
// Tags:
|
||||
// protocol: no https
|
||||
@ -45,55 +57,74 @@ public class AnimegalleriesNet extends antiDDoSForHost {
|
||||
|
||||
@Override
|
||||
public String getAGBLink() {
|
||||
return "http://www.animegalleries.net/privacy.php";
|
||||
return "https://www.animegalleries.net/privacy.php";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLinkID(final DownloadLink link) {
|
||||
final String fid = getFID(link);
|
||||
if (fid != null) {
|
||||
return this.getHost() + "://" + fid;
|
||||
} else {
|
||||
return super.getLinkID(link);
|
||||
}
|
||||
}
|
||||
|
||||
private String getFID(final DownloadLink link) {
|
||||
return new Regex(link.getPluginPatternMatcher(), this.getSupportedLinks()).getMatch(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public AvailableStatus requestFileInformation(final DownloadLink link) throws Exception {
|
||||
return requestFileInformation(link, false);
|
||||
}
|
||||
|
||||
private AvailableStatus requestFileInformation(final DownloadLink link, final boolean isDownload) throws Exception {
|
||||
dllink = null;
|
||||
final String extDefault = ".jpg";
|
||||
this.setBrowserExclusive();
|
||||
br.setFollowRedirects(true);
|
||||
getPage(link.getDownloadURL());
|
||||
br.getPage(link.getPluginPatternMatcher());
|
||||
if (br.getHttpConnection().getResponseCode() == 404) {
|
||||
throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
final String url_filename = new Regex(link.getDownloadURL(), "(\\d+)").getMatch(0);
|
||||
String filename = br.getRegex("<title>Anime Galleries dot Net \\- ([^<>\"]+) Pics, Images, Screencaps, and Scans</title>").getMatch(0);
|
||||
if (filename == null) {
|
||||
filename = url_filename;
|
||||
final String fileid = this.getFID(link);
|
||||
String title = br.getRegex("<title>Anime Galleries dot Net \\- ([^<>\"]+) Pics, Images, Screencaps, and Scans</title>").getMatch(0);
|
||||
if (title == null) {
|
||||
title = fileid;
|
||||
}
|
||||
dllink = br.getRegex("id=\"photoholder\"><img src=\"(http[^<>\"]+)\"").getMatch(0);
|
||||
if (dllink == null) {
|
||||
dllink = br.getRegex("\"(https?://media\\.animegalleries\\.net/albums/[^<>\"]+)\"").getMatch(0);
|
||||
}
|
||||
if (filename == null || dllink == null) {
|
||||
if (title == null || dllink == null) {
|
||||
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
|
||||
}
|
||||
dllink = Encoding.htmlDecode(dllink);
|
||||
filename = Encoding.htmlDecode(filename);
|
||||
filename = filename.trim();
|
||||
filename = encodeUnicode(filename);
|
||||
final String ext = getFileNameExtensionFromString(dllink, ".jpg");
|
||||
if (!filename.endsWith(ext)) {
|
||||
filename += ext;
|
||||
}
|
||||
link.setFinalFileName(filename);
|
||||
URLConnectionAdapter con = null;
|
||||
try {
|
||||
con = br.openHeadConnection(dllink);
|
||||
if (this.looksLikeDownloadableContent(con)) {
|
||||
if (con.getCompleteContentLength() > 0) {
|
||||
link.setDownloadSize(con.getCompleteContentLength());
|
||||
}
|
||||
} else {
|
||||
throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
link.setProperty("directlink", dllink);
|
||||
} finally {
|
||||
title = Encoding.htmlDecode(title);
|
||||
title = title.trim();
|
||||
final String extFromURL = getFileNameExtensionFromString(dllink, extDefault);
|
||||
link.setName(this.correctOrApplyFileNameExtension(title, extFromURL));
|
||||
final String filesizeStr = br.getRegex("(?i)File Size\\s*:\\s*</td><td [^>]*><span [^>]*>(\\d+ [^<]+)</span>").getMatch(0);
|
||||
if (filesizeStr != null) {
|
||||
link.setDownloadSize(SizeFormatter.getSize(filesizeStr));
|
||||
} else if (!StringUtils.isEmpty(dllink) && !isDownload) {
|
||||
URLConnectionAdapter con = null;
|
||||
try {
|
||||
con.disconnect();
|
||||
} catch (final Throwable e) {
|
||||
con = br.openHeadConnection(this.dllink);
|
||||
handleConnectionErrors(br, con);
|
||||
if (con.getCompleteContentLength() > 0) {
|
||||
link.setVerifiedFileSize(con.getCompleteContentLength());
|
||||
}
|
||||
final String ext = Plugin.getExtensionFromMimeTypeStatic(con.getContentType());
|
||||
if (ext != null) {
|
||||
link.setFinalFileName(this.correctOrApplyFileNameExtension(title, "." + ext));
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
con.disconnect();
|
||||
} catch (final Throwable e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return AvailableStatus.TRUE;
|
||||
@ -101,25 +132,26 @@ public class AnimegalleriesNet extends antiDDoSForHost {
|
||||
|
||||
@Override
|
||||
public void handleFree(final DownloadLink link) throws Exception {
|
||||
requestFileInformation(link);
|
||||
dl = jd.plugins.BrowserAdapter.openDownload(br, link, dllink, free_resume, free_maxchunks);
|
||||
if (!this.looksLikeDownloadableContent(dl.getConnection())) {
|
||||
br.followConnection(true);
|
||||
if (dl.getConnection().getResponseCode() == 403) {
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error 403", 60 * 60 * 1000l);
|
||||
} else if (dl.getConnection().getResponseCode() == 404) {
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error 404", 60 * 60 * 1000l);
|
||||
} else {
|
||||
/* 2020-11-17: WTF happens randomly */
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Unknown server error", 1 * 60 * 1000l);
|
||||
}
|
||||
requestFileInformation(link, true);
|
||||
if (StringUtils.isEmpty(dllink)) {
|
||||
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
|
||||
}
|
||||
dl = jd.plugins.BrowserAdapter.openDownload(br, link, dllink, free_resume, free_maxchunks);
|
||||
handleConnectionErrors(br, dl.getConnection());
|
||||
dl.startDownload();
|
||||
}
|
||||
|
||||
// for the decrypter, so we have only one session of antiddos
|
||||
public void getPage(final String url) throws Exception {
|
||||
super.getPage(url);
|
||||
private void handleConnectionErrors(final Browser br, final URLConnectionAdapter con) throws PluginException, IOException {
|
||||
if (!this.looksLikeDownloadableContent(con)) {
|
||||
br.followConnection(true);
|
||||
if (con.getResponseCode() == 403) {
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error 403", 60 * 60 * 1000l);
|
||||
} else if (con.getResponseCode() == 404) {
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error 404", 60 * 60 * 1000l);
|
||||
} else {
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Image broken?");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -17,6 +17,9 @@ package jd.plugins.hoster;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.appwork.utils.StringUtils;
|
||||
import org.jdownloader.plugins.controller.LazyPlugin;
|
||||
|
||||
import jd.PluginWrapper;
|
||||
import jd.http.Browser;
|
||||
import jd.http.URLConnectionAdapter;
|
||||
@ -26,6 +29,7 @@ import jd.plugins.DownloadLink;
|
||||
import jd.plugins.DownloadLink.AvailableStatus;
|
||||
import jd.plugins.HostPlugin;
|
||||
import jd.plugins.LinkStatus;
|
||||
import jd.plugins.Plugin;
|
||||
import jd.plugins.PluginException;
|
||||
import jd.plugins.PluginForHost;
|
||||
import jd.plugins.components.SiteType.SiteTemplate;
|
||||
@ -36,6 +40,11 @@ public class GelbooruCom extends PluginForHost {
|
||||
super(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public LazyPlugin.FEATURE[] getFeatures() {
|
||||
return new LazyPlugin.FEATURE[] { LazyPlugin.FEATURE.IMAGE_GALLERY, LazyPlugin.FEATURE.IMAGE_HOST };
|
||||
}
|
||||
|
||||
/* DEV NOTES */
|
||||
// Tags:
|
||||
// protocol: no https
|
||||
@ -65,25 +74,31 @@ public class GelbooruCom extends PluginForHost {
|
||||
return new Regex(link.getPluginPatternMatcher(), this.getSupportedLinks()).getMatch(0);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public AvailableStatus requestFileInformation(final DownloadLink link) throws IOException, PluginException {
|
||||
return requestFileInformation(link, false);
|
||||
}
|
||||
|
||||
private AvailableStatus requestFileInformation(final DownloadLink link, final boolean isDownload) throws IOException, PluginException {
|
||||
dllink = null;
|
||||
this.setBrowserExclusive();
|
||||
br.setFollowRedirects(true);
|
||||
br.setCookie(getHost(), "fringeBenefits", "yup");
|
||||
final String url_filename = new Regex(link.getPluginPatternMatcher(), "id=(\\d+)$").getMatch(0);
|
||||
link.setName(url_filename);
|
||||
br.getPage(link.getDownloadURL());
|
||||
final String extDefault = ".jpg";
|
||||
final String fid = this.getFID(link);
|
||||
if (!link.isNameSet()) {
|
||||
link.setName(fid + extDefault);
|
||||
}
|
||||
br.getPage(link.getPluginPatternMatcher());
|
||||
if (br.getHttpConnection().getResponseCode() == 404 || !this.br.getURL().contains(this.getFID(link))) {
|
||||
throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
String filename = br.getRegex("<title>([^<>\"]+) - Image View -.*?</title>").getMatch(0);
|
||||
if (filename != null && false) {
|
||||
String title = br.getRegex("(?i)<title>([^<>\"]+) - Image View -.*?</title>").getMatch(0);
|
||||
if (title != null && false) {
|
||||
// filename can be too long
|
||||
filename = url_filename + "_" + filename;
|
||||
title = fid + "_" + title;
|
||||
} else {
|
||||
filename = url_filename;
|
||||
title = fid;
|
||||
}
|
||||
dllink = br.getRegex("<a href=\"([^<>\"\\']+)\"[^<>]+>Original image</a>").getMatch(0);
|
||||
if (dllink == null) {
|
||||
@ -103,8 +118,8 @@ public class GelbooruCom extends PluginForHost {
|
||||
dllink = br.getRegex("<\\s*source\\s+[^>]*src\\s*=\\s*(\"|'|)(.*?)\\1").getMatch(1);
|
||||
}
|
||||
}
|
||||
if (filename == null || dllink == null) {
|
||||
logger.info("filename: " + filename + " dllink: " + dllink);
|
||||
if (title == null || dllink == null) {
|
||||
logger.info("filename: " + title + " dllink: " + dllink);
|
||||
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
|
||||
}
|
||||
if (dllink.startsWith("//")) {
|
||||
@ -113,31 +128,30 @@ public class GelbooruCom extends PluginForHost {
|
||||
dllink = "https://" + dllink;
|
||||
}
|
||||
dllink = Encoding.htmlDecode(dllink);
|
||||
filename = Encoding.htmlDecode(filename);
|
||||
filename = filename.trim();
|
||||
filename = encodeUnicode(filename);
|
||||
final String ext = getFileNameExtensionFromString(dllink, ".jpg");
|
||||
if (!filename.endsWith(ext)) {
|
||||
filename += ext;
|
||||
}
|
||||
link.setFinalFileName(filename);
|
||||
final Browser br2 = br.cloneBrowser();
|
||||
// In case the link redirects to the finallink
|
||||
br2.setFollowRedirects(true);
|
||||
URLConnectionAdapter con = null;
|
||||
try {
|
||||
con = br2.openHeadConnection(dllink);
|
||||
if (this.looksLikeDownloadableContent(con)) {
|
||||
title = Encoding.htmlDecode(title);
|
||||
title = title.trim();
|
||||
final String extFromURL = getFileNameExtensionFromString(dllink, extDefault);
|
||||
link.setFinalFileName(this.correctOrApplyFileNameExtension(title, extFromURL));
|
||||
if (!StringUtils.isEmpty(dllink)) {
|
||||
final Browser br2 = br.cloneBrowser();
|
||||
// In case the link redirects to the finallink
|
||||
br2.setFollowRedirects(true);
|
||||
URLConnectionAdapter con = null;
|
||||
try {
|
||||
con = br2.openHeadConnection(this.dllink);
|
||||
handleConnectionErrors(br2, con);
|
||||
if (con.getCompleteContentLength() > 0) {
|
||||
link.setVerifiedFileSize(con.getCompleteContentLength());
|
||||
}
|
||||
} else {
|
||||
throw new PluginException(LinkStatus.ERROR_FILE_NOT_FOUND);
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
con.disconnect();
|
||||
} catch (final Throwable e) {
|
||||
final String ext = Plugin.getExtensionFromMimeTypeStatic(con.getContentType());
|
||||
if (ext != null) {
|
||||
link.setFinalFileName(this.correctOrApplyFileNameExtension(title, "." + ext));
|
||||
}
|
||||
} finally {
|
||||
try {
|
||||
con.disconnect();
|
||||
} catch (final Throwable e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
return AvailableStatus.TRUE;
|
||||
@ -145,19 +159,26 @@ public class GelbooruCom extends PluginForHost {
|
||||
|
||||
@Override
|
||||
public void handleFree(final DownloadLink link) throws Exception {
|
||||
requestFileInformation(link);
|
||||
requestFileInformation(link, true);
|
||||
if (StringUtils.isEmpty(dllink)) {
|
||||
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
|
||||
}
|
||||
dl = jd.plugins.BrowserAdapter.openDownload(br, link, dllink, free_resume, free_maxchunks);
|
||||
if (!this.looksLikeDownloadableContent(dl.getConnection())) {
|
||||
handleConnectionErrors(br, dl.getConnection());
|
||||
dl.startDownload();
|
||||
}
|
||||
|
||||
private void handleConnectionErrors(final Browser br, final URLConnectionAdapter con) throws PluginException, IOException {
|
||||
if (!this.looksLikeDownloadableContent(con)) {
|
||||
br.followConnection(true);
|
||||
if (dl.getConnection().getResponseCode() == 403) {
|
||||
if (con.getResponseCode() == 403) {
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error 403", 60 * 60 * 1000l);
|
||||
} else if (dl.getConnection().getResponseCode() == 404) {
|
||||
} else if (con.getResponseCode() == 404) {
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Server error 404", 60 * 60 * 1000l);
|
||||
} else {
|
||||
throw new PluginException(LinkStatus.ERROR_PLUGIN_DEFECT);
|
||||
throw new PluginException(LinkStatus.ERROR_TEMPORARILY_UNAVAILABLE, "Image broken?");
|
||||
}
|
||||
}
|
||||
dl.startDownload();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -231,7 +231,6 @@ public class OkRu extends PluginForHost {
|
||||
}
|
||||
if (title != null) {
|
||||
title = Encoding.htmlDecode(title).trim();
|
||||
title = encodeUnicode(title);
|
||||
link.setFinalFileName(this.correctOrApplyFileNameExtension(title, extDefault));
|
||||
}
|
||||
// final String url_quality = new Regex(dllink, "(st.mq=\\d+)").getMatch(0);
|
||||
|
@ -1016,7 +1016,6 @@ public class PornHubCom extends PluginForHost {
|
||||
}
|
||||
if (site_title != null) {
|
||||
site_title = Encoding.htmlDecode(site_title);
|
||||
site_title = plugin.encodeUnicode(site_title);
|
||||
site_title = site_title.trim();
|
||||
}
|
||||
return site_title;
|
||||
|
Loading…
Reference in New Issue
Block a user