Change login process of Amateur.tv
This commit is contained in:
parent
3f75e03766
commit
f98e01d08c
|
@ -1,3 +1,9 @@
|
|||
4.5.4
|
||||
========================
|
||||
* Fix LiveJasmin followed tab
|
||||
* Add buttons to settings to delete cookies per site
|
||||
* Fix bug in minimal browser
|
||||
|
||||
4.5.3
|
||||
========================
|
||||
* Fix Cam4 login
|
||||
|
|
|
@ -41,6 +41,7 @@ public class ExternalBrowser implements AutoCloseable {
|
|||
private Object browserReadyLock = new Object();
|
||||
|
||||
private Map<String, CompletableFuture<Object>> responseFutures = new HashMap<>();
|
||||
private Runnable onReadyCallback;
|
||||
|
||||
public static ExternalBrowser getInstance() {
|
||||
return INSTANCE;
|
||||
|
@ -77,6 +78,8 @@ public class ExternalBrowser implements AutoCloseable {
|
|||
out.write('\n');
|
||||
out.flush();
|
||||
|
||||
onReadyCallback.run();
|
||||
|
||||
LOG.debug("Waiting for browser to terminate");
|
||||
p.waitFor();
|
||||
int exitValue = p.exitValue();
|
||||
|
@ -231,4 +234,9 @@ public class ExternalBrowser implements AutoCloseable {
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public ExternalBrowser onReady(Runnable onReadyCallback) {
|
||||
this.onReadyCallback = onReadyCallback;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,9 @@ public class AmateurTvElectronLoginDialog {
|
|||
config.put("h", 480);
|
||||
var msg = new JSONObject();
|
||||
msg.put("config", config);
|
||||
browser.run(msg, msgHandler);
|
||||
browser
|
||||
.onReady(this::onReady)
|
||||
.run(msg, msgHandler);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
throw new IOException("Couldn't wait for login dialog", e);
|
||||
|
@ -48,22 +50,6 @@ public class AmateurTvElectronLoginDialog {
|
|||
LOG.error("Didn't received a JSON object {}", line);
|
||||
} else {
|
||||
var json = new JSONObject(line);
|
||||
try {
|
||||
browser.executeJavaScript("let loginDialogVisible = document.querySelectorAll('div[class~=\"MuiDialog-container\"]').length > 1");
|
||||
browser.executeJavaScript("if (!loginDialogVisible) { document.querySelector('button').innerHTML.indexOf('I agree') >= 0 && document.querySelector('button').click(); }");
|
||||
browser.executeJavaScript("if (!loginDialogVisible) { document.querySelector('button[aria-label=\"open drawer\"]').click(); }"); // open the burger menu to get to the login button
|
||||
browser.executeJavaScript("if (!loginDialogVisible) { document.querySelectorAll('button').forEach(function(b) { if (b.textContent === 'Log in') b.click(); }); }"); // click the login button to open the login dialog
|
||||
browser.executeJavaScript("loginDialogVisible = document.querySelectorAll('div[class~=\"MuiDialog-container\"]').length > 1");
|
||||
browser.executeJavaScript("if (loginDialogVisible) throw new Error(\"Stop execution right here\")");
|
||||
// String username = Config.getInstance().getSettings().amateurTvUsername;
|
||||
// String password = Config.getInstance().getSettings().amateurTvPassword;
|
||||
// browser.executeJavaScript("if (loginDialogVisible) { document.querySelectorAll('div[class~=\"MuiDialog-container\"] input').item(0).value = '" + username + "' }"); // enter username
|
||||
// browser.executeJavaScript("if (loginDialogVisible) { document.querySelectorAll('div[class~=\"MuiDialog-container\"] input').item(1).value = '" + password + "' }"); // enter password
|
||||
//browser.executeJavaScript("console.log('submit')");
|
||||
// browser.executeJavaScript("if(loginDialogVisible) { document.querySelector('div[class~=\"MuiDialog-container\"] button[type=\"submit\"]').click() }"); // click the submit button
|
||||
} catch(Exception e) {
|
||||
LOG.warn("Couldn't auto fill username and password for Amateur.TV", e);
|
||||
}
|
||||
|
||||
var loginSuccessful = false;
|
||||
if (json.has("cookies")) {
|
||||
|
@ -99,10 +85,42 @@ public class AmateurTvElectronLoginDialog {
|
|||
if (loginSuccessful) {
|
||||
try {
|
||||
browser.close();
|
||||
return;
|
||||
} catch (IOException e) {
|
||||
LOG.error("Couldn't send shutdown request to external browser", e);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
browser.executeJavaScript("document.querySelector('div[class~=\"cy_ubCoins\"]') != null")
|
||||
.thenAccept(b -> {
|
||||
LOG.debug("Result: {}", b);
|
||||
if (Boolean.TRUE.equals(b)) {
|
||||
try {
|
||||
browser.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
})
|
||||
.exceptionally(ex -> {LOG.error("Error", ex); return null;});
|
||||
|
||||
browser.executeJavaScript("if (!loginDialogVisible) { document.querySelector('button').innerHTML.indexOf('I agree') >= 0 && document.querySelector('button').click(); }");
|
||||
browser.executeJavaScript("if (!loginDialogVisible) { document.querySelector('button[aria-label=\"open drawer\"]').click(); }"); // open the burger menu to get to the login button
|
||||
browser.executeJavaScript("if (!loginDialogVisible) { document.querySelectorAll('button').forEach(function(b) { if (b.textContent === 'Log in') b.click(); }); }"); // click the login button to open the login dialog
|
||||
browser.executeJavaScript("loginDialogVisible = document.querySelectorAll('div[class~=\"MuiDialog-container\"]').length > 1");
|
||||
browser.executeJavaScript("if (loginDialogVisible) throw new Error(\"Stop execution right here\")");
|
||||
} catch(Exception e) {
|
||||
LOG.warn("Couldn't auto fill username and password for Amateur.TV", e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private void onReady() {
|
||||
try {
|
||||
browser.executeJavaScript("let loginDialogVisible = document.querySelectorAll('div[class~=\"MuiDialog-container\"]').length > 1");
|
||||
} catch(Exception e) {
|
||||
LOG.warn("Couldn't auto fill username and password for Amateur.TV", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue