forked from j62/ctbrec
Add setting to set the base URL for MFC
This commit is contained in:
parent
353f3fb317
commit
6b4d320bc2
|
@ -26,6 +26,7 @@ public class MyFreeCamsConfigUI extends AbstractConfigUI {
|
||||||
GridPane layout = SettingsTab.createGridLayout();
|
GridPane layout = SettingsTab.createGridLayout();
|
||||||
layout.add(new Label("MyFreeCams User"), 0, 0);
|
layout.add(new Label("MyFreeCams User"), 0, 0);
|
||||||
TextField username = new TextField(Config.getInstance().getSettings().mfcUsername);
|
TextField username = new TextField(Config.getInstance().getSettings().mfcUsername);
|
||||||
|
username.setPrefWidth(300);
|
||||||
username.textProperty().addListener((ob, o, n) -> {
|
username.textProperty().addListener((ob, o, n) -> {
|
||||||
Config.getInstance().getSettings().mfcUsername = username.getText();
|
Config.getInstance().getSettings().mfcUsername = username.getText();
|
||||||
save();
|
save();
|
||||||
|
@ -47,13 +48,27 @@ public class MyFreeCamsConfigUI extends AbstractConfigUI {
|
||||||
GridPane.setColumnSpan(password, 2);
|
GridPane.setColumnSpan(password, 2);
|
||||||
layout.add(password, 1, 1);
|
layout.add(password, 1, 1);
|
||||||
|
|
||||||
|
layout.add(new Label("MyFreeCams Base URL"), 0, 2);
|
||||||
|
TextField baseUrl = new TextField();
|
||||||
|
baseUrl.setText(Config.getInstance().getSettings().mfcBaseUrl);
|
||||||
|
baseUrl.textProperty().addListener((ob, o, n) -> {
|
||||||
|
Config.getInstance().getSettings().mfcBaseUrl = baseUrl.getText();
|
||||||
|
save();
|
||||||
|
});
|
||||||
|
GridPane.setFillWidth(baseUrl, true);
|
||||||
|
GridPane.setHgrow(baseUrl, Priority.ALWAYS);
|
||||||
|
GridPane.setColumnSpan(baseUrl, 2);
|
||||||
|
layout.add(baseUrl, 1, 2);
|
||||||
|
|
||||||
Button createAccount = new Button("Create new Account");
|
Button createAccount = new Button("Create new Account");
|
||||||
createAccount.setOnAction((e) -> DesktopIntegration.open(myFreeCams.getAffiliateLink()));
|
createAccount.setOnAction((e) -> DesktopIntegration.open(myFreeCams.getAffiliateLink()));
|
||||||
layout.add(createAccount, 1, 2);
|
layout.add(createAccount, 1, 3);
|
||||||
GridPane.setColumnSpan(createAccount, 2);
|
GridPane.setColumnSpan(createAccount, 2);
|
||||||
GridPane.setMargin(username, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
|
GridPane.setMargin(username, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
|
||||||
GridPane.setMargin(password, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
|
GridPane.setMargin(password, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
|
||||||
|
GridPane.setMargin(baseUrl, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
|
||||||
GridPane.setMargin(createAccount, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
|
GridPane.setMargin(createAccount, new Insets(0, 0, 0, SettingsTab.CHECKBOX_MARGIN));
|
||||||
|
|
||||||
return layout;
|
return layout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ public class Settings {
|
||||||
public String bongaPassword = "";
|
public String bongaPassword = "";
|
||||||
public String mfcUsername = "";
|
public String mfcUsername = "";
|
||||||
public String mfcPassword = "";
|
public String mfcPassword = "";
|
||||||
|
public String mfcBaseUrl = "https://www.myfreecams.com";
|
||||||
public String camsodaUsername = "";
|
public String camsodaUsername = "";
|
||||||
public String camsodaPassword = "";
|
public String camsodaPassword = "";
|
||||||
public String cam4Username;
|
public String cam4Username;
|
||||||
|
|
|
@ -17,13 +17,14 @@ import okhttp3.Response;
|
||||||
|
|
||||||
public class MyFreeCams extends AbstractSite {
|
public class MyFreeCams extends AbstractSite {
|
||||||
|
|
||||||
public static final String BASE_URI = "https://www.myfreecams.com";
|
static String baseUrl = "https://www.myfreecams.com";
|
||||||
|
|
||||||
private MyFreeCamsClient client;
|
private MyFreeCamsClient client;
|
||||||
private MyFreeCamsHttpClient httpClient;
|
private MyFreeCamsHttpClient httpClient;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws IOException {
|
public void init() throws IOException {
|
||||||
|
baseUrl = Config.getInstance().getSettings().mfcBaseUrl;
|
||||||
client = MyFreeCamsClient.getInstance();
|
client = MyFreeCamsClient.getInstance();
|
||||||
client.setSite(this);
|
client.setSite(this);
|
||||||
client.start();
|
client.start();
|
||||||
|
@ -41,12 +42,12 @@ public class MyFreeCams extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBaseUrl() {
|
public String getBaseUrl() {
|
||||||
return BASE_URI;
|
return baseUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAffiliateLink() {
|
public String getAffiliateLink() {
|
||||||
return BASE_URI + "/?baf=8127165";
|
return baseUrl + "/?baf=8127165";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -59,7 +60,7 @@ public class MyFreeCams extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Integer getTokenBalance() throws IOException {
|
public Integer getTokenBalance() throws IOException {
|
||||||
Request req = new Request.Builder().url(BASE_URI + "/php/account.php?request=status").build();
|
Request req = new Request.Builder().url(baseUrl + "/php/account.php?request=status").build();
|
||||||
try(Response response = getHttpClient().execute(req)) {
|
try(Response response = getHttpClient().execute(req)) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
String content = response.body().string();
|
String content = response.body().string();
|
||||||
|
@ -74,7 +75,7 @@ public class MyFreeCams extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getBuyTokensLink() {
|
public String getBuyTokensLink() {
|
||||||
return BASE_URI + "/php/purchase.php?request=tokens";
|
return baseUrl + "/php/purchase.php?request=tokens";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -85,7 +85,7 @@ public class MyFreeCamsClient {
|
||||||
|
|
||||||
public void start() throws IOException {
|
public void start() throws IOException {
|
||||||
running = true;
|
running = true;
|
||||||
serverConfig = new ServerConfig(mfc.getHttpClient());
|
serverConfig = new ServerConfig(mfc);
|
||||||
List<String> websocketServers = new ArrayList<String>(serverConfig.wsServers.keySet());
|
List<String> websocketServers = new ArrayList<String>(serverConfig.wsServers.keySet());
|
||||||
String server = websocketServers.get((int) (Math.random()*websocketServers.size()));
|
String server = websocketServers.get((int) (Math.random()*websocketServers.size()));
|
||||||
String wsUrl = "ws://" + server + ".myfreecams.com:8080/fcsl";
|
String wsUrl = "ws://" + server + ".myfreecams.com:8080/fcsl";
|
||||||
|
|
|
@ -53,8 +53,8 @@ public class MyFreeCamsHttpClient extends HttpClient {
|
||||||
.add("submit_login", "97")
|
.add("submit_login", "97")
|
||||||
.build();
|
.build();
|
||||||
Request req = new Request.Builder()
|
Request req = new Request.Builder()
|
||||||
.url(MyFreeCams.BASE_URI + "/php/login.php")
|
.url(MyFreeCams.baseUrl + "/php/login.php")
|
||||||
.header("Referer", MyFreeCams.BASE_URI)
|
.header("Referer", MyFreeCams.baseUrl)
|
||||||
.header("Content-Type", "application/x-www-form-urlencoded")
|
.header("Content-Type", "application/x-www-form-urlencoded")
|
||||||
.post(body)
|
.post(body)
|
||||||
.build();
|
.build();
|
||||||
|
@ -75,7 +75,7 @@ public class MyFreeCamsHttpClient extends HttpClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkLogin() throws IOException {
|
private boolean checkLogin() throws IOException {
|
||||||
Request req = new Request.Builder().url(MyFreeCams.BASE_URI + "/php/account.php?request=status").build();
|
Request req = new Request.Builder().url(MyFreeCams.baseUrl + "/php/account.php?request=status").build();
|
||||||
try(Response response = execute(req)) {
|
try(Response response = execute(req)) {
|
||||||
if(response.isSuccessful()) {
|
if(response.isSuccessful()) {
|
||||||
String content = response.body().string();
|
String content = response.body().string();
|
||||||
|
@ -99,7 +99,7 @@ public class MyFreeCamsHttpClient extends HttpClient {
|
||||||
|
|
||||||
public Cookie getCookie(String name) {
|
public Cookie getCookie(String name) {
|
||||||
CookieJar jar = client.cookieJar();
|
CookieJar jar = client.cookieJar();
|
||||||
HttpUrl url = HttpUrl.parse(MyFreeCams.BASE_URI);
|
HttpUrl url = HttpUrl.parse(MyFreeCams.baseUrl);
|
||||||
List<Cookie> cookies = jar.loadForRequest(url);
|
List<Cookie> cookies = jar.loadForRequest(url);
|
||||||
for (Cookie cookie : cookies) {
|
for (Cookie cookie : cookies) {
|
||||||
if(Objects.equals(cookie.name(), name)) {
|
if(Objects.equals(cookie.name(), name)) {
|
||||||
|
|
|
@ -132,7 +132,7 @@ public class MyFreeCamsModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveTip(int tokens) throws IOException {
|
public void receiveTip(int tokens) throws IOException {
|
||||||
String tipUrl = MyFreeCams.BASE_URI + "/php/tip.php";
|
String tipUrl = MyFreeCams.baseUrl + "/php/tip.php";
|
||||||
String initUrl = tipUrl + "?request=tip&username="+getName()+"&broadcaster_id="+getUid();
|
String initUrl = tipUrl + "?request=tip&username="+getName()+"&broadcaster_id="+getUid();
|
||||||
Request req = new Request.Builder().url(initUrl).build();
|
Request req = new Request.Builder().url(initUrl).build();
|
||||||
try(Response resp = site.getHttpClient().execute(req)) {
|
try(Response resp = site.getHttpClient().execute(req)) {
|
||||||
|
|
|
@ -9,13 +9,16 @@ import java.util.Objects;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.io.HttpClient;
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
public class ServerConfig {
|
public class ServerConfig {
|
||||||
|
|
||||||
|
private static final transient Logger LOG = LoggerFactory.getLogger(ServerConfig.class);
|
||||||
|
|
||||||
List<String> ajaxServers;
|
List<String> ajaxServers;
|
||||||
List<String> videoServers;
|
List<String> videoServers;
|
||||||
List<String> chatServers;
|
List<String> chatServers;
|
||||||
|
@ -24,9 +27,11 @@ public class ServerConfig {
|
||||||
Map<String, String> wzobsServers;
|
Map<String, String> wzobsServers;
|
||||||
Map<String, String> ngVideoServers;
|
Map<String, String> ngVideoServers;
|
||||||
|
|
||||||
public ServerConfig(HttpClient client) throws IOException {
|
public ServerConfig(MyFreeCams mfc) throws IOException {
|
||||||
Request req = new Request.Builder().url("http://www.myfreecams.com/_js/serverconfig.js").build();
|
String url = mfc.getBaseUrl() + "/_js/serverconfig.js";
|
||||||
Response resp = client.execute(req);
|
LOG.debug("Loading server config from {}", url);
|
||||||
|
Request req = new Request.Builder().url(url).build();
|
||||||
|
Response resp = mfc.getHttpClient().execute(req);
|
||||||
String json = resp.body().string();
|
String json = resp.body().string();
|
||||||
|
|
||||||
JSONObject serverConfig = new JSONObject(json);
|
JSONObject serverConfig = new JSONObject(json);
|
||||||
|
|
Loading…
Reference in New Issue