Reduce use of Config.getInstance()
This commit is contained in:
parent
6dd2779cf4
commit
805097c7ec
|
@ -124,7 +124,7 @@ public class CamrecApplication extends Application {
|
|||
});
|
||||
|
||||
logEnvironment();
|
||||
initSites();
|
||||
createSites();
|
||||
loadConfig();
|
||||
registerAlertSystem();
|
||||
registerActiveRecordingsCounter();
|
||||
|
@ -132,6 +132,7 @@ public class CamrecApplication extends Application {
|
|||
createHttpClient();
|
||||
hostServices = getHostServices();
|
||||
createRecorder();
|
||||
initSites();
|
||||
startOnlineMonitor();
|
||||
createGui(primaryStage);
|
||||
checkForUpdates();
|
||||
|
@ -166,7 +167,7 @@ public class CamrecApplication extends Application {
|
|||
});
|
||||
}
|
||||
|
||||
private void initSites() {
|
||||
private void createSites() {
|
||||
sites.add(new AmateurTv());
|
||||
sites.add(new BongaCams());
|
||||
sites.add(new Cam4());
|
||||
|
@ -190,17 +191,21 @@ public class CamrecApplication extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
private void startOnlineMonitor() {
|
||||
private void initSites() {
|
||||
for (Site site : sites) {
|
||||
if (site.isEnabled()) {
|
||||
try {
|
||||
site.setRecorder(recorder);
|
||||
site.setConfig(config);
|
||||
site.init();
|
||||
} catch (Exception e) {
|
||||
LOG.error("Error while initializing site {}", site.getName(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void startOnlineMonitor() {
|
||||
onlineMonitor = new OnlineMonitor(recorder, config);
|
||||
onlineMonitor.start();
|
||||
}
|
||||
|
@ -540,7 +545,7 @@ public class CamrecApplication extends Application {
|
|||
}
|
||||
|
||||
private void createHttpClient() {
|
||||
httpClient = new HttpClient("camrec") {
|
||||
httpClient = new HttpClient("camrec", config) {
|
||||
@Override
|
||||
public boolean login() {
|
||||
return false;
|
||||
|
|
|
@ -161,6 +161,11 @@ public class UnknownModel extends AbstractModel {
|
|||
public String getTitle() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfig(Config config) {
|
||||
// noop
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -60,12 +60,14 @@ public abstract class HttpClient {
|
|||
|
||||
protected OkHttpClient client;
|
||||
protected CookieJarImpl cookieJar = new CookieJarImpl();
|
||||
protected Config config;
|
||||
protected boolean loggedIn = false;
|
||||
protected int loginTries = 0;
|
||||
private String name;
|
||||
|
||||
protected HttpClient(String name) {
|
||||
protected HttpClient(String name, Config config) {
|
||||
this.name = name;
|
||||
this.config = config;
|
||||
cookieJar = createCookieJar();
|
||||
reconfigure();
|
||||
}
|
||||
|
@ -75,32 +77,32 @@ public abstract class HttpClient {
|
|||
}
|
||||
|
||||
private void loadProxySettings() {
|
||||
ProxyType proxyType = Config.getInstance().getSettings().proxyType;
|
||||
ProxyType proxyType = config.getSettings().proxyType;
|
||||
switch (proxyType) {
|
||||
case HTTP:
|
||||
System.setProperty("http.proxyHost", Config.getInstance().getSettings().proxyHost);
|
||||
System.setProperty("http.proxyPort", Config.getInstance().getSettings().proxyPort);
|
||||
System.setProperty("https.proxyHost", Config.getInstance().getSettings().proxyHost);
|
||||
System.setProperty("https.proxyPort", Config.getInstance().getSettings().proxyPort);
|
||||
if(Config.getInstance().getSettings().proxyUser != null && !Config.getInstance().getSettings().proxyUser.isEmpty()) {
|
||||
String username = Config.getInstance().getSettings().proxyUser;
|
||||
String password = Config.getInstance().getSettings().proxyPassword;
|
||||
System.setProperty("http.proxyHost", config.getSettings().proxyHost);
|
||||
System.setProperty("http.proxyPort", config.getSettings().proxyPort);
|
||||
System.setProperty("https.proxyHost", config.getSettings().proxyHost);
|
||||
System.setProperty("https.proxyPort", config.getSettings().proxyPort);
|
||||
if(config.getSettings().proxyUser != null && !config.getSettings().proxyUser.isEmpty()) {
|
||||
String username = config.getSettings().proxyUser;
|
||||
String password = config.getSettings().proxyPassword;
|
||||
System.setProperty("http.proxyUser", username);
|
||||
System.setProperty("http.proxyPassword", password);
|
||||
}
|
||||
break;
|
||||
case SOCKS4:
|
||||
System.setProperty("socksProxyVersion", "4");
|
||||
System.setProperty("socksProxyHost", Config.getInstance().getSettings().proxyHost);
|
||||
System.setProperty("socksProxyPort", Config.getInstance().getSettings().proxyPort);
|
||||
System.setProperty("socksProxyHost", config.getSettings().proxyHost);
|
||||
System.setProperty("socksProxyPort", config.getSettings().proxyPort);
|
||||
break;
|
||||
case SOCKS5:
|
||||
System.setProperty("socksProxyVersion", "5");
|
||||
System.setProperty("socksProxyHost", Config.getInstance().getSettings().proxyHost);
|
||||
System.setProperty("socksProxyPort", Config.getInstance().getSettings().proxyPort);
|
||||
if(Config.getInstance().getSettings().proxyUser != null && !Config.getInstance().getSettings().proxyUser.isEmpty()) {
|
||||
String username = Config.getInstance().getSettings().proxyUser;
|
||||
String password = Config.getInstance().getSettings().proxyPassword;
|
||||
System.setProperty("socksProxyHost", config.getSettings().proxyHost);
|
||||
System.setProperty("socksProxyPort", config.getSettings().proxyPort);
|
||||
if(config.getSettings().proxyUser != null && !config.getSettings().proxyUser.isEmpty()) {
|
||||
String username = config.getSettings().proxyUser;
|
||||
String password = config.getSettings().proxyPassword;
|
||||
Authenticator.setDefault(new SocksProxyAuth(username, password));
|
||||
}
|
||||
break;
|
||||
|
@ -141,21 +143,21 @@ public abstract class HttpClient {
|
|||
Builder builder = new OkHttpClient.Builder()
|
||||
.cookieJar(cookieJar)
|
||||
.connectionPool(GLOBAL_HTTP_CONN_POOL)
|
||||
.connectTimeout(Config.getInstance().getSettings().httpTimeout, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(Config.getInstance().getSettings().httpTimeout, TimeUnit.MILLISECONDS);
|
||||
.connectTimeout(config.getSettings().httpTimeout, TimeUnit.MILLISECONDS)
|
||||
.readTimeout(config.getSettings().httpTimeout, TimeUnit.MILLISECONDS);
|
||||
//.addInterceptor(new LoggingInterceptor());
|
||||
|
||||
ProxyType proxyType = Config.getInstance().getSettings().proxyType;
|
||||
ProxyType proxyType = config.getSettings().proxyType;
|
||||
if (proxyType == ProxyType.HTTP) {
|
||||
String username = Config.getInstance().getSettings().proxyUser;
|
||||
String password = Config.getInstance().getSettings().proxyPassword;
|
||||
String username = config.getSettings().proxyUser;
|
||||
String password = config.getSettings().proxyPassword;
|
||||
if (username != null && !username.isEmpty()) {
|
||||
builder.proxyAuthenticator(createHttpProxyAuthenticator(username, password));
|
||||
}
|
||||
}
|
||||
|
||||
// if transport layer security (TLS) is switched on, accept the self signed cert from the server
|
||||
if (Config.getInstance().getSettings().transportLayerSecurity) {
|
||||
if (config.getSettings().transportLayerSecurity) {
|
||||
acceptAllTlsCerts(builder);
|
||||
}
|
||||
|
||||
|
@ -209,7 +211,7 @@ public abstract class HttpClient {
|
|||
JsonAdapter<CookieContainer> adapter = moshi.adapter(CookieContainer.class).indent(" ");
|
||||
String json = adapter.toJson(cookies);
|
||||
|
||||
File cookieFile = new File(Config.getInstance().getConfigDir(), "cookies-" + name + ".json");
|
||||
File cookieFile = new File(config.getConfigDir(), "cookies-" + name + ".json");
|
||||
try(FileOutputStream fout = new FileOutputStream(cookieFile)) {
|
||||
fout.write(json.getBytes(UTF_8));
|
||||
}
|
||||
|
@ -220,7 +222,7 @@ public abstract class HttpClient {
|
|||
|
||||
private void loadCookies() {
|
||||
try {
|
||||
File cookieFile = new File(Config.getInstance().getConfigDir(), "cookies-" + name + ".json");
|
||||
File cookieFile = new File(config.getConfigDir(), "cookies-" + name + ".json");
|
||||
if(!cookieFile.exists()) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -2,12 +2,13 @@ package ctbrec.recorder;
|
|||
|
||||
import java.io.IOException;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.io.HttpClient;
|
||||
|
||||
public class RecorderHttpClient extends HttpClient {
|
||||
|
||||
public RecorderHttpClient() {
|
||||
super("recorder");
|
||||
public RecorderHttpClient(Config config) {
|
||||
super("recorder", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,6 +4,7 @@ import java.io.IOException;
|
|||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.recorder.Recorder;
|
||||
|
||||
|
@ -11,6 +12,7 @@ public abstract class AbstractSite implements Site {
|
|||
|
||||
private boolean enabled;
|
||||
private Recorder recorder;
|
||||
private Config config;
|
||||
|
||||
@Override
|
||||
public void setEnabled(boolean enabled) {
|
||||
|
@ -56,4 +58,13 @@ public abstract class AbstractSite implements Site {
|
|||
public String getTitle() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setConfig(Config config) {
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
protected Config getConfig() {
|
||||
return config;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package ctbrec.sites;
|
|||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.recorder.Recorder;
|
||||
|
@ -31,4 +32,5 @@ public interface Site {
|
|||
public List<Model> search(String q) throws IOException, InterruptedException;
|
||||
public boolean searchRequiresLogin();
|
||||
public Model createModelFromUrl(String url);
|
||||
public void setConfig(Config config);
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.List;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.sites.AbstractSite;
|
||||
|
@ -61,7 +60,7 @@ public class AmateurTv extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new AmateurTvHttpClient();
|
||||
httpClient = new AmateurTvHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -105,7 +104,7 @@ public class AmateurTv extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().amateurTvUsername;
|
||||
String username = getConfig().getSettings().amateurTvUsername;
|
||||
return username != null && !username.trim().isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -15,8 +15,8 @@ import okhttp3.Response;
|
|||
|
||||
public class AmateurTvHttpClient extends HttpClient {
|
||||
|
||||
public AmateurTvHttpClient() {
|
||||
super("amateurtv");
|
||||
public AmateurTvHttpClient(Config config) {
|
||||
super("amateurtv", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
|
@ -36,7 +35,7 @@ public class BongaCams extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
baseUrl = Config.getInstance().getSettings().bongacamsBaseUrl;
|
||||
baseUrl = getConfig().getSettings().bongacamsBaseUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -74,7 +73,7 @@ public class BongaCams extends AbstractSite {
|
|||
.build();
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.addHeader(REFERER, BongaCams.baseUrl)
|
||||
|
@ -109,7 +108,7 @@ public class BongaCams extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new BongaCamsHttpClient();
|
||||
httpClient = new BongaCamsHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -146,7 +145,7 @@ public class BongaCams extends AbstractSite {
|
|||
String url = baseUrl + "/tools/listing_v3.php?offset=0&model_search[display_name][text]=" + URLEncoder.encode(q, "utf-8");
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.addHeader(REFERER, BongaCams.baseUrl)
|
||||
|
@ -191,7 +190,7 @@ public class BongaCams extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().bongaUsername;
|
||||
String username = getConfig().getSettings().bongaUsername;
|
||||
return username != null && !username.trim().isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,8 +29,8 @@ public class BongaCamsHttpClient extends HttpClient {
|
|||
private static final String SORT_COOKIE = "ls01";
|
||||
private int userId = 0;
|
||||
|
||||
public BongaCamsHttpClient() {
|
||||
super("bongacams");
|
||||
public BongaCamsHttpClient(Config config) {
|
||||
super("bongacams", config);
|
||||
addSortByPopularCookie();
|
||||
}
|
||||
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.regex.Pattern;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.io.HttpClient;
|
||||
|
@ -75,7 +74,7 @@ public class Cam4 extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new Cam4HttpClient();
|
||||
httpClient = new Cam4HttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -127,7 +126,7 @@ public class Cam4 extends AbstractSite {
|
|||
}
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = getHttpClient().execute(req)) {
|
||||
if (response.isSuccessful()) {
|
||||
|
@ -160,7 +159,7 @@ public class Cam4 extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().cam4Username;
|
||||
String username = getConfig().getSettings().cam4Username;
|
||||
return username != null && !username.trim().isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.io.HttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
@ -17,8 +18,8 @@ public class Cam4HttpClient extends HttpClient {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Cam4HttpClient.class);
|
||||
|
||||
public Cam4HttpClient() {
|
||||
super("cam4");
|
||||
public Cam4HttpClient(Config config) {
|
||||
super("cam4", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,7 +15,6 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
|
@ -90,7 +89,7 @@ public class Camsoda extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new CamsodaHttpClient();
|
||||
httpClient = new CamsodaHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -127,7 +126,7 @@ public class Camsoda extends AbstractSite {
|
|||
String url = BASE_URI + "/api/v1/browse/autocomplete?s=" + URLEncoder.encode(q, "utf-8");
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try(Response response = getHttpClient().execute(req)) {
|
||||
if(response.isSuccessful()) {
|
||||
|
@ -165,7 +164,7 @@ public class Camsoda extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().camsodaUsername;
|
||||
String username = getConfig().getSettings().camsodaUsername;
|
||||
return username != null && !username.trim().isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,8 +24,8 @@ public class CamsodaHttpClient extends HttpClient {
|
|||
private static final Pattern CSRF_PATTERN = Pattern.compile("\"csrf\"\\s*:\\s*\"(.*?)\"", MULTILINE | DOTALL);
|
||||
private String csrfToken = null;
|
||||
|
||||
public CamsodaHttpClient() {
|
||||
super("camsoda");
|
||||
public CamsodaHttpClient(Config config) {
|
||||
super("camsoda", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.regex.Pattern;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.io.HtmlParser;
|
||||
|
@ -31,7 +30,7 @@ public class Chaturbate extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
baseUrl = Config.getInstance().getSettings().chaturbateBaseUrl;
|
||||
baseUrl = getConfig().getSettings().chaturbateBaseUrl;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +59,7 @@ public class Chaturbate extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public Double getTokenBalance() throws IOException {
|
||||
String username = Config.getInstance().getSettings().chaturbateUsername;
|
||||
String username = getConfig().getSettings().chaturbateUsername;
|
||||
if (username == null || username.trim().isEmpty()) {
|
||||
throw new IOException("Not logged in");
|
||||
}
|
||||
|
@ -68,7 +67,7 @@ public class Chaturbate extends AbstractSite {
|
|||
String url = "https://chaturbate.com/p/" + username + "/";
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
Response resp = getHttpClient().execute(req);
|
||||
if (resp.isSuccessful()) {
|
||||
|
@ -94,7 +93,7 @@ public class Chaturbate extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new ChaturbateHttpClient();
|
||||
httpClient = new ChaturbateHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -129,7 +128,7 @@ public class Chaturbate extends AbstractSite {
|
|||
// search online models
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
.header(REFERER, getBaseUrl())
|
||||
|
@ -164,7 +163,7 @@ public class Chaturbate extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().chaturbateUsername;
|
||||
String username = getConfig().getSettings().chaturbateUsername;
|
||||
return username != null && !username.trim().isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -28,8 +28,8 @@ public class ChaturbateHttpClient extends HttpClient {
|
|||
private static Semaphore requestThrottle = new Semaphore(2, true);
|
||||
private static long lastRequest = 0;
|
||||
|
||||
public ChaturbateHttpClient() {
|
||||
super("chaturbate");
|
||||
public ChaturbateHttpClient(Config config) {
|
||||
super("chaturbate", config);
|
||||
}
|
||||
|
||||
private void extractCsrfToken(Request request) {
|
||||
|
|
|
@ -23,8 +23,8 @@ public class Fc2HttpClient extends HttpClient {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Fc2HttpClient.class);
|
||||
|
||||
public Fc2HttpClient() {
|
||||
super("fc2live");
|
||||
public Fc2HttpClient(Config config) {
|
||||
super("fc2live", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,7 +4,6 @@ import java.io.IOException;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.sites.AbstractSite;
|
||||
|
@ -74,13 +73,14 @@ public class Fc2Live extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new Fc2HttpClient();
|
||||
httpClient = new Fc2HttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
// noop
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -107,7 +107,7 @@ public class Fc2Live extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
return !Config.getInstance().getSettings().fc2liveUsername.isEmpty();
|
||||
return !getConfig().getSettings().fc2liveUsername.isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import java.util.regex.Pattern;
|
|||
import org.jsoup.nodes.Element;
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HtmlParser;
|
||||
import ctbrec.io.HttpClient;
|
||||
|
@ -66,7 +65,7 @@ public class Flirt4Free extends AbstractSite {
|
|||
String url = Flirt4Free.BASE_URI + "/my-account/";
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try(Response response = getHttpClient().execute(request)) {
|
||||
if(response.isSuccessful()) {
|
||||
|
@ -87,7 +86,7 @@ public class Flirt4Free extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new Flirt4FreeHttpClient();
|
||||
httpClient = new Flirt4FreeHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -124,7 +123,7 @@ public class Flirt4Free extends AbstractSite {
|
|||
String url = BASE_URI + "/search/?query=" + URLEncoder.encode(q, "utf-8");
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = getHttpClient().execute(req)) {
|
||||
if (response.isSuccessful()) {
|
||||
|
@ -155,7 +154,7 @@ public class Flirt4Free extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().flirt4freeUsername;
|
||||
String username = getConfig().getSettings().flirt4freeUsername;
|
||||
return username != null && !username.trim().isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ public class Flirt4FreeHttpClient extends HttpClient {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(Flirt4FreeHttpClient.class);
|
||||
|
||||
public Flirt4FreeHttpClient() {
|
||||
super("flirt4free");
|
||||
public Flirt4FreeHttpClient(Config config) {
|
||||
super("flirt4free", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,6 @@ import org.jsoup.select.Elements;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.NotLoggedInExcetion;
|
||||
import ctbrec.io.HtmlParser;
|
||||
|
@ -67,7 +66,7 @@ public class LiveJasmin extends AbstractSite {
|
|||
String sessionId = getLiveJasminHttpClient().getSessionId();
|
||||
String url = getBaseUrl() + "/en/offline-surprise/get-member-balance?session=" + sessionId;
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.addHeader(ACCEPT, "*/*")
|
||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.addHeader(REFERER, getBaseUrl())
|
||||
|
@ -104,14 +103,14 @@ public class LiveJasmin extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new LiveJasminHttpClient();
|
||||
httpClient = new LiveJasminHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
baseUrl = Config.getInstance().getSettings().livejasminBaseUrl;
|
||||
baseUrl = getConfig().getSettings().livejasminBaseUrl;
|
||||
HttpUrl url = HttpUrl.parse(baseUrl);
|
||||
baseDomain = url.topPrivateDomain();
|
||||
}
|
||||
|
@ -144,7 +143,7 @@ public class LiveJasmin extends AbstractSite {
|
|||
long ts = System.currentTimeMillis();
|
||||
String url = getBaseUrl() + "/en/auto-suggest-search/auto-suggest?category=girls&searchText=" + query + "&_dc=" + ts + "&appletType=html5";
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.addHeader(ACCEPT, "*/*")
|
||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.addHeader(REFERER, getBaseUrl())
|
||||
|
@ -189,7 +188,7 @@ public class LiveJasmin extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
return !Config.getInstance().getSettings().livejasminUsername.isEmpty();
|
||||
return !getConfig().getSettings().livejasminUsername.isEmpty();
|
||||
}
|
||||
|
||||
private LiveJasminHttpClient getLiveJasminHttpClient() {
|
||||
|
|
|
@ -19,10 +19,10 @@ import okhttp3.Response;
|
|||
|
||||
public class LiveJasminHttpClient extends HttpClient {
|
||||
|
||||
private static final transient Logger LOG = LoggerFactory.getLogger(LiveJasminHttpClient.class);
|
||||
private static final Logger LOG = LoggerFactory.getLogger(LiveJasminHttpClient.class);
|
||||
|
||||
protected LiveJasminHttpClient() {
|
||||
super("livejasmin");
|
||||
protected LiveJasminHttpClient(Config config) {
|
||||
super("livejasmin", config);
|
||||
|
||||
// delete all cookies, if we are guests, because old guest sessions cause
|
||||
// endless redirects
|
||||
|
|
|
@ -18,7 +18,6 @@ import org.jsoup.select.Elements;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.Model.State;
|
||||
import ctbrec.io.HtmlParser;
|
||||
|
@ -82,7 +81,7 @@ public class MVLive extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if(httpClient == null) {
|
||||
httpClient = new MVLiveHttpClient();
|
||||
httpClient = new MVLiveHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -122,7 +121,7 @@ public class MVLive extends AbstractSite {
|
|||
public List<Model> getModels() throws IOException {
|
||||
Request request = new Request.Builder()
|
||||
.url(getBaseUrl())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.header(REFERER, MVLive.BASE_URL)
|
||||
.build();
|
||||
try (Response response = getHttpClient().execute(request)) {
|
||||
|
@ -186,7 +185,7 @@ public class MVLive extends AbstractSite {
|
|||
if (mvtoken == null) {
|
||||
Request request = new Request.Builder()
|
||||
.url("https://www.manyvids.com/")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = getHttpClient().execute(request)) {
|
||||
if (response.isSuccessful()) {
|
||||
|
@ -213,7 +212,7 @@ public class MVLive extends AbstractSite {
|
|||
.url("https://www.manyvids.com/includes/filterSearch.php")
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.header(ORIGIN, MVLive.BASE_URL)
|
||||
.header(REFERER, MVLive.BASE_URL)
|
||||
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
|
|
|
@ -12,8 +12,8 @@ import okhttp3.Response;
|
|||
|
||||
public class MVLiveHttpClient extends HttpClient {
|
||||
|
||||
public MVLiveHttpClient() {
|
||||
super("mvlive");
|
||||
public MVLiveHttpClient(Config config) {
|
||||
super("mvlive", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,7 +22,7 @@ public class MVLiveHttpClient extends HttpClient {
|
|||
}
|
||||
|
||||
public MVLiveHttpClient newSession() {
|
||||
MVLiveHttpClient newClient = new MVLiveHttpClient();
|
||||
MVLiveHttpClient newClient = new MVLiveHttpClient(config);
|
||||
newClient.client = newClient.client.newBuilder()
|
||||
.cookieJar(createCookieJar())
|
||||
.build();
|
||||
|
@ -34,7 +34,7 @@ public class MVLiveHttpClient extends HttpClient {
|
|||
public void fetchAuthenticationCookies() throws IOException {
|
||||
Request req = new Request.Builder()
|
||||
.url("https://www.manyvids.com/tak-live-redirect.php")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = execute(req)) {
|
||||
if (!response.isSuccessful()) {
|
||||
|
|
|
@ -10,7 +10,6 @@ import java.util.regex.Pattern;
|
|||
|
||||
import org.jsoup.select.Elements;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HtmlParser;
|
||||
import ctbrec.io.HttpException;
|
||||
|
@ -27,7 +26,7 @@ public class MyFreeCams extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
baseUrl = Config.getInstance().getSettings().mfcBaseUrl;
|
||||
baseUrl = getConfig().getSettings().mfcBaseUrl;
|
||||
client = MyFreeCamsClient.getInstance();
|
||||
client.setSite(this);
|
||||
client.start();
|
||||
|
@ -67,7 +66,7 @@ public class MyFreeCams extends AbstractSite {
|
|||
.url(baseUrl + "/php/account.php?request=status")
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.header(CONNECTION, KEEP_ALIVE)
|
||||
.build();
|
||||
try(Response response = getHttpClient().execute(req)) {
|
||||
|
@ -90,7 +89,7 @@ public class MyFreeCams extends AbstractSite {
|
|||
@Override
|
||||
public MyFreeCamsHttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new MyFreeCamsHttpClient();
|
||||
httpClient = new MyFreeCamsHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -133,7 +132,7 @@ public class MyFreeCams extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().mfcUsername;
|
||||
String username = getConfig().getSettings().mfcUsername;
|
||||
return username != null && !username.trim().isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ public class MyFreeCamsHttpClient extends HttpClient {
|
|||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(MyFreeCamsHttpClient.class);
|
||||
|
||||
public MyFreeCamsHttpClient() {
|
||||
super("myfreecams");
|
||||
public MyFreeCamsHttpClient(Config config) {
|
||||
super("myfreecams", config);
|
||||
client = client.newBuilder()
|
||||
.protocols(Arrays.asList(Protocol.HTTP_1_1))
|
||||
.build();
|
||||
|
@ -51,8 +51,8 @@ public class MyFreeCamsHttpClient extends HttpClient {
|
|||
return true;
|
||||
}
|
||||
|
||||
String username = Config.getInstance().getSettings().mfcUsername;
|
||||
String password = Config.getInstance().getSettings().mfcPassword;
|
||||
String username = config.getSettings().mfcUsername;
|
||||
String password = config.getSettings().mfcPassword;
|
||||
RequestBody body = new FormBody.Builder()
|
||||
.add("username", username)
|
||||
.add("password", password)
|
||||
|
@ -64,7 +64,7 @@ public class MyFreeCamsHttpClient extends HttpClient {
|
|||
.url(MyFreeCams.baseUrl + "/php/login.php")
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(CONNECTION, KEEP_ALIVE)
|
||||
.header(REFERER, MyFreeCams.baseUrl)
|
||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
@ -91,7 +91,7 @@ public class MyFreeCamsHttpClient extends HttpClient {
|
|||
.url(MyFreeCams.baseUrl + "/php/account.php?request=status")
|
||||
.header(ACCEPT, "*/*")
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(CONNECTION, KEEP_ALIVE)
|
||||
.build();
|
||||
try(Response response = execute(req)) {
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
|
@ -74,7 +73,7 @@ public class Showup extends AbstractSite {
|
|||
String url = getBaseUrl() + "/site/get_stream_list/big";
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
|
||||
try (Response response = getHttpClient().execute(req)) {
|
||||
|
@ -131,7 +130,7 @@ public class Showup extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new ShowupHttpClient();
|
||||
httpClient = new ShowupHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
|
|
@ -23,8 +23,8 @@ public class ShowupHttpClient extends HttpClient {
|
|||
|
||||
private String csrfToken;
|
||||
|
||||
protected ShowupHttpClient() {
|
||||
super("showup");
|
||||
protected ShowupHttpClient(Config config) {
|
||||
super("showup", config);
|
||||
setCookie("accept_rules", "true");
|
||||
setCookie("category", "all");
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class ShowupHttpClient extends HttpClient {
|
|||
if (csrfToken == null) {
|
||||
Request req = new Request.Builder()
|
||||
.url(Showup.BASE_URL + "/site/log_in")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.build();
|
||||
|
||||
try (Response response = execute(req)) {
|
||||
|
@ -74,7 +74,7 @@ public class ShowupHttpClient extends HttpClient {
|
|||
@Override
|
||||
public boolean login() throws IOException {
|
||||
return checkLoginSuccess();
|
||||
// Settings settings = Config.getInstance().getSettings();
|
||||
// Settings settings = config.getSettings();
|
||||
// FormBody body = new FormBody.Builder()
|
||||
// .add("is_ajax", "1")
|
||||
// .add("email", settings.showupUsername)
|
||||
|
@ -83,7 +83,7 @@ public class ShowupHttpClient extends HttpClient {
|
|||
// .build();
|
||||
// Request req = new Request.Builder()
|
||||
// .url(Showup.BASE_URL)
|
||||
// .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
// .header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
// .header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
// .header(REFERER, Showup.BASE_URL + '/')
|
||||
// .header(ORIGIN, Showup.BASE_URL)
|
||||
|
@ -110,7 +110,7 @@ public class ShowupHttpClient extends HttpClient {
|
|||
Request req = new Request.Builder()
|
||||
.url(Showup.BASE_URL)
|
||||
.header(ACCEPT_LANGUAGE, "pl")
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = execute(req)) {
|
||||
if (response.isSuccessful()) {
|
||||
|
|
|
@ -16,7 +16,6 @@ import org.json.JSONObject;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.io.HttpClient;
|
||||
|
@ -69,7 +68,7 @@ public class Streamate extends AbstractSite {
|
|||
// .build();
|
||||
// Request request = new Request.Builder()
|
||||
// .url(url)
|
||||
// .addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
// .addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
// .addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
// .addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
// .addHeader(REFERER, Streamate.BASE_URL)
|
||||
|
@ -105,7 +104,7 @@ public class Streamate extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new StreamateHttpClient();
|
||||
httpClient = new StreamateHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -192,7 +191,7 @@ public class Streamate extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().streamateUsername;
|
||||
String username = getConfig().getSettings().streamateUsername;
|
||||
return StringUtil.isNotBlank(username);
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ public class StreamateHttpClient extends HttpClient {
|
|||
private String userNickname = "";
|
||||
private String xsrfToken = null;
|
||||
|
||||
public StreamateHttpClient() {
|
||||
super("streamate");
|
||||
public StreamateHttpClient(Config config) {
|
||||
super("streamate", config);
|
||||
|
||||
// this cookie is needed for the search
|
||||
Cookie searchCookie = new Cookie.Builder()
|
||||
|
@ -62,7 +62,7 @@ public class StreamateHttpClient extends HttpClient {
|
|||
// do a first request to get cookies and stuff
|
||||
Request req = new Request.Builder() //
|
||||
.url(Streamate.BASE_URL + "/initialData.js") //
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent) //
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent) //
|
||||
.header(COOKIE, "smtid="+UUID.randomUUID().toString()+"; Xld_rct=1;") //
|
||||
.header(REFERER, Streamate.BASE_URL)
|
||||
.build();
|
||||
|
@ -101,8 +101,8 @@ public class StreamateHttpClient extends HttpClient {
|
|||
private synchronized boolean loginWithoutCookies() throws IOException {
|
||||
JSONObject loginRequest = new JSONObject();
|
||||
loginRequest.put("allowLoginRedirection", true);
|
||||
loginRequest.put("email", Config.getInstance().getSettings().streamateUsername);
|
||||
loginRequest.put("password", Config.getInstance().getSettings().streamatePassword);
|
||||
loginRequest.put("email", config.getSettings().streamateUsername);
|
||||
loginRequest.put("password", config.getSettings().streamatePassword);
|
||||
loginRequest.put("referrerId", 0);
|
||||
loginRequest.put("siteId", 1);
|
||||
loginRequest.put("siteType", "premium");
|
||||
|
@ -131,7 +131,7 @@ public class StreamateHttpClient extends HttpClient {
|
|||
|
||||
public Request.Builder newRequestBuilder() {
|
||||
return new Request.Builder() // @formatter:off
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(REFERER, Streamate.BASE_URL)
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.util.regex.Pattern;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.io.HttpClient;
|
||||
import ctbrec.io.HttpException;
|
||||
|
@ -29,7 +28,7 @@ public class Stripchat extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
boolean hamster = Config.getInstance().getSettings().stripchatUseXhamster;
|
||||
boolean hamster = getConfig().getSettings().stripchatUseXhamster;
|
||||
if (hamster) {
|
||||
domain = "xhamsterlive.com";
|
||||
baseUri = "https://" + domain;
|
||||
|
@ -71,7 +70,7 @@ public class Stripchat extends AbstractSite {
|
|||
throw new IOException("Account settings not available");
|
||||
}
|
||||
|
||||
String username = Config.getInstance().getSettings().stripchatPassword;
|
||||
String username = getConfig().getSettings().stripchatPassword;
|
||||
String url = baseUri + "/api/v1/user/" + username;
|
||||
Request request = new Request.Builder().url(url).build();
|
||||
try (Response response = getHttpClient().execute(request)) {
|
||||
|
@ -98,7 +97,7 @@ public class Stripchat extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new StripchatHttpClient();
|
||||
httpClient = new StripchatHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -130,7 +129,7 @@ public class Stripchat extends AbstractSite {
|
|||
String url = baseUri + "/api/front/v2/models/search?limit=20&query=" + URLEncoder.encode(q, "utf-8");
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response response = getHttpClient().execute(req)) {
|
||||
if (response.isSuccessful()) {
|
||||
|
@ -161,7 +160,7 @@ public class Stripchat extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
String username = Config.getInstance().getSettings().stripchatUsername;
|
||||
String username = getConfig().getSettings().stripchatUsername;
|
||||
return username != null && !username.trim().isEmpty();
|
||||
}
|
||||
|
||||
|
|
|
@ -27,8 +27,8 @@ public class StripchatHttpClient extends HttpClient {
|
|||
private String csrfTimestamp;
|
||||
private String csrfNotifyTimestamp;
|
||||
|
||||
public StripchatHttpClient() {
|
||||
super("stripchat");
|
||||
public StripchatHttpClient(Config config) {
|
||||
super("stripchat", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,8 +56,8 @@ public class StripchatHttpClient extends HttpClient {
|
|||
|
||||
String url = Stripchat.baseUri + "/api/front/auth/login";
|
||||
JSONObject requestParams = new JSONObject();
|
||||
requestParams.put("loginOrEmail", Config.getInstance().getSettings().stripchatUsername);
|
||||
requestParams.put("password", Config.getInstance().getSettings().stripchatPassword);
|
||||
requestParams.put("loginOrEmail", config.getSettings().stripchatUsername);
|
||||
requestParams.put("password", config.getSettings().stripchatPassword);
|
||||
requestParams.put("remember", true);
|
||||
requestParams.put("csrfToken", csrfToken);
|
||||
requestParams.put("csrfTimestamp", csrfTimestamp);
|
||||
|
@ -66,7 +66,7 @@ public class StripchatHttpClient extends HttpClient {
|
|||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri)
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
|
@ -94,7 +94,7 @@ public class StripchatHttpClient extends HttpClient {
|
|||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri)
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
|
@ -122,7 +122,7 @@ public class StripchatHttpClient extends HttpClient {
|
|||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri + "/favorites")
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
|
@ -139,11 +139,11 @@ public class StripchatHttpClient extends HttpClient {
|
|||
|
||||
public long getUserId() throws JSONException, IOException {
|
||||
if (userId == 0) {
|
||||
String url = Stripchat.baseUri + "/api/front/users/username/" + Config.getInstance().getSettings().stripchatUsername;
|
||||
String url = Stripchat.baseUri + "/api/front/users/username/" + config.getSettings().stripchatUsername;
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(ORIGIN, Stripchat.baseUri)
|
||||
.header(REFERER, Stripchat.baseUri)
|
||||
.header(CONTENT_TYPE, MIMETYPE_APPLICATION_JSON)
|
||||
|
|
|
@ -7,7 +7,6 @@ import java.util.Map;
|
|||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import ctbrec.Config;
|
||||
import ctbrec.Model;
|
||||
import ctbrec.StringUtil;
|
||||
import ctbrec.io.HttpClient;
|
||||
|
@ -21,7 +20,7 @@ public class XloveCam extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public void init() throws IOException {
|
||||
httpClient = new XloveCamHttpClient();
|
||||
// noop
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,7 +65,7 @@ public class XloveCam extends AbstractSite {
|
|||
@Override
|
||||
public HttpClient getHttpClient() {
|
||||
if (httpClient == null) {
|
||||
httpClient = new XloveCamHttpClient();
|
||||
httpClient = new XloveCamHttpClient(getConfig());
|
||||
}
|
||||
return httpClient;
|
||||
}
|
||||
|
@ -112,7 +111,7 @@ public class XloveCam extends AbstractSite {
|
|||
|
||||
@Override
|
||||
public boolean credentialsAvailable() {
|
||||
return StringUtil.isNotBlank(Config.getInstance().getSettings().xlovecamUsername);
|
||||
return StringUtil.isNotBlank(getConfig().getSettings().xlovecamUsername);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,18 +29,18 @@ public class XloveCamHttpClient extends HttpClient {
|
|||
private static final Pattern CSRF_PATTERN = Pattern.compile("CSRFToken\\s*=\\s*\"(.*?)\";");
|
||||
private final Random rng = new Random();
|
||||
|
||||
public XloveCamHttpClient() {
|
||||
super("xlovecam");
|
||||
public XloveCamHttpClient(Config config) {
|
||||
super("xlovecam", config);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean login() throws IOException {
|
||||
String username = Config.getInstance().getSettings().xlovecamUsername;
|
||||
String username = config.getSettings().xlovecamUsername;
|
||||
String csrfToken = getCsrfToken();
|
||||
JSONObject config = getConfig();
|
||||
String token = config.getString("token");
|
||||
byte[] passwordKey = getPasswordKey(config);
|
||||
byte[] encryptedPassword = encryptPassword(Config.getInstance().getSettings().xlovecamPassword, passwordKey);
|
||||
JSONObject xlovecamConfig = getXlovecamConfig();
|
||||
String token = xlovecamConfig.getString("token");
|
||||
byte[] passwordKey = getPasswordKey(xlovecamConfig);
|
||||
byte[] encryptedPassword = encryptPassword(config.getSettings().xlovecamPassword, passwordKey);
|
||||
String base64EncryptedPassword = Base64.getEncoder().encodeToString(encryptedPassword);
|
||||
LOG.debug("csrf:{} token:{} key:{}", csrfToken, token, Arrays.toString(passwordKey));
|
||||
LOG.debug("encrypted password: {}", base64EncryptedPassword);
|
||||
|
@ -84,7 +84,7 @@ public class XloveCamHttpClient extends HttpClient {
|
|||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(REFERER, XloveCam.baseUrl + "/en/login")
|
||||
.header(ORIGIN, XloveCam.baseUrl)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(CONTENT_TYPE, FORM_ENCODED)
|
||||
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
.build();
|
||||
|
@ -147,7 +147,7 @@ public class XloveCamHttpClient extends HttpClient {
|
|||
Request req = new Request.Builder()
|
||||
.url(XloveCam.baseUrl)
|
||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.build();
|
||||
try (Response resp = execute(req)) {
|
||||
if (resp.isSuccessful()) {
|
||||
|
@ -164,7 +164,7 @@ public class XloveCamHttpClient extends HttpClient {
|
|||
}
|
||||
}
|
||||
|
||||
private JSONObject getConfig() throws IOException {
|
||||
private JSONObject getXlovecamConfig() throws IOException {
|
||||
String url = XloveCam.baseUrl + "/en/popup/login";
|
||||
LOG.debug("Calling {}", url);
|
||||
RequestBody body = new FormBody.Builder()
|
||||
|
@ -180,7 +180,7 @@ public class XloveCamHttpClient extends HttpClient {
|
|||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||
.header(REFERER, XloveCam.baseUrl)
|
||||
.header(ORIGIN, XloveCam.baseUrl)
|
||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||
.header(USER_AGENT, config.getSettings().httpUserAgent)
|
||||
.header(CONTENT_TYPE, FORM_ENCODED)
|
||||
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||
.build();
|
||||
|
|
|
@ -111,10 +111,20 @@ public class HttpServer {
|
|||
LOG.info("HMAC authentication is {}", config.getSettings().key != null ? "enabled" : "disabled");
|
||||
|
||||
recorder = new NextGenLocalRecorder(config, sites);
|
||||
initSites();
|
||||
|
||||
onlineMonitor = new OnlineMonitor(recorder, config);
|
||||
onlineMonitor.start();
|
||||
startHttpServer();
|
||||
}
|
||||
|
||||
private void initSites() {
|
||||
for (Site site : sites) {
|
||||
if (site.isEnabled()) {
|
||||
GlobalThreadPool.submit(() -> {
|
||||
try {
|
||||
site.setRecorder(recorder);
|
||||
site.setConfig(config);
|
||||
site.init();
|
||||
safeLogin(site);
|
||||
} catch (IOException e) {
|
||||
|
@ -123,9 +133,6 @@ public class HttpServer {
|
|||
});
|
||||
}
|
||||
}
|
||||
onlineMonitor = new OnlineMonitor(recorder, config);
|
||||
onlineMonitor.start();
|
||||
startHttpServer();
|
||||
}
|
||||
|
||||
private void safeLogin(Site site) {
|
||||
|
|
Loading…
Reference in New Issue