Fix BongaCams online check
This commit is contained in:
parent
a3fc1e31d4
commit
3ed7fd1aff
|
@ -1,16 +1,5 @@
|
||||||
package ctbrec.ui.sites.bonga;
|
package ctbrec.ui.sites.bonga;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.function.Consumer;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.sites.bonga.BongaCams;
|
import ctbrec.sites.bonga.BongaCams;
|
||||||
import ctbrec.ui.ExternalBrowser;
|
import ctbrec.ui.ExternalBrowser;
|
||||||
|
@ -18,21 +7,32 @@ import okhttp3.Cookie;
|
||||||
import okhttp3.Cookie.Builder;
|
import okhttp3.Cookie.Builder;
|
||||||
import okhttp3.CookieJar;
|
import okhttp3.CookieJar;
|
||||||
import okhttp3.HttpUrl;
|
import okhttp3.HttpUrl;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class BongaCamsElectronLoginDialog {
|
public class BongaCamsElectronLoginDialog {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BongaCamsElectronLoginDialog.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BongaCamsElectronLoginDialog.class);
|
||||||
public static final String DOMAIN = "bongacams.com";
|
public static final String DOMAIN = "bongacams.com";
|
||||||
public static final String URL = BongaCams.baseUrl + "/login";
|
private final BongaCams site;
|
||||||
private CookieJar cookieJar;
|
private CookieJar cookieJar;
|
||||||
private ExternalBrowser browser;
|
private ExternalBrowser browser;
|
||||||
|
|
||||||
public BongaCamsElectronLoginDialog(CookieJar cookieJar) throws IOException {
|
public BongaCamsElectronLoginDialog(BongaCams site, CookieJar cookieJar) throws IOException {
|
||||||
|
this.site = site;
|
||||||
this.cookieJar = cookieJar;
|
this.cookieJar = cookieJar;
|
||||||
browser = ExternalBrowser.getInstance();
|
browser = ExternalBrowser.getInstance();
|
||||||
try {
|
try {
|
||||||
var config = new JSONObject();
|
var config = new JSONObject();
|
||||||
config.put("url", URL);
|
config.put("url", site.getBaseUrl() + "/login");
|
||||||
config.put("w", 640);
|
config.put("w", 640);
|
||||||
config.put("h", 480);
|
config.put("h", 480);
|
||||||
var msg = new JSONObject();
|
var msg = new JSONObject();
|
||||||
|
@ -46,7 +46,7 @@ public class BongaCamsElectronLoginDialog {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Consumer<String> msgHandler = line -> {
|
private final Consumer<String> msgHandler = line -> {
|
||||||
if (!line.startsWith("{")) {
|
if (!line.startsWith("{")) {
|
||||||
LOG.error("Didn't received a JSON object {}", line);
|
LOG.error("Didn't received a JSON object {}", line);
|
||||||
} else {
|
} else {
|
||||||
|
@ -104,7 +104,7 @@ public class BongaCamsElectronLoginDialog {
|
||||||
b.secure();
|
b.secure();
|
||||||
}
|
}
|
||||||
Cookie c = b.build();
|
Cookie c = b.build();
|
||||||
cookieJar.saveFromResponse(HttpUrl.parse(BongaCams.baseUrl), Collections.singletonList(c));
|
cookieJar.saveFromResponse(HttpUrl.parse(BongaCamsElectronLoginDialog.this.site.getBaseUrl()), Collections.singletonList(c));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
package ctbrec.ui.sites.bonga;
|
package ctbrec.ui.sites.bonga;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import ctbrec.sites.bonga.BongaCams;
|
import ctbrec.sites.bonga.BongaCams;
|
||||||
import ctbrec.sites.bonga.BongaCamsHttpClient;
|
import ctbrec.sites.bonga.BongaCamsHttpClient;
|
||||||
import ctbrec.ui.controls.Dialogs;
|
import ctbrec.ui.controls.Dialogs;
|
||||||
import ctbrec.ui.sites.AbstractSiteUi;
|
import ctbrec.ui.sites.AbstractSiteUi;
|
||||||
import ctbrec.ui.sites.ConfigUI;
|
import ctbrec.ui.sites.ConfigUI;
|
||||||
import ctbrec.ui.tabs.TabProvider;
|
import ctbrec.ui.tabs.TabProvider;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
public class BongaCamsSiteUi extends AbstractSiteUi {
|
public class BongaCamsSiteUi extends AbstractSiteUi {
|
||||||
|
|
||||||
|
@ -47,7 +46,7 @@ public class BongaCamsSiteUi extends AbstractSiteUi {
|
||||||
} else {
|
} else {
|
||||||
// login with external browser window
|
// login with external browser window
|
||||||
try {
|
try {
|
||||||
new BongaCamsElectronLoginDialog(bongaCams.getHttpClient().getCookieJar());
|
new BongaCamsElectronLoginDialog(bongaCams, bongaCams.getHttpClient().getCookieJar());
|
||||||
} catch (Exception e1) {
|
} catch (Exception e1) {
|
||||||
LOG.error("Error logging in with external browser", e1);
|
LOG.error("Error logging in with external browser", e1);
|
||||||
Dialogs.showError("Login error", "Couldn't login to " + bongaCams.getName(), e1);
|
Dialogs.showError("Login error", "Couldn't login to " + bongaCams.getName(), e1);
|
||||||
|
|
|
@ -23,32 +23,32 @@ public class BongaCamsTabProvider extends AbstractTabProvider {
|
||||||
List<Tab> tabs = new ArrayList<>();
|
List<Tab> tabs = new ArrayList<>();
|
||||||
|
|
||||||
// female
|
// female
|
||||||
String url = BongaCams.baseUrl + "/tools/listing_v3.php?livetab=female&online_only=true&is_mobile=true&offset=";
|
String url = site.getBaseUrl() + "/tools/listing_v3.php?livetab=female&online_only=true&is_mobile=true&offset=";
|
||||||
var updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
var updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
||||||
tabs.add(createTab("Female", updateService));
|
tabs.add(createTab("Female", updateService));
|
||||||
|
|
||||||
// male
|
// male
|
||||||
url = BongaCams.baseUrl + "/tools/listing_v3.php?livetab=male&online_only=true&is_mobile=true&offset=";
|
url = site.getBaseUrl() + "/tools/listing_v3.php?livetab=male&online_only=true&is_mobile=true&offset=";
|
||||||
updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
||||||
tabs.add(createTab("Male", updateService));
|
tabs.add(createTab("Male", updateService));
|
||||||
|
|
||||||
// couples
|
// couples
|
||||||
url = BongaCams.baseUrl + "/tools/listing_v3.php?livetab=couples&online_only=true&is_mobile=true&offset=";
|
url = site.getBaseUrl() + "/tools/listing_v3.php?livetab=couples&online_only=true&is_mobile=true&offset=";
|
||||||
updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
||||||
tabs.add(createTab("Couples", updateService));
|
tabs.add(createTab("Couples", updateService));
|
||||||
|
|
||||||
// trans
|
// trans
|
||||||
url = BongaCams.baseUrl + "/tools/listing_v3.php?livetab=transsexual&online_only=true&is_mobile=true&offset=";
|
url = site.getBaseUrl() + "/tools/listing_v3.php?livetab=transsexual&online_only=true&is_mobile=true&offset=";
|
||||||
updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
||||||
tabs.add(createTab("Transsexual", updateService));
|
tabs.add(createTab("Transsexual", updateService));
|
||||||
|
|
||||||
// new
|
// new
|
||||||
url = BongaCams.baseUrl + "/tools/listing_v3.php?livetab=new&online_only=true&is_mobile=true&offset=";
|
url = site.getBaseUrl() + "/tools/listing_v3.php?livetab=new&online_only=true&is_mobile=true&offset=";
|
||||||
updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
updateService = new BongaCamsUpdateService((BongaCams) site, url);
|
||||||
tabs.add(createTab("New", updateService));
|
tabs.add(createTab("New", updateService));
|
||||||
|
|
||||||
// friends
|
// friends
|
||||||
url = BongaCams.baseUrl + "/tools/listing_v3.php?livetab=friends&online_only=true&offset=";
|
url = site.getBaseUrl() + "/tools/listing_v3.php?livetab=friends&online_only=true&offset=";
|
||||||
updateService = new BongaCamsUpdateService((BongaCams) site, url, true);
|
updateService = new BongaCamsUpdateService((BongaCams) site, url, true);
|
||||||
friendsTab = new BongaCamsFriendsTab("Friends", updateService, site);
|
friendsTab = new BongaCamsFriendsTab("Friends", updateService, site);
|
||||||
friendsTab.setRecorder(recorder);
|
friendsTab.setRecorder(recorder);
|
||||||
|
|
|
@ -6,6 +6,7 @@ public class HttpConstants {
|
||||||
public static final String ACCEPT_ENCODING = "Accept-Encoding";
|
public static final String ACCEPT_ENCODING = "Accept-Encoding";
|
||||||
public static final String ACCEPT_ENCODING_GZIP = "gzip";
|
public static final String ACCEPT_ENCODING_GZIP = "gzip";
|
||||||
public static final String ACCEPT_LANGUAGE = "Accept-Language";
|
public static final String ACCEPT_LANGUAGE = "Accept-Language";
|
||||||
|
public static final String ALL = "*";
|
||||||
public static final String AUTHORIZATION = "Authorization";
|
public static final String AUTHORIZATION = "Authorization";
|
||||||
public static final String CACHE_CONTROL = "Cache-Control";
|
public static final String CACHE_CONTROL = "Cache-Control";
|
||||||
public static final String CONNECTION = "Connection";
|
public static final String CONNECTION = "Connection";
|
||||||
|
|
|
@ -1,21 +1,5 @@
|
||||||
package ctbrec.sites.bonga;
|
package ctbrec.sites.bonga;
|
||||||
|
|
||||||
import static ctbrec.io.HttpConstants.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.io.HttpClient;
|
import ctbrec.io.HttpClient;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
|
@ -24,12 +8,26 @@ import okhttp3.FormBody;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL;
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||||
|
|
||||||
public class BongaCams extends AbstractSite {
|
public class BongaCams extends AbstractSite {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BongaCams.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BongaCams.class);
|
||||||
|
|
||||||
public static String baseUrl = "https://bongacams.com";
|
private String baseUrl = "https://bongacams.com";
|
||||||
|
|
||||||
private BongaCamsHttpClient httpClient;
|
private BongaCamsHttpClient httpClient;
|
||||||
|
|
||||||
|
@ -50,7 +48,7 @@ public class BongaCams extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getAffiliateLink() {
|
public String getAffiliateLink() {
|
||||||
return "http://bongacams2.com/track?c=610249";
|
return "https://bongacams10.com/track?c=610249";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -66,7 +64,7 @@ public class BongaCams extends AbstractSite {
|
||||||
@Override
|
@Override
|
||||||
public Double getTokenBalance() throws IOException {
|
public Double getTokenBalance() throws IOException {
|
||||||
int userId = ((BongaCamsHttpClient) getHttpClient()).getUserId();
|
int userId = ((BongaCamsHttpClient) getHttpClient()).getUserId();
|
||||||
String url = BongaCams.baseUrl + "/tools/amf.php";
|
String url = getBaseUrl() + "/tools/amf.php";
|
||||||
RequestBody body = new FormBody.Builder()
|
RequestBody body = new FormBody.Builder()
|
||||||
.add("method", "ping")
|
.add("method", "ping")
|
||||||
.add("args[]", Integer.toString(userId))
|
.add("args[]", Integer.toString(userId))
|
||||||
|
@ -76,13 +74,13 @@ public class BongaCams extends AbstractSite {
|
||||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
.addHeader(REFERER, BongaCams.baseUrl)
|
.addHeader(REFERER, getBaseUrl())
|
||||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.post(body)
|
.post(body)
|
||||||
.build();
|
.build();
|
||||||
try (Response response = getHttpClient().execute(request)) {
|
try (Response response = getHttpClient().execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
JSONObject json = new JSONObject(response.body().string());
|
JSONObject json = new JSONObject(Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string());
|
||||||
if (json.optString("status").equals("online")) {
|
if (json.optString("status").equals("online")) {
|
||||||
JSONObject userData = json.getJSONObject("userData");
|
JSONObject userData = json.getJSONObject("userData");
|
||||||
return (double) userData.getInt("balance");
|
return (double) userData.getInt("balance");
|
||||||
|
@ -108,7 +106,7 @@ public class BongaCams extends AbstractSite {
|
||||||
@Override
|
@Override
|
||||||
public HttpClient getHttpClient() {
|
public HttpClient getHttpClient() {
|
||||||
if (httpClient == null) {
|
if (httpClient == null) {
|
||||||
httpClient = new BongaCamsHttpClient(getConfig());
|
httpClient = new BongaCamsHttpClient(this, getConfig());
|
||||||
}
|
}
|
||||||
return httpClient;
|
return httpClient;
|
||||||
}
|
}
|
||||||
|
@ -142,21 +140,34 @@ public class BongaCams extends AbstractSite {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Model> search(String q) throws IOException, InterruptedException {
|
public List<Model> search(String q) throws IOException, InterruptedException {
|
||||||
String url = baseUrl + "/tools/listing_v3.php?offset=0&model_search[display_name][text]=" + URLEncoder.encode(q, "utf-8");
|
String url = baseUrl + "/tools/listing_v3.php?offset=0&model_search[display_name][text]=" + URLEncoder.encode(q, UTF_8);
|
||||||
Request req = new Request.Builder()
|
Request req = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
.addHeader(USER_AGENT, getConfig().getSettings().httpUserAgent)
|
||||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
.addHeader(REFERER, BongaCams.baseUrl)
|
.addHeader(REFERER, getBaseUrl())
|
||||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.build();
|
.build();
|
||||||
try (Response response = getHttpClient().execute(req)) {
|
try (Response response = getHttpClient().execute(req)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String body = response.body().string();
|
String body = Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
if (json.optString("status").equals("success")) {
|
if (json.optString("status").equals("success")) {
|
||||||
List<Model> models = new ArrayList<>();
|
List<Model> models = new ArrayList<>();
|
||||||
|
parseModelList(models, json);
|
||||||
|
return models;
|
||||||
|
} else {
|
||||||
|
LOG.warn("Search result: {}", json.toString(2));
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new HttpException(response.code(), response.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void parseModelList(List<Model> models, JSONObject json) {
|
||||||
JSONArray results = json.getJSONArray("models");
|
JSONArray results = json.getJSONArray("models");
|
||||||
for (int i = 0; i < results.length(); i++) {
|
for (int i = 0; i < results.length(); i++) {
|
||||||
JSONObject result = results.getJSONObject(i);
|
JSONObject result = results.getJSONObject(i);
|
||||||
|
@ -172,15 +183,6 @@ public class BongaCams extends AbstractSite {
|
||||||
models.add(model);
|
models.add(model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return models;
|
|
||||||
} else {
|
|
||||||
LOG.warn("Search result: " + json.toString(2));
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new HttpException(response.code(), response.message());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,36 +1,34 @@
|
||||||
package ctbrec.sites.bonga;
|
package ctbrec.sites.bonga;
|
||||||
|
|
||||||
import static ctbrec.io.HttpConstants.*;
|
import ctbrec.Config;
|
||||||
|
import ctbrec.io.HttpClient;
|
||||||
import java.io.IOException;
|
import ctbrec.io.HttpException;
|
||||||
import java.util.Iterator;
|
import okhttp3.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Map.Entry;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import java.io.IOException;
|
||||||
import ctbrec.io.HttpClient;
|
import java.util.List;
|
||||||
import ctbrec.io.HttpException;
|
import java.util.Locale;
|
||||||
import okhttp3.Cookie;
|
import java.util.Map;
|
||||||
import okhttp3.FormBody;
|
import java.util.Map.Entry;
|
||||||
import okhttp3.Request;
|
import java.util.Objects;
|
||||||
import okhttp3.RequestBody;
|
|
||||||
import okhttp3.Response;
|
import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL;
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
|
||||||
public class BongaCamsHttpClient extends HttpClient {
|
public class BongaCamsHttpClient extends HttpClient {
|
||||||
|
|
||||||
private static final Logger LOG = LoggerFactory.getLogger(BongaCamsHttpClient.class);
|
private static final Logger LOG = LoggerFactory.getLogger(BongaCamsHttpClient.class);
|
||||||
private static final String SORT_COOKIE = "ls01";
|
private static final String SORT_COOKIE = "ls01";
|
||||||
|
private final BongaCams site;
|
||||||
private int userId = 0;
|
private int userId = 0;
|
||||||
|
|
||||||
public BongaCamsHttpClient(Config config) {
|
public BongaCamsHttpClient(BongaCams site, Config config) {
|
||||||
super("bongacams", config);
|
super("bongacams", config);
|
||||||
|
this.site = site;
|
||||||
addSortByPopularCookie();
|
addSortByPopularCookie();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -48,12 +46,7 @@ public class BongaCamsHttpClient extends HttpClient {
|
||||||
Map<String, List<Cookie>> cookies = cookieJar.getCookies();
|
Map<String, List<Cookie>> cookies = cookieJar.getCookies();
|
||||||
for (Entry<String, List<Cookie>> entry : cookies.entrySet()) {
|
for (Entry<String, List<Cookie>> entry : cookies.entrySet()) {
|
||||||
List<Cookie> cookieList = entry.getValue();
|
List<Cookie> cookieList = entry.getValue();
|
||||||
for (Iterator<Cookie> iterator = cookieList.iterator(); iterator.hasNext();) {
|
cookieList.removeIf(cookie -> cookie.name().equals(SORT_COOKIE));
|
||||||
Cookie cookie = iterator.next();
|
|
||||||
if(cookie.name().equals(SORT_COOKIE)) {
|
|
||||||
iterator.remove();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
entry.getValue().add(sortByCookie);
|
entry.getValue().add(sortByCookie);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -76,32 +69,31 @@ public class BongaCamsHttpClient extends HttpClient {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check, if the login worked by requesting roomdata and looking
|
* Check, if the login worked by requesting roomdata and looking
|
||||||
* @throws IOException
|
*
|
||||||
|
* @throws IOException if the roomdata couldn't be loaded
|
||||||
*/
|
*/
|
||||||
public boolean checkLoginSuccess() throws IOException {
|
public boolean checkLoginSuccess() throws IOException {
|
||||||
String modelName = getAnyModelName();
|
String modelName = getAnyModelName();
|
||||||
// we request the roomData of a random model, because it contains
|
// we request the roomData of a random model, because it contains
|
||||||
// user data, if the user is logged in, which we can use to verify, that the login worked
|
// user data, if the user is logged in, which we can use to verify, that the login worked
|
||||||
String url = BongaCams.baseUrl + "/tools/amf.php";
|
String url = site.getBaseUrl() + "/tools/amf.php";
|
||||||
RequestBody body = new FormBody.Builder()
|
RequestBody body = new FormBody.Builder()
|
||||||
.add("method", "getRoomData")
|
.add("method", "getRoomData")
|
||||||
.add("args[]", modelName)
|
.add("args[]", modelName)
|
||||||
.add("args[]", "false")
|
.add("args[]", "false")
|
||||||
//.add("method", "ping") // TODO alternative request, but
|
|
||||||
//.add("args[]", <userId>) // where to get the userId
|
|
||||||
.build();
|
.build();
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(url)
|
.url(url)
|
||||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
.addHeader(REFERER, BongaCams.baseUrl)
|
.addHeader(REFERER, site.getBaseUrl())
|
||||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.post(body)
|
.post(body)
|
||||||
.build();
|
.build();
|
||||||
try (Response response = execute(request)) {
|
try (Response response = execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
JSONObject json = new JSONObject(response.body().string());
|
JSONObject json = new JSONObject(Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string());
|
||||||
if (json.optString("status").equals("success")) {
|
if (json.optString("status").equals("success")) {
|
||||||
JSONObject userData = json.getJSONObject("userData");
|
JSONObject userData = json.getJSONObject("userData");
|
||||||
userId = userData.optInt("userId");
|
userId = userData.optInt("userId");
|
||||||
|
@ -120,16 +112,16 @@ public class BongaCamsHttpClient extends HttpClient {
|
||||||
*/
|
*/
|
||||||
private String getAnyModelName() throws IOException {
|
private String getAnyModelName() throws IOException {
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(BongaCams.baseUrl + "/tools/listing_v3.php?livetab=female&online_only=true&is_mobile=true&offset=0")
|
.url(site.getBaseUrl() + "/tools/listing_v3.php?livetab=female&online_only=true&is_mobile=true&offset=0")
|
||||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
.addHeader(REFERER, BongaCams.baseUrl)
|
.addHeader(REFERER, site.getBaseUrl())
|
||||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.build();
|
.build();
|
||||||
try (Response response = execute(request)) {
|
try (Response response = execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String content = response.body().string();
|
String content = Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
JSONObject json = new JSONObject(content);
|
JSONObject json = new JSONObject(content);
|
||||||
if (json.optString("status").equals("success")) {
|
if (json.optString("status").equals("success")) {
|
||||||
JSONArray jsonModels = json.getJSONArray("models");
|
JSONArray jsonModels = json.getJSONArray("models");
|
||||||
|
@ -145,43 +137,6 @@ public class BongaCamsHttpClient extends HttpClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Override
|
|
||||||
// public boolean login() throws IOException {
|
|
||||||
// String url = BongaCams.BASE_URL + "/login";
|
|
||||||
// String dateTime = new SimpleDateFormat("d.MM.yyyy', 'HH:mm:ss").format(new Date());
|
|
||||||
// RequestBody body = new FormBody.Builder()
|
|
||||||
// .add("security_log_additional_info","{\"language\":\"en\",\"cookieEnabled\":true,\"javaEnabled\":false,\"flashVersion\":\"31.0.0\",\"dateTime\":\""+dateTime+"\",\"ips\":[\"192.168.0.1\"]}")
|
|
||||||
// .add("log_in[username]", Config.getInstance().getSettings().bongaUsername)
|
|
||||||
// .add("log_in[password]", Config.getInstance().getSettings().bongaPassword)
|
|
||||||
// .add("log_in[remember]", "1")
|
|
||||||
// .add("log_in[bfpt]", "")
|
|
||||||
// .add("header_form", "1")
|
|
||||||
// .build();
|
|
||||||
// Request request = new Request.Builder()
|
|
||||||
// .url(url)
|
|
||||||
// .post(body)
|
|
||||||
// .addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
|
||||||
// .addHeader(ACCEPT,"application/json")
|
|
||||||
// .addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
|
||||||
// .addHeader(REFERER, BongaCams.BASE_URL)
|
|
||||||
// .addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
|
||||||
// .build();
|
|
||||||
// try(Response response = execute(request)) {
|
|
||||||
// if(response.isSuccessful()) {
|
|
||||||
// JSONObject json = new JSONObject(response.body().string());
|
|
||||||
// if(json.optString("status").equals("success")) {
|
|
||||||
// return true;
|
|
||||||
// } else {
|
|
||||||
// LOG.debug("Login response: {}", json.toString(2));
|
|
||||||
// Platform.runLater(() -> new BongaCamsLoginDialog());
|
|
||||||
// throw new IOException("Login not successful");
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// throw new HttpException(response.code(), response.message());
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
public int getUserId() throws IOException {
|
public int getUserId() throws IOException {
|
||||||
if (userId == 0) {
|
if (userId == 0) {
|
||||||
login();
|
login();
|
||||||
|
|
|
@ -1,44 +1,34 @@
|
||||||
package ctbrec.sites.bonga;
|
package ctbrec.sites.bonga;
|
||||||
|
|
||||||
import static ctbrec.Model.State.*;
|
import com.iheartradio.m3u8.*;
|
||||||
import static ctbrec.io.HttpConstants.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.ExecutionException;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.jsoup.nodes.Element;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import com.iheartradio.m3u8.Encoding;
|
|
||||||
import com.iheartradio.m3u8.Format;
|
|
||||||
import com.iheartradio.m3u8.ParseException;
|
|
||||||
import com.iheartradio.m3u8.ParsingMode;
|
|
||||||
import com.iheartradio.m3u8.PlaylistException;
|
|
||||||
import com.iheartradio.m3u8.PlaylistParser;
|
|
||||||
import com.iheartradio.m3u8.data.MasterPlaylist;
|
import com.iheartradio.m3u8.data.MasterPlaylist;
|
||||||
import com.iheartradio.m3u8.data.Playlist;
|
import com.iheartradio.m3u8.data.Playlist;
|
||||||
import com.iheartradio.m3u8.data.PlaylistData;
|
import com.iheartradio.m3u8.data.PlaylistData;
|
||||||
import com.iheartradio.m3u8.data.StreamInfo;
|
import com.iheartradio.m3u8.data.StreamInfo;
|
||||||
|
|
||||||
import ctbrec.AbstractModel;
|
import ctbrec.AbstractModel;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.io.HtmlParser;
|
import ctbrec.io.HtmlParser;
|
||||||
import ctbrec.io.HtmlParserException;
|
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
import ctbrec.recorder.download.StreamSource;
|
import ctbrec.recorder.download.StreamSource;
|
||||||
import okhttp3.FormBody;
|
import okhttp3.FormBody;
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.RequestBody;
|
import okhttp3.RequestBody;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.jsoup.nodes.Element;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import static ctbrec.ErrorMessages.HTTP_RESPONSE_BODY_IS_NULL;
|
||||||
|
import static ctbrec.Model.State.*;
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
|
||||||
public class BongaCamsModel extends AbstractModel {
|
public class BongaCamsModel extends AbstractModel {
|
||||||
|
|
||||||
|
@ -47,28 +37,47 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
private static final String SUCCESS = "success";
|
private static final String SUCCESS = "success";
|
||||||
private static final String STATUS = "status";
|
private static final String STATUS = "status";
|
||||||
|
|
||||||
private int userId;
|
private static final Pattern ONLINE_BADGE_REGEX = Pattern.compile("class=\"badge_online\s*\"");
|
||||||
|
|
||||||
private boolean online = false;
|
private boolean online = false;
|
||||||
private transient List<StreamSource> streamSources = new ArrayList<>();
|
private final transient List<StreamSource> streamSources = new ArrayList<>();
|
||||||
private int[] resolution;
|
private int[] resolution;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
public boolean isOnline(boolean ignoreCache) throws IOException, ExecutionException, InterruptedException {
|
||||||
if (ignoreCache) {
|
if (ignoreCache) {
|
||||||
String url = "https://en.bongacams.com/" + URLEncoder.encode(getName(), StandardCharsets.UTF_8.name());
|
boolean modelIsConnected = basicOnlineCheck();
|
||||||
Request req = new Request.Builder().url(url)
|
if (!modelIsConnected) {
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
onlineState = OFFLINE;
|
||||||
.header(ACCEPT, "*")
|
online = false;
|
||||||
.header(ACCEPT_LANGUAGE, "en")
|
return false;
|
||||||
.header(REFERER, getSite().getBaseUrl())
|
}
|
||||||
.build();
|
|
||||||
try (Response resp = site.getHttpClient().execute(req)) {
|
return completeOnlineCheck();
|
||||||
String body = resp.body().string();
|
}
|
||||||
String chatType = parseChatType(body);
|
return online;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean completeOnlineCheck() throws IOException {
|
||||||
|
JSONObject roomData = getRoomData();
|
||||||
|
if (!roomData.has("performerData")) {
|
||||||
|
onlineState = UNKNOWN;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
JSONObject performerData = roomData.getJSONObject("performerData");
|
||||||
|
setDisplayName(performerData.optString("displayName"));
|
||||||
|
String chatType = performerData.optString("showType");
|
||||||
|
boolean isAway = performerData.optBoolean("isAway");
|
||||||
|
|
||||||
onlineState = mapState(chatType);
|
onlineState = mapState(chatType);
|
||||||
if (onlineState == ONLINE) {
|
if (onlineState == ONLINE) {
|
||||||
if (isStreamAvailable()) {
|
if (isStreamAvailable()) {
|
||||||
|
if (isAway) {
|
||||||
|
onlineState = AWAY;
|
||||||
|
online = false;
|
||||||
|
} else {
|
||||||
online = true;
|
online = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
online = false;
|
online = false;
|
||||||
onlineState = AWAY;
|
onlineState = AWAY;
|
||||||
|
@ -76,31 +85,38 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
} else {
|
} else {
|
||||||
online = false;
|
online = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
return online;
|
return online;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String parseChatType(String body) {
|
private boolean basicOnlineCheck() {
|
||||||
String chatType = "";
|
|
||||||
if (body.contains("chatType")) {
|
|
||||||
try {
|
try {
|
||||||
chatType = HtmlParser.getText(body, ".chatType");
|
String url = site.getBaseUrl() + "/profile/" + getName().toLowerCase();
|
||||||
} catch (HtmlParserException e) {
|
Request req = new Request.Builder().url(url).build();
|
||||||
LOG.warn("Online check didn't work", e);
|
try (Response resp = site.getHttpClient().execute(req)) {
|
||||||
|
if (resp.isSuccessful()) {
|
||||||
|
String body = Objects.requireNonNull(resp.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
|
Matcher m = ONLINE_BADGE_REGEX.matcher(body);
|
||||||
|
return m.find();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return chatType;
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Couldn't check if model is connected: {}", e.getLocalizedMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private State mapState(String chatType) {
|
public State mapState(String roomState) {
|
||||||
if (chatType.matches(".*? is in a public chat")) {
|
switch (roomState) {
|
||||||
return ONLINE;
|
case "private", "fullprivate":
|
||||||
} else if (chatType.matches(".*? is in a group chat")) {
|
|
||||||
return GROUP;
|
|
||||||
} else if (chatType.matches(".*? is in a private chat")) {
|
|
||||||
return PRIVATE;
|
return PRIVATE;
|
||||||
} else {
|
case "group":
|
||||||
|
return GROUP;
|
||||||
|
case "public":
|
||||||
|
return ONLINE;
|
||||||
|
default:
|
||||||
|
LOG.debug(roomState);
|
||||||
return OFFLINE;
|
return OFFLINE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +127,7 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
Request req = new Request.Builder().url(url).build();
|
Request req = new Request.Builder().url(url).build();
|
||||||
try (Response resp = site.getHttpClient().execute(req)) {
|
try (Response resp = site.getHttpClient().execute(req)) {
|
||||||
if (resp.isSuccessful()) {
|
if (resp.isSuccessful()) {
|
||||||
String body = resp.body().string();
|
String body = Objects.requireNonNull(resp.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
return body.contains("#EXT-X-STREAM-INF");
|
return body.contains("#EXT-X-STREAM-INF");
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
|
@ -124,7 +140,7 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
private JSONObject getRoomData() throws IOException {
|
private JSONObject getRoomData() throws IOException {
|
||||||
String url = BongaCams.baseUrl + "/tools/amf.php";
|
String url = getSite().getBaseUrl() + "/tools/amf.php";
|
||||||
RequestBody body = new FormBody.Builder()
|
RequestBody body = new FormBody.Builder()
|
||||||
.add("method", "getRoomData")
|
.add("method", "getRoomData")
|
||||||
.add(ARGS, getName())
|
.add(ARGS, getName())
|
||||||
|
@ -135,13 +151,13 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
.addHeader(REFERER, BongaCams.baseUrl)
|
.addHeader(REFERER, getSite().getBaseUrl())
|
||||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.post(body)
|
.post(body)
|
||||||
.build();
|
.build();
|
||||||
try (Response response = site.getHttpClient().execute(request)) {
|
try (Response response = site.getHttpClient().execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
JSONObject json = new JSONObject(response.body().string());
|
JSONObject json = new JSONObject(Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string());
|
||||||
return json;
|
return json;
|
||||||
} else {
|
} else {
|
||||||
throw new IOException(response.code() + " " + response.message());
|
throw new IOException(response.code() + " " + response.message());
|
||||||
|
@ -155,9 +171,7 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
public State getOnlineState(boolean failFast) throws IOException, ExecutionException {
|
||||||
if (failFast) {
|
if (!failFast) {
|
||||||
return onlineState;
|
|
||||||
} else {
|
|
||||||
try {
|
try {
|
||||||
isOnline(true);
|
isOnline(true);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
|
@ -166,8 +180,8 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
} catch (IOException | ExecutionException e) {
|
} catch (IOException | ExecutionException e) {
|
||||||
onlineState = OFFLINE;
|
onlineState = OFFLINE;
|
||||||
}
|
}
|
||||||
return onlineState;
|
|
||||||
}
|
}
|
||||||
|
return onlineState;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -181,10 +195,19 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
Request req = new Request.Builder().url(streamUrl).build();
|
Request req = new Request.Builder().url(streamUrl).build();
|
||||||
try (Response response = site.getHttpClient().execute(req)) {
|
try (Response response = site.getHttpClient().execute(req)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
InputStream inputStream = response.body().byteStream();
|
InputStream inputStream = Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).byteStream();
|
||||||
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
PlaylistParser parser = new PlaylistParser(inputStream, Format.EXT_M3U, Encoding.UTF_8, ParsingMode.LENIENT);
|
||||||
Playlist playlist = parser.parse();
|
Playlist playlist = parser.parse();
|
||||||
MasterPlaylist master = playlist.getMasterPlaylist();
|
MasterPlaylist master = playlist.getMasterPlaylist();
|
||||||
|
extractStreamSources(streamUrl, master);
|
||||||
|
} else {
|
||||||
|
throw new HttpException(response.code(), response.message());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return streamSources;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void extractStreamSources(String streamUrl, MasterPlaylist master) {
|
||||||
streamSources.clear();
|
streamSources.clear();
|
||||||
for (PlaylistData playlistData : master.getPlaylists()) {
|
for (PlaylistData playlistData : master.getPlaylists()) {
|
||||||
StreamSource streamsource = new StreamSource();
|
StreamSource streamsource = new StreamSource();
|
||||||
|
@ -201,11 +224,6 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
streamSources.add(streamsource);
|
streamSources.add(streamsource);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
throw new HttpException(response.code(), response.message());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return streamSources;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getStreamUrl() throws IOException {
|
private String getStreamUrl() throws IOException {
|
||||||
|
@ -226,8 +244,8 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void receiveTip(Double tokens) throws IOException {
|
public void receiveTip(Double tokens) throws IOException {
|
||||||
String url = BongaCams.baseUrl + "/chat-ajax-amf-service?" + System.currentTimeMillis();
|
String url = getSite().getBaseUrl() + "/chat-ajax-amf-service?" + System.currentTimeMillis();
|
||||||
userId = ((BongaCamsHttpClient)site.getHttpClient()).getUserId();
|
int userId = ((BongaCamsHttpClient) site.getHttpClient()).getUserId();
|
||||||
RequestBody body = new FormBody.Builder()
|
RequestBody body = new FormBody.Builder()
|
||||||
.add("method", "tipModel")
|
.add("method", "tipModel")
|
||||||
.add(ARGS, getName())
|
.add(ARGS, getName())
|
||||||
|
@ -240,13 +258,13 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.addHeader(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
.addHeader(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
.addHeader(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
.addHeader(REFERER, BongaCams.baseUrl + '/' + getName())
|
.addHeader(REFERER, getSite().getBaseUrl() + '/' + getName())
|
||||||
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.addHeader(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.post(body)
|
.post(body)
|
||||||
.build();
|
.build();
|
||||||
try (Response response = site.getHttpClient().execute(request)) {
|
try (Response response = site.getHttpClient().execute(request)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
JSONObject json = new JSONObject(response.body().string());
|
JSONObject json = new JSONObject(Objects.requireNonNull(response.body(), HTTP_RESPONSE_BODY_IS_NULL).string());
|
||||||
if (!json.optString(STATUS).equals(SUCCESS)) {
|
if (!json.optString(STATUS).equals(SUCCESS)) {
|
||||||
LOG.error("Sending tip failed {}", json.toString(2));
|
LOG.error("Sending tip failed {}", json.toString(2));
|
||||||
throw new IOException("Sending tip failed");
|
throw new IOException("Sending tip failed");
|
||||||
|
@ -279,10 +297,8 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
||||||
resolution = new int[2];
|
resolution = new int[2];
|
||||||
}
|
}
|
||||||
return resolution;
|
|
||||||
} else {
|
|
||||||
return resolution;
|
|
||||||
}
|
}
|
||||||
|
return resolution;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -308,7 +324,7 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
.build();
|
.build();
|
||||||
try (Response resp = site.getHttpClient().execute(req)) {
|
try (Response resp = site.getHttpClient().execute(req)) {
|
||||||
if (resp.isSuccessful()) {
|
if (resp.isSuccessful()) {
|
||||||
String msg = resp.body().string();
|
String msg = Objects.requireNonNull(resp.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
JSONObject json = new JSONObject(msg);
|
JSONObject json = new JSONObject(msg);
|
||||||
if (json.optBoolean(SUCCESS)) {
|
if (json.optBoolean(SUCCESS)) {
|
||||||
LOG.debug("Follow/Unfollow -> {}", msg);
|
LOG.debug("Follow/Unfollow -> {}", msg);
|
||||||
|
@ -328,12 +344,12 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
.url(getUrl())
|
.url(getUrl())
|
||||||
.header(ACCEPT, "*/*")
|
.header(ACCEPT, "*/*")
|
||||||
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
.header(ACCEPT_LANGUAGE, Locale.ENGLISH.getLanguage())
|
||||||
.header(REFERER, BongaCams.baseUrl)
|
.header(REFERER, getSite().getBaseUrl())
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.build();
|
.build();
|
||||||
try (Response resp = site.getHttpClient().execute(req)) {
|
try (Response resp = site.getHttpClient().execute(req)) {
|
||||||
if (resp.isSuccessful()) {
|
if (resp.isSuccessful()) {
|
||||||
String content = resp.body().string();
|
String content = Objects.requireNonNull(resp.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
Element html = HtmlParser.getTag(content, "html");
|
Element html = HtmlParser.getTag(content, "html");
|
||||||
String csrfToken = html.attr("data-csrf_value");
|
String csrfToken = html.attr("data-csrf_value");
|
||||||
LOG.debug("CSRF-Token {}", csrfToken);
|
LOG.debug("CSRF-Token {}", csrfToken);
|
||||||
|
@ -366,7 +382,7 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
.build();
|
.build();
|
||||||
try (Response resp = site.getHttpClient().execute(req)) {
|
try (Response resp = site.getHttpClient().execute(req)) {
|
||||||
if (resp.isSuccessful()) {
|
if (resp.isSuccessful()) {
|
||||||
String msg = resp.body().string();
|
String msg = Objects.requireNonNull(resp.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
JSONObject json = new JSONObject(msg);
|
JSONObject json = new JSONObject(msg);
|
||||||
if (json.optBoolean(SUCCESS)) {
|
if (json.optBoolean(SUCCESS)) {
|
||||||
LOG.debug("Follow/Unfollow -> {}", msg);
|
LOG.debug("Follow/Unfollow -> {}", msg);
|
||||||
|
@ -381,34 +397,19 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getUserId() throws IOException {
|
|
||||||
if (userId == 0) {
|
|
||||||
JSONObject roomData = getRoomData();
|
|
||||||
userId = roomData.getJSONObject("performerData").getInt("userId");
|
|
||||||
}
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUserId(int userId) {
|
|
||||||
this.userId = userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void mapOnlineState(String roomState) {
|
public void mapOnlineState(String roomState) {
|
||||||
switch (roomState) {
|
switch (roomState) {
|
||||||
case "private":
|
case "private", "fullprivate" -> setOnlineState(PRIVATE);
|
||||||
case "fullprivate":
|
case "group", "public" -> {
|
||||||
setOnlineState(PRIVATE);
|
|
||||||
break;
|
|
||||||
case "group":
|
|
||||||
case "public":
|
|
||||||
setOnlineState(ONLINE);
|
setOnlineState(ONLINE);
|
||||||
setOnline(true);
|
setOnline(true);
|
||||||
break;
|
}
|
||||||
default:
|
default -> {
|
||||||
LOG.debug(roomState);
|
LOG.debug(roomState);
|
||||||
setOnlineState(OFFLINE);
|
setOnlineState(OFFLINE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean exists() throws IOException {
|
public boolean exists() throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue