PornHubCom:

-updated getFirstPageWithAccount to auto learn new accessAge cookies
build>full

git-svn-id: svn://svn.jdownloader.org/jdownloader/trunk@48037 ebf7c1c2-ba36-0410-9fe8-c592906822b4

Former-commit-id: e38936c2dfacd9bf9013e9d3efce7793a5549c3a
This commit is contained in:
jiaz 2023-07-21 17:52:13 +00:00
parent a3a2b95462
commit d723c3c076
3 changed files with 74 additions and 40 deletions

View File

@ -38,23 +38,6 @@ import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager; import javax.script.ScriptEngineManager;
import javax.script.ScriptException; import javax.script.ScriptException;
import org.appwork.storage.JSonMapperException;
import org.appwork.storage.JSonStorage;
import org.appwork.storage.TypeRef;
import org.appwork.utils.ReflectionUtils;
import org.appwork.utils.StringUtils;
import org.appwork.utils.net.httpconnection.HTTPConnection;
import org.appwork.utils.net.httpconnection.SSLSocketStreamOptions;
import org.appwork.utils.net.httpconnection.SSLSocketStreamOptionsModifier;
import org.jdownloader.downloader.hls.HLSDownloader;
import org.jdownloader.downloader.hls.M3U8Playlist;
import org.jdownloader.gui.translate._GUI;
import org.jdownloader.logging.LogController;
import org.jdownloader.net.BCSSLSocketStreamFactory;
import org.jdownloader.plugins.components.hls.HlsContainer;
import org.jdownloader.plugins.controller.LazyPlugin;
import org.jdownloader.scripting.JavaScriptEngineFactory;
import jd.PluginWrapper; import jd.PluginWrapper;
import jd.config.ConfigContainer; import jd.config.ConfigContainer;
import jd.config.ConfigEntry; import jd.config.ConfigEntry;
@ -86,6 +69,23 @@ import jd.plugins.PluginException;
import jd.plugins.PluginForHost; import jd.plugins.PluginForHost;
import jd.plugins.decrypter.PornHubComVideoCrawler; import jd.plugins.decrypter.PornHubComVideoCrawler;
import org.appwork.storage.JSonMapperException;
import org.appwork.storage.JSonStorage;
import org.appwork.storage.TypeRef;
import org.appwork.utils.ReflectionUtils;
import org.appwork.utils.StringUtils;
import org.appwork.utils.net.httpconnection.HTTPConnection;
import org.appwork.utils.net.httpconnection.SSLSocketStreamOptions;
import org.appwork.utils.net.httpconnection.SSLSocketStreamOptionsModifier;
import org.jdownloader.downloader.hls.HLSDownloader;
import org.jdownloader.downloader.hls.M3U8Playlist;
import org.jdownloader.gui.translate._GUI;
import org.jdownloader.logging.LogController;
import org.jdownloader.net.BCSSLSocketStreamFactory;
import org.jdownloader.plugins.components.hls.HlsContainer;
import org.jdownloader.plugins.controller.LazyPlugin;
import org.jdownloader.scripting.JavaScriptEngineFactory;
@HostPlugin(revision = "$Revision$", interfaceVersion = 3, names = {}, urls = {}) @HostPlugin(revision = "$Revision$", interfaceVersion = 3, names = {}, urls = {})
@PluginDependencies(dependencies = { PornHubComVideoCrawler.class }) @PluginDependencies(dependencies = { PornHubComVideoCrawler.class })
public class PornHubCom extends PluginForHost { public class PornHubCom extends PluginForHost {
@ -360,19 +360,43 @@ public class PornHubCom extends PluginForHost {
} }
public static Request getFirstPageWithAccount(final PornHubCom plg, final Account account, final String url) throws Exception { public static Request getFirstPageWithAccount(final PornHubCom plg, final Account account, final String url) throws Exception {
if (account == null) { synchronized (DEFAULT_COOKIES) {
return getPage(plg.getBrowser(), url); final Browser br = plg.getBrowser();
} else { if (account == null) {
synchronized (account) { while (true) {
final boolean verifiedLogin = plg.login(account, false); final Request request = getPage(br, url);
final Request request = getPage(plg.getBrowser(), url); final String accessAgeCookie[] = new Regex(request.getHtmlCode(), "setCookieAdvanced\\s*\\(\\s*'(accessAge[^']+)'\\s*,\\s*([^,]+),").getRow(0);
if (!isLoggedInHtml(plg.getBrowser())) { if (accessAgeCookie != null) {
plg.getLogger().info("Not logged in?|VerifiedLogin:" + verifiedLogin); if (!DEFAULT_COOKIES.containsKey(accessAgeCookie[0])) {
plg.login(account, true); plg.getLogger().info("Auto-Learn new accessAge cookie:" + Arrays.toString(accessAgeCookie));
return getPage(plg.getBrowser(), url); DEFAULT_COOKIES.put(accessAgeCookie[0], accessAgeCookie[1].trim());
} else { setDefaultCookies(br, br.getBaseURL());
continue;
}
}
return request; return request;
} }
} else {
while (true) {
final boolean verifiedLogin = plg.login(account, false);
final Request request = getPage(br, url);
final String accessAgeCookie[] = new Regex(request.getHtmlCode(), "setCookieAdvanced\\s*\\(\\s*'(accessAge[^']+)'\\s*,\\s*([^,]+),").getRow(0);
if (accessAgeCookie != null) {
if (!DEFAULT_COOKIES.containsKey(accessAgeCookie[0])) {
plg.getLogger().info("Auto-Learn new accessAge cookie:" + Arrays.toString(accessAgeCookie));
DEFAULT_COOKIES.put(accessAgeCookie[0], accessAgeCookie[1].trim());
setDefaultCookies(br, br.getBaseURL());
continue;
}
}
if (!isLoggedInHtml(br)) {
plg.getLogger().info("Not logged in?|VerifiedLogin:" + verifiedLogin);
plg.login(account, true);
continue;
} else {
return request;
}
}
} }
} }
} }
@ -1217,8 +1241,8 @@ public class PornHubCom extends PluginForHost {
if (premiumExpired && !isPremiumDomain(br.getHost())) { if (premiumExpired && !isPremiumDomain(br.getHost())) {
/** /**
* Expired pornhub premium --> It should still be a valid free account --> We might need to access a special url * Expired pornhub premium --> It should still be a valid free account --> We might need to access a special url
* which redirects us to the pornhub free mainpage and sets the cookies. </br> * which redirects us to the pornhub free mainpage and sets the cookies. </br> 2022-06-27: Old code but let's leave
* 2022-06-27: Old code but let's leave it in for now as we can't know if it is still needed. * it in for now as we can't know if it is still needed.
*/ */
logger.info("Expired premium --> Free account (?)"); logger.info("Expired premium --> Free account (?)");
final String pornhubMainpageCookieRedirectUrl = br.getRegex("\\'pornhubLink\\'\\s*?:\\s*?(?:\"|\\')(https?://(?:www\\.)?pornhub\\.(?:com|org)/[^<>\"\\']+)(?:\"|\\')").getMatch(0); final String pornhubMainpageCookieRedirectUrl = br.getRegex("\\'pornhubLink\\'\\s*?:\\s*?(?:\"|\\')(https?://(?:www\\.)?pornhub\\.(?:com|org)/[^<>\"\\']+)(?:\"|\\')").getMatch(0);
@ -1271,8 +1295,7 @@ public class PornHubCom extends PluginForHost {
} }
/** /**
* Checks login and sets account-type. </br> * Checks login and sets account-type. </br> Expects browser instance to be logged in already (cookies need to be there).
* Expects browser instance to be logged in already (cookies need to be there).
* *
* @throws Exception * @throws Exception
*/ */
@ -1568,12 +1591,23 @@ public class PornHubCom extends PluginForHost {
return br; return br;
} }
private static Map<String, String> DEFAULT_COOKIES = new HashMap<String, String>();
static {
synchronized (DEFAULT_COOKIES) {
DEFAULT_COOKIES.put("accessAgeDisclaimerPH", "1");
DEFAULT_COOKIES.put("accessAgeDisclaimerUK", "1");// 2023-07-19
/* 2023-04-14: STATE OF UTAH WARNING */
DEFAULT_COOKIES.put("accessPH", "1");
}
}
private static void setDefaultCookies(final Browser br, final String domain) { private static void setDefaultCookies(final Browser br, final String domain) {
br.setCookie(domain, "cookiesBannerSeen", "1"); br.setCookie(domain, "cookiesBannerSeen", "1");
br.setCookie(domain, "accessAgeDisclaimerPH", "1"); synchronized (DEFAULT_COOKIES) {
br.setCookie(domain, "accessAgeDisclaimerUK", "1"); // 2023-07-19 for (Map.Entry<String, String> defaultCookie : DEFAULT_COOKIES.entrySet()) {
/* 2023-04-14: STATE OF UTAH WARNING */ br.setCookie(domain, defaultCookie.getKey(), defaultCookie.getValue());
br.setCookie(domain, "accessPH", "1"); }
}
} }
private static void setEnglishLangCookie(final Browser br, final String domain) { private static void setEnglishLangCookie(final Browser br, final String domain) {

View File

@ -158,7 +158,7 @@ public abstract class LazyPlugin<T extends Plugin> implements MinTimeWeakReferen
COOKIE_LOGIN_ONLY { COOKIE_LOGIN_ONLY {
@Override @Override
public String getLabel() { public String getLabel() {
return _JDT.T.LazyHostPlugin_FEATURE_COOKIE_ONLY(); return _JDT.T.LazyHostPlugin_FEATURE_COOKIE_LOGIN_ONLY();
} }
@Override @Override
@ -174,7 +174,7 @@ public abstract class LazyPlugin<T extends Plugin> implements MinTimeWeakReferen
@Override @Override
public String getTooltip() { public String getTooltip() {
return _JDT.T.LazyHostPlugin_FEATURE_COOKIE_OPTIONAL_TOOLTIP(); return _JDT.T.LazyHostPlugin_FEATURE_COOKIE_LOGIN_OPTIONAL_TOOLTIP();
} }
}; };
public static final long CACHEVERSION = Math.abs(StringUtils.join(values(), "<->").hashCode()) + Math.abs(StringUtils.join(values(), ":").hashCode()) + Math.abs(StringUtils.join(values(), "<=>").hashCode()); public static final long CACHEVERSION = Math.abs(StringUtils.join(values(), "<->").hashCode()) + Math.abs(StringUtils.join(values(), ":").hashCode()) + Math.abs(StringUtils.join(values(), "<=>").hashCode());

View File

@ -1078,10 +1078,10 @@ public interface JdownloaderTranslation extends TranslateInterface {
String LazyHostPlugin_FEATURE_COOKIE_LOGIN_OPTIONAL(); String LazyHostPlugin_FEATURE_COOKIE_LOGIN_OPTIONAL();
@Default(lngs = { "en" }, values = { "This plugin also supports login via cookies" }) @Default(lngs = { "en" }, values = { "This plugin also supports login via cookies" })
String LazyHostPlugin_FEATURE_COOKIE_OPTIONAL_TOOLTIP(); String LazyHostPlugin_FEATURE_COOKIE_LOGIN_OPTIONAL_TOOLTIP();
@Default(lngs = { "en" }, values = { "Cookie login only" }) @Default(lngs = { "en" }, values = { "Cookie login only" })
String LazyHostPlugin_FEATURE_COOKIE_ONLY(); String LazyHostPlugin_FEATURE_COOKIE_LOGIN_ONLY();
@Default(lngs = { "en" }, values = { "This plugin only supports login via cookies" }) @Default(lngs = { "en" }, values = { "This plugin only supports login via cookies" })
String LazyHostPlugin_FEATURE_COOKIE_LOGIN_ONLY_TOOLTIP(); String LazyHostPlugin_FEATURE_COOKIE_LOGIN_ONLY_TOOLTIP();