Make Showup login work with minimal browser
This commit is contained in:
parent
5f4e17c2d2
commit
cf165b7fc0
|
@ -34,6 +34,7 @@ public class ShowupElectronLoginDialog {
|
||||||
config.put("url", URL);
|
config.put("url", URL);
|
||||||
config.put("w", 640);
|
config.put("w", 640);
|
||||||
config.put("h", 480);
|
config.put("h", 480);
|
||||||
|
config.put("userAgent", Config.getInstance().getSettings().httpUserAgent);
|
||||||
JSONObject msg = new JSONObject();
|
JSONObject msg = new JSONObject();
|
||||||
msg.put("config", config);
|
msg.put("config", config);
|
||||||
browser.run(msg, msgHandler);
|
browser.run(msg, msgHandler);
|
||||||
|
@ -50,7 +51,6 @@ public class ShowupElectronLoginDialog {
|
||||||
System.err.println(line); // NOSONAR
|
System.err.println(line); // NOSONAR
|
||||||
} else {
|
} else {
|
||||||
JSONObject json = new JSONObject(line);
|
JSONObject json = new JSONObject(line);
|
||||||
//LOG.debug("Browser: {}", json.toString(2));
|
|
||||||
if(json.has("url")) {
|
if(json.has("url")) {
|
||||||
String url = json.getString("url");
|
String url = json.getString("url");
|
||||||
LOG.debug(url);
|
LOG.debug(url);
|
||||||
|
@ -66,33 +66,31 @@ public class ShowupElectronLoginDialog {
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
LOG.warn("Couldn't auto fill username and password for Showup", e);
|
LOG.warn("Couldn't auto fill username and password for Showup", e);
|
||||||
}
|
}
|
||||||
} else if(url.equals(URL + '/')) {
|
} else if(url.equals(URL + '/') && firstCall) {
|
||||||
if(firstCall) {
|
firstCall = false;
|
||||||
firstCall = false;
|
try {
|
||||||
try {
|
Thread.sleep(500);
|
||||||
Thread.sleep(500);
|
browser.executeJavaScript("user.openLoginPopUp();");
|
||||||
browser.executeJavaScript("user.openLoginPopUp();");
|
String username = Config.getInstance().getSettings().showupUsername;
|
||||||
String username = Config.getInstance().getSettings().showupUsername;
|
if (username != null && !username.trim().isEmpty()) {
|
||||||
if (username != null && !username.trim().isEmpty()) {
|
browser.executeJavaScript("$('input[name=\"email\"]').attr('value','" + username + "')");
|
||||||
browser.executeJavaScript("$('input[name=\"email\"]').attr('value','" + username + "')");
|
|
||||||
}
|
|
||||||
String password = Config.getInstance().getSettings().showupPassword;
|
|
||||||
if (password != null && !password.trim().isEmpty()) {
|
|
||||||
password = password.replace("'", "\\'");
|
|
||||||
browser.executeJavaScript("$('input[name=\"password\"]').attr('value','" + password + "')");
|
|
||||||
}
|
|
||||||
browser.executeJavaScript("$('input[name=\"remember\"]').attr('value','true')");
|
|
||||||
return;
|
|
||||||
} catch(Exception e) {
|
|
||||||
LOG.warn("Couldn't auto fill username and password for Showup", e);
|
|
||||||
}
|
}
|
||||||
|
String password = Config.getInstance().getSettings().showupPassword;
|
||||||
|
if (password != null && !password.trim().isEmpty()) {
|
||||||
|
password = password.replace("'", "\\'");
|
||||||
|
browser.executeJavaScript("$('input[name=\"password\"]').attr('value','" + password + "')");
|
||||||
|
}
|
||||||
|
browser.executeJavaScript("$('input[name=\"remember\"]').attr('value','true')");
|
||||||
|
return;
|
||||||
|
} catch(Exception e) {
|
||||||
|
LOG.warn("Couldn't auto fill username and password for Showup", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(json.has("cookies")) {
|
if(json.has("cookies")) {
|
||||||
JSONArray _cookies = json.getJSONArray("cookies");
|
JSONArray cookies = json.getJSONArray("cookies");
|
||||||
for (int i = 0; i < _cookies.length(); i++) {
|
for (int i = 0; i < cookies.length(); i++) {
|
||||||
JSONObject cookie = _cookies.getJSONObject(i);
|
JSONObject cookie = cookies.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"))
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package ctbrec.io;
|
package ctbrec.io;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -196,7 +198,7 @@ public abstract class HttpClient {
|
||||||
|
|
||||||
File cookieFile = new File(Config.getInstance().getConfigDir(), "cookies-" + name + ".json");
|
File cookieFile = new File(Config.getInstance().getConfigDir(), "cookies-" + name + ".json");
|
||||||
try(FileOutputStream fout = new FileOutputStream(cookieFile)) {
|
try(FileOutputStream fout = new FileOutputStream(cookieFile)) {
|
||||||
fout.write(json.getBytes("utf-8"));
|
fout.write(json.getBytes(UTF_8));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOG.error("Couldn't persist cookies for {}", name, e);
|
LOG.error("Couldn't persist cookies for {}", name, e);
|
||||||
|
@ -211,7 +213,7 @@ public abstract class HttpClient {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
byte[] jsonBytes = Files.readAllBytes(cookieFile.toPath());
|
byte[] jsonBytes = Files.readAllBytes(cookieFile.toPath());
|
||||||
String json = new String(jsonBytes, "utf-8");
|
String json = new String(jsonBytes, UTF_8);
|
||||||
|
|
||||||
Map<String, List<Cookie>> cookies = cookieJar.getCookies();
|
Map<String, List<Cookie>> cookies = cookieJar.getCookies();
|
||||||
Moshi moshi = new Moshi.Builder()
|
Moshi moshi = new Moshi.Builder()
|
||||||
|
@ -267,7 +269,6 @@ public abstract class HttpClient {
|
||||||
}
|
}
|
||||||
|
|
||||||
public WebSocket newWebSocket(Request request, WebSocketListener l) {
|
public WebSocket newWebSocket(Request request, WebSocketListener l) {
|
||||||
//Request request = new Request.Builder().url(url).build();
|
|
||||||
return client.newWebSocket(request, l);
|
return client.newWebSocket(request, l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ public abstract class AbstractHlsDownload extends AbstractDownload {
|
||||||
protected State state = State.UNKNOWN;
|
protected State state = State.UNKNOWN;
|
||||||
private int playlistEmptyCount = 0;
|
private int playlistEmptyCount = 0;
|
||||||
|
|
||||||
public AbstractHlsDownload(HttpClient client) {
|
protected AbstractHlsDownload(HttpClient client) {
|
||||||
this.client = client;
|
this.client = client;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,16 +10,12 @@ import java.util.Map;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Settings;
|
|
||||||
import ctbrec.io.HttpClient;
|
import ctbrec.io.HttpClient;
|
||||||
import ctbrec.io.HttpException;
|
import ctbrec.io.HttpException;
|
||||||
import okhttp3.Cookie;
|
import okhttp3.Cookie;
|
||||||
import okhttp3.FormBody;
|
|
||||||
import okhttp3.Request;
|
import okhttp3.Request;
|
||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
|
|
||||||
|
@ -77,39 +73,53 @@ public class ShowupHttpClient extends HttpClient {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean login() throws IOException {
|
public boolean login() throws IOException {
|
||||||
Settings settings = Config.getInstance().getSettings();
|
return checkLoginSuccess();
|
||||||
FormBody body = new FormBody.Builder()
|
// Settings settings = Config.getInstance().getSettings();
|
||||||
.add("is_ajax", "1")
|
// FormBody body = new FormBody.Builder()
|
||||||
.add("email", settings.showupUsername)
|
// .add("is_ajax", "1")
|
||||||
.add("password", settings.showupPassword)
|
// .add("email", settings.showupUsername)
|
||||||
.add("remember", "1")
|
// .add("password", settings.showupPassword)
|
||||||
.build();
|
// .add("remember", "1")
|
||||||
|
// .build();
|
||||||
|
// Request req = new Request.Builder()
|
||||||
|
// .url(Showup.BASE_URL)
|
||||||
|
// .header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
|
// .header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
||||||
|
// .header(REFERER, Showup.BASE_URL + '/')
|
||||||
|
// .header(ORIGIN, Showup.BASE_URL)
|
||||||
|
// .header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
||||||
|
// .post(body)
|
||||||
|
// .build();
|
||||||
|
//
|
||||||
|
// try (Response response = execute(req)) {
|
||||||
|
// if (response.isSuccessful()) {
|
||||||
|
// String responseBody = response.body().string();
|
||||||
|
// if (responseBody.startsWith("{")) {
|
||||||
|
// JSONObject json = new JSONObject(responseBody);
|
||||||
|
// return json.optString("status").equalsIgnoreCase("success");
|
||||||
|
// } else {
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// throw new HttpException(response.code(), response.message());
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkLoginSuccess() throws IOException {
|
||||||
Request req = new Request.Builder()
|
Request req = new Request.Builder()
|
||||||
.url(Showup.BASE_URL)
|
.url(Showup.BASE_URL)
|
||||||
|
.header(ACCEPT_LANGUAGE, "pl")
|
||||||
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
.header(USER_AGENT, Config.getInstance().getSettings().httpUserAgent)
|
||||||
.header(X_REQUESTED_WITH, XML_HTTP_REQUEST)
|
|
||||||
.header(REFERER, Showup.BASE_URL + '/')
|
|
||||||
.header(ORIGIN, Showup.BASE_URL)
|
|
||||||
.header(ACCEPT, MIMETYPE_APPLICATION_JSON)
|
|
||||||
.post(body)
|
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try (Response response = execute(req)) {
|
try (Response response = execute(req)) {
|
||||||
if (response.isSuccessful()) {
|
if (response.isSuccessful()) {
|
||||||
String responseBody = response.body().string();
|
String responseBody = response.body().string();
|
||||||
if (responseBody.startsWith("{")) {
|
loggedIn = responseBody.contains("Wyloguj");
|
||||||
JSONObject json = new JSONObject(responseBody);
|
return loggedIn;
|
||||||
return json.optString("status").equalsIgnoreCase("success");
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
throw new HttpException(response.code(), response.message());
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkLoginSuccess() {
|
|
||||||
return loggedIn;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package ctbrec.sites.showup;
|
package ctbrec.sites.showup;
|
||||||
|
|
||||||
import static ctbrec.Model.State.*;
|
import static ctbrec.Model.State.*;
|
||||||
|
import static ctbrec.io.HttpConstants.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
|
|
||||||
|
@ -19,6 +22,8 @@ import ctbrec.AbstractModel;
|
||||||
import ctbrec.Config;
|
import ctbrec.Config;
|
||||||
import ctbrec.Model;
|
import ctbrec.Model;
|
||||||
import ctbrec.recorder.download.Download;
|
import ctbrec.recorder.download.Download;
|
||||||
|
import ctbrec.recorder.download.HttpHeaderFactory;
|
||||||
|
import ctbrec.recorder.download.HttpHeaderFactoryImpl;
|
||||||
import ctbrec.recorder.download.StreamSource;
|
import ctbrec.recorder.download.StreamSource;
|
||||||
|
|
||||||
public class ShowupModel extends AbstractModel {
|
public class ShowupModel extends AbstractModel {
|
||||||
|
@ -131,4 +136,21 @@ public class ShowupModel extends AbstractModel {
|
||||||
return new ShowupMergedDownload(getSite().getHttpClient());
|
return new ShowupMergedDownload(getSite().getHttpClient());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public HttpHeaderFactory getHttpHeaderFactory() {
|
||||||
|
HttpHeaderFactoryImpl fac = new HttpHeaderFactoryImpl();
|
||||||
|
Map<String, String> headers = new HashMap<>();
|
||||||
|
headers.put(ACCEPT, "*/*");
|
||||||
|
headers.put(ACCEPT_LANGUAGE, "pl");
|
||||||
|
headers.put(CONNECTION, KEEP_ALIVE);
|
||||||
|
if (getSite() != null) {
|
||||||
|
headers.put(REFERER, getSite().getBaseUrl());
|
||||||
|
}
|
||||||
|
headers.put(USER_AGENT, Config.getInstance().getSettings().httpUserAgent);
|
||||||
|
fac.setMasterPlaylistHeaders(headers);
|
||||||
|
fac.setSegmentPlaylistHeaders(headers);
|
||||||
|
fac.setSegmentHeaders(headers);
|
||||||
|
return fac;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue