forked from j62/ctbrec
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,14 +46,14 @@ 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 {
|
||||||
var json = new JSONObject(line);
|
var json = new JSONObject(line);
|
||||||
if(json.has("url")) {
|
if (json.has("url")) {
|
||||||
var url = json.getString("url");
|
var url = json.getString("url");
|
||||||
if(url.endsWith("/login")) {
|
if (url.endsWith("/login")) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(500);
|
Thread.sleep(500);
|
||||||
String username = Config.getInstance().getSettings().bongaUsername;
|
String username = Config.getInstance().getSettings().bongaUsername;
|
||||||
|
@ -65,7 +65,7 @@ public class BongaCamsElectronLoginDialog {
|
||||||
password = password.replace("'", "\\'");
|
password = password.replace("'", "\\'");
|
||||||
browser.executeJavaScript("document.getElementById('log_in_password').value = '" + password + "';");
|
browser.executeJavaScript("document.getElementById('log_in_password').value = '" + password + "';");
|
||||||
}
|
}
|
||||||
var simplify = new String[] {
|
var simplify = new String[]{
|
||||||
"$('div[class~=\"page_header\"]').css('display','none');",
|
"$('div[class~=\"page_header\"]').css('display','none');",
|
||||||
"$('div[class~=\"header_bar\"]').css('display','none')",
|
"$('div[class~=\"header_bar\"]').css('display','none')",
|
||||||
"$('footer').css('display','none');",
|
"$('footer').css('display','none');",
|
||||||
|
@ -75,36 +75,36 @@ public class BongaCamsElectronLoginDialog {
|
||||||
for (String js : simplify) {
|
for (String js : simplify) {
|
||||||
browser.executeJavaScript(js);
|
browser.executeJavaScript(js);
|
||||||
}
|
}
|
||||||
} catch(InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
LOG.warn("Couldn't auto fill username and password for BongaCams", e);
|
LOG.warn("Couldn't auto fill username and password for BongaCams", e);
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Couldn't auto fill username and password for BongaCams", e);
|
LOG.warn("Couldn't auto fill username and password for BongaCams", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json.has("cookies")) {
|
if (json.has("cookies")) {
|
||||||
var cookiesFromBrowser = json.getJSONArray("cookies");
|
var cookiesFromBrowser = json.getJSONArray("cookies");
|
||||||
for (var i = 0; i < cookiesFromBrowser.length(); i++) {
|
for (var i = 0; i < cookiesFromBrowser.length(); i++) {
|
||||||
var cookie = cookiesFromBrowser.getJSONObject(i);
|
var cookie = cookiesFromBrowser.getJSONObject(i);
|
||||||
if(cookie.getString("domain").contains(DOMAIN)) {
|
if (cookie.getString("domain").contains(DOMAIN)) {
|
||||||
Builder b = new Cookie.Builder()
|
Builder b = new Cookie.Builder()
|
||||||
.path(cookie.getString("path"))
|
.path(cookie.getString("path"))
|
||||||
.domain(DOMAIN)
|
.domain(DOMAIN)
|
||||||
.name(cookie.getString("name"))
|
.name(cookie.getString("name"))
|
||||||
.value(cookie.getString("value"))
|
.value(cookie.getString("value"))
|
||||||
.expiresAt((long) cookie.optDouble("expirationDate"));
|
.expiresAt((long) cookie.optDouble("expirationDate"));
|
||||||
if(cookie.optBoolean("hostOnly")) {
|
if (cookie.optBoolean("hostOnly")) {
|
||||||
b.hostOnlyDomain(DOMAIN);
|
b.hostOnlyDomain(DOMAIN);
|
||||||
}
|
}
|
||||||
if(cookie.optBoolean("httpOnly")) {
|
if (cookie.optBoolean("httpOnly")) {
|
||||||
b.httpOnly();
|
b.httpOnly();
|
||||||
}
|
}
|
||||||
if(cookie.optBoolean("secure")) {
|
if (cookie.optBoolean("secure")) {
|
||||||
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
|
||||||
|
@ -65,8 +63,8 @@ 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,14 +74,14 @@ 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");
|
||||||
} else {
|
} else {
|
||||||
|
@ -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,39 +140,25 @@ 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<>();
|
||||||
JSONArray results = json.getJSONArray("models");
|
parseModelList(models, json);
|
||||||
for (int i = 0; i < results.length(); i++) {
|
|
||||||
JSONObject result = results.getJSONObject(i);
|
|
||||||
if(result.has("username")) {
|
|
||||||
Model model = createModel(result.getString("username"));
|
|
||||||
String thumb = result.getString("thumb_image").replace("{ext}", "jpg");
|
|
||||||
if(thumb != null) {
|
|
||||||
model.setPreview("https:" + thumb);
|
|
||||||
}
|
|
||||||
if(result.has("display_name")) {
|
|
||||||
model.setDisplayName(result.getString("display_name"));
|
|
||||||
}
|
|
||||||
models.add(model);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return models;
|
return models;
|
||||||
} else {
|
} else {
|
||||||
LOG.warn("Search result: " + json.toString(2));
|
LOG.warn("Search result: {}", json.toString(2));
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -183,6 +167,24 @@ public class BongaCams extends AbstractSite {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void parseModelList(List<Model> models, JSONObject json) {
|
||||||
|
JSONArray results = json.getJSONArray("models");
|
||||||
|
for (int i = 0; i < results.length(); i++) {
|
||||||
|
JSONObject result = results.getJSONObject(i);
|
||||||
|
if (result.has("username")) {
|
||||||
|
Model model = createModel(result.getString("username"));
|
||||||
|
String thumb = result.getString("thumb_image").replace("{ext}", "jpg");
|
||||||
|
if (thumb != null) {
|
||||||
|
model.setPreview("https:" + thumb);
|
||||||
|
}
|
||||||
|
if (result.has("display_name")) {
|
||||||
|
model.setDisplayName(result.getString("display_name"));
|
||||||
|
}
|
||||||
|
models.add(model);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isSiteForModel(Model m) {
|
public boolean isSiteForModel(Model m) {
|
||||||
return m instanceof BongaCamsModel;
|
return m instanceof BongaCamsModel;
|
||||||
|
@ -197,7 +199,7 @@ public class BongaCams extends AbstractSite {
|
||||||
@Override
|
@Override
|
||||||
public Model createModelFromUrl(String url) {
|
public Model createModelFromUrl(String url) {
|
||||||
Matcher m = Pattern.compile("https?://.*?bongacams.com(?:/profile)?/([^/]*?)/?").matcher(url);
|
Matcher m = Pattern.compile("https?://.*?bongacams.com(?:/profile)?/([^/]*?)/?").matcher(url);
|
||||||
if(m.matches()) {
|
if (m.matches()) {
|
||||||
String modelName = m.group(1);
|
String modelName = m.group(1);
|
||||||
return createModel(modelName);
|
return createModel(modelName);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -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,24 +46,19 @@ 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized boolean login() throws IOException {
|
public synchronized boolean login() throws IOException {
|
||||||
if(loggedIn) {
|
if (loggedIn) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean cookiesWorked = checkLoginSuccess();
|
boolean cookiesWorked = checkLoginSuccess();
|
||||||
if(cookiesWorked) {
|
if (cookiesWorked) {
|
||||||
loggedIn = true;
|
loggedIn = true;
|
||||||
LOG.debug("Logged in with cookies");
|
LOG.debug("Logged in with cookies");
|
||||||
return true;
|
return true;
|
||||||
|
@ -76,33 +69,32 @@ 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");
|
||||||
return userId > 0;
|
return userId > 0;
|
||||||
|
@ -120,23 +112,23 @@ 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");
|
||||||
JSONObject m = jsonModels.getJSONObject(0);
|
JSONObject m = jsonModels.getJSONObject(0);
|
||||||
String name = m.getString("username");
|
String name = m.getString("username");
|
||||||
return name;
|
return name;
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Request was not successful: " + content);
|
throw new IOException("Request was not successful: " + content);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -145,45 +137,8 @@ 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();
|
||||||
}
|
}
|
||||||
return userId;
|
return userId;
|
||||||
|
|
|
@ -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,61 +37,87 @@ 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)) {
|
|
||||||
String body = resp.body().string();
|
|
||||||
String chatType = parseChatType(body);
|
|
||||||
onlineState = mapState(chatType);
|
|
||||||
if (onlineState == ONLINE) {
|
|
||||||
if (isStreamAvailable()) {
|
|
||||||
online = true;
|
|
||||||
} else {
|
|
||||||
online = false;
|
|
||||||
onlineState = AWAY;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
online = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return completeOnlineCheck();
|
||||||
}
|
}
|
||||||
return online;
|
return online;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String parseChatType(String body) {
|
private boolean completeOnlineCheck() throws IOException {
|
||||||
String chatType = "";
|
JSONObject roomData = getRoomData();
|
||||||
if (body.contains("chatType")) {
|
if (!roomData.has("performerData")) {
|
||||||
try {
|
onlineState = UNKNOWN;
|
||||||
chatType = HtmlParser.getText(body, ".chatType");
|
return false;
|
||||||
} catch (HtmlParserException e) {
|
|
||||||
LOG.warn("Online check didn't work", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return chatType;
|
JSONObject performerData = roomData.getJSONObject("performerData");
|
||||||
|
setDisplayName(performerData.optString("displayName"));
|
||||||
|
String chatType = performerData.optString("showType");
|
||||||
|
boolean isAway = performerData.optBoolean("isAway");
|
||||||
|
|
||||||
|
onlineState = mapState(chatType);
|
||||||
|
if (onlineState == ONLINE) {
|
||||||
|
if (isStreamAvailable()) {
|
||||||
|
if (isAway) {
|
||||||
|
onlineState = AWAY;
|
||||||
|
online = false;
|
||||||
|
} else {
|
||||||
|
online = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
online = false;
|
||||||
|
onlineState = AWAY;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
online = false;
|
||||||
|
}
|
||||||
|
return online;
|
||||||
}
|
}
|
||||||
|
|
||||||
private State mapState(String chatType) {
|
private boolean basicOnlineCheck() {
|
||||||
if (chatType.matches(".*? is in a public chat")) {
|
try {
|
||||||
return ONLINE;
|
String url = site.getBaseUrl() + "/profile/" + getName().toLowerCase();
|
||||||
} else if (chatType.matches(".*? is in a group chat")) {
|
Request req = new Request.Builder().url(url).build();
|
||||||
return GROUP;
|
try (Response resp = site.getHttpClient().execute(req)) {
|
||||||
} else if (chatType.matches(".*? is in a private chat")) {
|
if (resp.isSuccessful()) {
|
||||||
return PRIVATE;
|
String body = Objects.requireNonNull(resp.body(), HTTP_RESPONSE_BODY_IS_NULL).string();
|
||||||
} else {
|
Matcher m = ONLINE_BADGE_REGEX.matcher(body);
|
||||||
return OFFLINE;
|
return m.find();
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOG.warn("Couldn't check if model is connected: {}", e.getLocalizedMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public State mapState(String roomState) {
|
||||||
|
switch (roomState) {
|
||||||
|
case "private", "fullprivate":
|
||||||
|
return PRIVATE;
|
||||||
|
case "group":
|
||||||
|
return GROUP;
|
||||||
|
case "public":
|
||||||
|
return ONLINE;
|
||||||
|
default:
|
||||||
|
LOG.debug(roomState);
|
||||||
|
return OFFLINE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,20 +127,20 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.warn("Couldn't check if stream is available: {}", e.getLocalizedMessage());
|
LOG.warn("Couldn't check if stream is available: {}", e.getLocalizedMessage());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
||||||
|
@ -179,28 +193,13 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
|
public List<StreamSource> getStreamSources() throws IOException, ExecutionException, ParseException, PlaylistException {
|
||||||
String streamUrl = getStreamUrl();
|
String streamUrl = getStreamUrl();
|
||||||
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();
|
||||||
streamSources.clear();
|
extractStreamSources(streamUrl, master);
|
||||||
for (PlaylistData playlistData : master.getPlaylists()) {
|
|
||||||
StreamSource streamsource = new StreamSource();
|
|
||||||
streamsource.mediaPlaylistUrl = streamUrl.replace("playlist.m3u8", playlistData.getUri());
|
|
||||||
if (playlistData.hasStreamInfo()) {
|
|
||||||
StreamInfo info = playlistData.getStreamInfo();
|
|
||||||
streamsource.bandwidth = info.getBandwidth();
|
|
||||||
streamsource.width = info.hasResolution() ? info.getResolution().width : 0;
|
|
||||||
streamsource.height = info.hasResolution() ? info.getResolution().height : 0;
|
|
||||||
} else {
|
|
||||||
streamsource.bandwidth = 0;
|
|
||||||
streamsource.width = 0;
|
|
||||||
streamsource.height = 0;
|
|
||||||
}
|
|
||||||
streamSources.add(streamsource);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
throw new HttpException(response.code(), response.message());
|
||||||
}
|
}
|
||||||
|
@ -208,6 +207,25 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
return streamSources;
|
return streamSources;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void extractStreamSources(String streamUrl, MasterPlaylist master) {
|
||||||
|
streamSources.clear();
|
||||||
|
for (PlaylistData playlistData : master.getPlaylists()) {
|
||||||
|
StreamSource streamsource = new StreamSource();
|
||||||
|
streamsource.mediaPlaylistUrl = streamUrl.replace("playlist.m3u8", playlistData.getUri());
|
||||||
|
if (playlistData.hasStreamInfo()) {
|
||||||
|
StreamInfo info = playlistData.getStreamInfo();
|
||||||
|
streamsource.bandwidth = info.getBandwidth();
|
||||||
|
streamsource.width = info.hasResolution() ? info.getResolution().width : 0;
|
||||||
|
streamsource.height = info.hasResolution() ? info.getResolution().height : 0;
|
||||||
|
} else {
|
||||||
|
streamsource.bandwidth = 0;
|
||||||
|
streamsource.width = 0;
|
||||||
|
streamsource.height = 0;
|
||||||
|
}
|
||||||
|
streamSources.add(streamsource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private String getStreamUrl() throws IOException {
|
private String getStreamUrl() throws IOException {
|
||||||
JSONObject roomData = getRoomData();
|
JSONObject roomData = getRoomData();
|
||||||
if (roomData.optString(STATUS).equals(SUCCESS)) {
|
if (roomData.optString(STATUS).equals(SUCCESS)) {
|
||||||
|
@ -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,14 +258,14 @@ 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");
|
||||||
}
|
}
|
||||||
|
@ -259,18 +277,18 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int[] getStreamResolution(boolean failFast) throws ExecutionException {
|
public int[] getStreamResolution(boolean failFast) throws ExecutionException {
|
||||||
if(resolution == null) {
|
if (resolution == null) {
|
||||||
if(failFast) {
|
if (failFast) {
|
||||||
return new int[2];
|
return new int[2];
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if(!isOnline()) {
|
if (!isOnline()) {
|
||||||
return new int[2];
|
return new int[2];
|
||||||
}
|
}
|
||||||
List<StreamSource> sources = getStreamSources();
|
List<StreamSource> sources = getStreamSources();
|
||||||
Collections.sort(sources);
|
Collections.sort(sources);
|
||||||
StreamSource best = sources.get(sources.size()-1);
|
StreamSource best = sources.get(sources.size() - 1);
|
||||||
resolution = new int[] {best.width, best.height};
|
resolution = new int[]{best.width, best.height};
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
LOG.warn("Couldn't determine stream resolution for {} - {}", getName(), e.getMessage());
|
||||||
|
@ -279,15 +297,13 @@ 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
|
||||||
public boolean follow() throws IOException {
|
public boolean follow() throws IOException {
|
||||||
if(!getSite().login()) {
|
if (!getSite().login()) {
|
||||||
throw new IOException("Not logged in");
|
throw new IOException("Not logged in");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,11 +322,11 @@ public class BongaCamsModel extends AbstractModel {
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
.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);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -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,32 +397,17 @@ 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);
|
setOnlineState(ONLINE);
|
||||||
break;
|
setOnline(true);
|
||||||
case "group":
|
}
|
||||||
case "public":
|
default -> {
|
||||||
setOnlineState(ONLINE);
|
LOG.debug(roomState);
|
||||||
setOnline(true);
|
setOnlineState(OFFLINE);
|
||||||
break;
|
}
|
||||||
default:
|
|
||||||
LOG.debug(roomState);
|
|
||||||
setOnlineState(OFFLINE);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue