-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Google Scholar fetcher for downloading a single entry #7075
Changes from all commits
4c25a1d
3f389c4
90efdd1
531fcad
4fcfb61
60c74e1
f3488e2
62a5100
07e93f4
9cad830
f504609
6775728
b691aed
f34d7f8
5051e1b
625778f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.jabref.gui.dialogs; | ||
|
||
import java.util.concurrent.CountDownLatch; | ||
|
||
import javafx.application.Platform; | ||
import javafx.scene.control.ButtonType; | ||
import javafx.scene.web.WebView; | ||
|
||
import org.jabref.gui.util.BaseDialog; | ||
import org.jabref.logic.l10n.Localization; | ||
import org.jabref.logic.net.URLDownload; | ||
|
||
import org.jsoup.helper.W3CDom; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.w3c.dom.Document; | ||
|
||
public class CaptchaSolverDialog extends BaseDialog<String> implements org.jabref.logic.importer.fetcher.CaptchaSolver { | ||
|
||
public static final Logger LOGGER = LoggerFactory.getLogger(CaptchaSolverDialog.class); | ||
|
||
private WebView webView; | ||
|
||
public CaptchaSolverDialog() { | ||
super(); | ||
this.setTitle(Localization.lang("Captcha Solver")); | ||
getDialogPane().getButtonTypes().add(ButtonType.CLOSE); | ||
getDialogPane().lookupButton(ButtonType.CLOSE).setVisible(true); | ||
|
||
webView = new WebView(); | ||
webView.getEngine().setJavaScriptEnabled(true); | ||
webView.getEngine().setUserAgent(URLDownload.USER_AGENT); | ||
getDialogPane().setContent(webView); | ||
} | ||
|
||
@Override | ||
public String solve(String queryURL) { | ||
// slim implementation of https://news.kynosarges.org/2014/05/01/simulating-platform-runandwait/ | ||
final CountDownLatch doneLatch = new CountDownLatch(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You need to listen for the web engine ready event, see the preview Tab viewer where we add this highlight ja stuff There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
See https://openjfx.io/javadoc/11/javafx.web/javafx/scene/web/WebEngine.html There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is this happen synchronously? The interface for the Captcha solver is designed in a synchronous way. Otherwise all fetchers need to be changed. I'll be away anyway for the next days. Thus, you are free to experiment 😅 |
||
Platform.runLater(() -> { | ||
webView.getEngine().load(queryURL); | ||
// For the quick implementation, we ignore the result | ||
// Later, at "webView", we directly extract it from the web view | ||
this.showAndWait(); | ||
doneLatch.countDown(); | ||
}); | ||
try { | ||
doneLatch.await(); | ||
Document document = webView.getEngine().getDocument(); | ||
return W3CDom.asString(document, null); | ||
} catch (InterruptedException e) { | ||
LOGGER.error("Issues with the UI", e); | ||
} | ||
return ""; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.jabref.logic.importer.fetcher; | ||
|
||
public interface CaptchaSolver { | ||
|
||
/** | ||
* Instructs the user to solve the captcha given at | ||
* | ||
* @param queryURL the URL to query | ||
* @return html content after solving the captcha | ||
*/ | ||
String solve(String queryURL); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can also just start JabRef with -debug as program argument.