Updates for version 1.1.2
This commit is contained in:
parent
12e7a2d2d4
commit
3776ed5071
13 changed files with 218 additions and 92 deletions
|
@ -50,8 +50,6 @@ public class AudibleClient extends WebClient {
|
|||
}
|
||||
});
|
||||
|
||||
CookieManager cm = this.getCookieManager();
|
||||
|
||||
|
||||
this.waitForBackgroundJavaScript(15000);
|
||||
if (!maxDebug) {
|
||||
|
|
|
@ -63,27 +63,6 @@ public class AudibleScraper {
|
|||
this.page = page;
|
||||
LOG.info("pageLoaded:" + page.getUrl() + " " + page.getTitleText());
|
||||
|
||||
|
||||
if (page != null && debugCust) {
|
||||
String xml = page.asXml();
|
||||
int i1 = xml.indexOf("cust_id");
|
||||
|
||||
int i2 = xml.indexOf("order_number");
|
||||
String s1 = "", s2 = "";
|
||||
if (i1 != -1) {
|
||||
s1 = xml.substring(i1 - 300, i1 + 300);
|
||||
}
|
||||
if (i2 != -1) {
|
||||
s2 = xml.substring(i2 - 300, i2 + 300);
|
||||
}
|
||||
if (s1.length() > 0 || s2.length() > 0) {
|
||||
LOG.info("Found cust_id:s1=" + s1 + "\ns2=" + s2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// progress.setSubTask("page.getTitleText());
|
||||
|
||||
}
|
||||
|
||||
public boolean isLoggedIn() {
|
||||
|
@ -109,7 +88,7 @@ public class AudibleScraper {
|
|||
} else {
|
||||
if (page != null) {
|
||||
String u = page.getUrl().toString();
|
||||
ConnectionNotifier.getInstance().setLastURL(u);
|
||||
ConnectionNotifier.getInstance().loginFailed(u, page.asXml());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -144,7 +123,7 @@ public class AudibleScraper {
|
|||
setLoggedIn(false);
|
||||
}
|
||||
|
||||
public void saveCookies() throws IOException {
|
||||
public void saveCookies() throws IOException {
|
||||
|
||||
CookieManager cm = getWebClient().getCookieManager();
|
||||
ArrayList<BasicClientCookie> list = new ArrayList<>();
|
||||
|
@ -232,12 +211,24 @@ public class AudibleScraper {
|
|||
|
||||
if (getProgress() != null)
|
||||
getProgress().setTask("Submitting credentials...");
|
||||
HTMLUtil.debugNode(page, "submitting-credentials");
|
||||
|
||||
setPage(submit.click());
|
||||
boolean ok = checkLoggedIn();
|
||||
|
||||
if (!ok)
|
||||
HTMLUtil.debugNode(page, "login submitted");
|
||||
{
|
||||
HTMLUtil.debugNode(page, "login failed");
|
||||
LOG.info(page.getUrl());
|
||||
|
||||
LOG.info("Login failed, see html files at:"+HTMLUtil.debugFile("submitting-credentials").getAbsolutePath()+" and "+HTMLUtil.debugFile("login failed").getAbsolutePath());
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
HTMLUtil.debugFile("submitting-credentials").delete();
|
||||
}
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
@ -455,30 +446,6 @@ public class AudibleScraper {
|
|||
}
|
||||
|
||||
|
||||
/*
|
||||
private DomDocumentFragment getLibraryFragment(int pageNum, int items) throws IOException, SAXException {
|
||||
EventTimer evt = new EventTimer();
|
||||
String url = getAudibleBase()+"/lib-ajax";
|
||||
WebRequest webRequest = new WebRequest(new URL(url), HttpMethod.POST);
|
||||
webRequest.setRequestBody("progType=all&timeFilter=all&itemsPerPage=" + items + "&searchTerm=&searchType=&sortColumn=&sortType=down&page=" + pageNum + "&mode=normal&subId=&subTitle=");
|
||||
WebResponse webResponse = getWebClient().getWebConnection().getResponse(webRequest);
|
||||
String content = webResponse.getContentAsString();
|
||||
DomDocumentFragment frag = new DomDocumentFragment(page);
|
||||
HTMLParser.parseFragment(frag, content);
|
||||
LOG.info(evt.reportString("get Library Page:" + pageNum));
|
||||
return frag;
|
||||
}
|
||||
|
||||
|
||||
public Collection<Book> fetchFirstLibraryPage() throws Exception {
|
||||
if (page == null)
|
||||
home();
|
||||
LOG.info("Accessing audible library...");
|
||||
HashSet<Book> results = new HashSet<>();
|
||||
lib();
|
||||
return results;
|
||||
}
|
||||
*/
|
||||
|
||||
public Collection<Book> fetchLibraryQuick(HashMap<String, Book> books) throws Exception {
|
||||
return _fetchLibrary(books);
|
||||
|
@ -487,7 +454,7 @@ public class AudibleScraper {
|
|||
public Collection<Book> _fetchLibrary(HashMap<String, Book> existingBooks) throws Exception {
|
||||
if (page == null)
|
||||
home();
|
||||
LOG.info("Accessing audible library...");
|
||||
// LOG.info("Accessing audible library...");
|
||||
HashSet<Book> results = new HashSet<>();
|
||||
// getWebClient().setJavascriptEnabled(false);
|
||||
progress.setTask("Scanning your library to get your list of books...", "");
|
||||
|
@ -511,21 +478,8 @@ public class AudibleScraper {
|
|||
if (next == null) {
|
||||
assert (pageNum == 1);
|
||||
setURL("/lib", "Reading Library...");
|
||||
setPageFilter();
|
||||
|
||||
DomElement purchaseDateFilter = page.getElementByName("purchaseDateFilter");
|
||||
if (purchaseDateFilter!=null)
|
||||
{
|
||||
DomNodeList<DomNode> nodes = purchaseDateFilter.getChildNodes();
|
||||
for (DomNode n:nodes)
|
||||
{
|
||||
if (n instanceof HtmlOption)
|
||||
{
|
||||
// "all" is first option..
|
||||
((HtmlOption) n).click();
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// getProgress().setTask("Getting a list of your library. );
|
||||
EventTimer evt = new EventTimer();
|
||||
|
@ -555,7 +509,7 @@ public class AudibleScraper {
|
|||
int newBooks = 0;
|
||||
|
||||
for (Book b : list) {
|
||||
LOG.info(b.toString());
|
||||
// LOG.info(b.toString());
|
||||
if (b.partial())
|
||||
continue;
|
||||
if (results.contains(b)) {
|
||||
|
@ -577,12 +531,57 @@ public class AudibleScraper {
|
|||
next = LibraryParser.instance.getNextPage(page);
|
||||
if (next == null)
|
||||
break;
|
||||
//LOG.info("next page:"+next);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public Collection<Book> fetchLibrary() throws Exception {
|
||||
private void setPageFilter()
|
||||
{
|
||||
DomElement purchaseDateFilter = page.getElementByName("purchaseDateFilter");
|
||||
if (purchaseDateFilter!=null && purchaseDateFilter instanceof HtmlSelect)
|
||||
{
|
||||
HtmlSelect h = (HtmlSelect)purchaseDateFilter;
|
||||
int i = h.getSelectedIndex();
|
||||
if (i!=0)
|
||||
{
|
||||
HtmlOption all = h.getOption(0);
|
||||
String url = all.getAttribute("data-url");
|
||||
try
|
||||
{
|
||||
if (url!=null && !url.isEmpty())
|
||||
{
|
||||
//LOG.info("url: "+ url);
|
||||
String newURL = url+ "&purchaseDateFilter=all&programFilter=all&sortBy=PURCHASE_DATE.dsc";
|
||||
page = (HtmlPage) setURL(newURL, "Setting view filter");
|
||||
LOG.info("new URL: "+ page.getUrl());
|
||||
}
|
||||
h = (HtmlSelect) page.getElementByName("purchaseDateFilter");
|
||||
i = h.getSelectedIndex();
|
||||
if (i!=0)
|
||||
{
|
||||
LOG.error("Expected filter to be set to 0, not "+i);
|
||||
}
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
LOG.error("Error setting filter.. update may be required.",e);
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
} else
|
||||
{
|
||||
LOG.info("warning: did not find library filter htmlSelect.");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public Collection<Book> fetchLibrary() throws Exception {
|
||||
return _fetchLibrary(null);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ import org.openaudible.AudibleAccountPrefs;
|
|||
*/
|
||||
public interface ConnectionListener {
|
||||
void connectionChanged(boolean connected);
|
||||
|
||||
AudibleAccountPrefs getAccountPrefs(AudibleAccountPrefs in);
|
||||
|
||||
void loginFailed(String url, String html);
|
||||
}
|
||||
|
|
|
@ -53,17 +53,25 @@ public class ConnectionNotifier extends EventNotifier<ConnectionListener> implem
|
|||
return getState() == State.Disconnected;
|
||||
}
|
||||
|
||||
public void setLastURL(String u) {
|
||||
|
||||
|
||||
}
|
||||
|
||||
// not connected is unknown.
|
||||
// connected means in account
|
||||
// disconnected means a password is being asked for.
|
||||
enum State {
|
||||
Not_Connected, Connected, Disconnected
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void loginFailed(String url, String html)
|
||||
{
|
||||
for (ConnectionListener l : getListeners()) {
|
||||
l.loginFailed(url, html);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -247,6 +247,10 @@ public enum LibraryParser {
|
|||
|
||||
HashMap<String, String> args = Util.urlGetArgs(url);
|
||||
for (String k : args.keySet()) {
|
||||
|
||||
|
||||
|
||||
|
||||
BookElement elem = BookElement.findByName(k);
|
||||
if (elem != null) {
|
||||
b.set(elem, args.get(k));
|
||||
|
|
|
@ -10,7 +10,26 @@ public enum BookElement {
|
|||
try {
|
||||
return BookElement.valueOf(s);
|
||||
} catch (Throwable th) {
|
||||
System.out.println("No BookElement:" + s);
|
||||
switch(s)
|
||||
{
|
||||
case "title":
|
||||
return shortTitle;
|
||||
case "DownloadType":
|
||||
break;
|
||||
case "domain":
|
||||
break;
|
||||
case "awtype":
|
||||
break;
|
||||
case "transfer_player":
|
||||
break;
|
||||
|
||||
default:
|
||||
//
|
||||
System.out.println("No BookElement:" + s);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,10 @@ import org.openaudible.desktop.swt.manager.menu.AppMenu;
|
|||
import org.openaudible.desktop.swt.manager.menu.CommandCenter;
|
||||
import org.openaudible.desktop.swt.util.shop.LayoutShop;
|
||||
import org.openaudible.desktop.swt.util.shop.PaintShop;
|
||||
import org.openaudible.util.Platform;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class GUI implements ITranslatable {
|
||||
/**
|
||||
|
@ -156,6 +160,39 @@ public abstract class GUI implements ITranslatable {
|
|||
return (isWindows() || isSolaris() || isMac());
|
||||
}
|
||||
|
||||
public static void explore(File m) {
|
||||
|
||||
String mac = "open ";
|
||||
|
||||
|
||||
String cmd = null;
|
||||
switch(Platform.getPlatform())
|
||||
{
|
||||
|
||||
case mac:
|
||||
cmd = "open ";
|
||||
if (!m.isDirectory()) cmd += "-R ";
|
||||
break;
|
||||
case win:
|
||||
cmd = "Explorer /select, ";
|
||||
break;
|
||||
case linux:
|
||||
cmd = "gnome-open PATH ";
|
||||
break;
|
||||
}
|
||||
|
||||
if (cmd != null) {
|
||||
cmd += "\"" + m.getAbsolutePath() + "\"";
|
||||
System.err.println(cmd);
|
||||
try {
|
||||
Runtime.getRuntime().exec(cmd);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public abstract String getAppName();
|
||||
|
||||
public abstract String getAppNameAndVersion();
|
||||
|
|
|
@ -7,7 +7,9 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.MessageBox;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.openaudible.Audible;
|
||||
import org.openaudible.AudibleAccountPrefs;
|
||||
|
@ -565,20 +567,8 @@ public class AudibleGUI implements BookListener, ConnectionListener {
|
|||
Book b = onlyOneSelected();
|
||||
File m = audible.getMP3FileDest(b);
|
||||
if (m.exists()) {
|
||||
String mac = "open -R ";
|
||||
String win = "Explorer /select, ";
|
||||
GUI.explore(m);
|
||||
|
||||
String cmd = null;
|
||||
if (Platform.isMac())
|
||||
cmd = mac;
|
||||
if (Platform.isWindows())
|
||||
cmd = win;
|
||||
// TODO: Support linux.
|
||||
if (cmd != null) {
|
||||
cmd += "\"" + m.getAbsolutePath() + "\"";
|
||||
System.err.println(cmd);
|
||||
Runtime.getRuntime().exec(cmd);
|
||||
}
|
||||
|
||||
// Desktop.getDesktop().open(m.getParentFile());
|
||||
}
|
||||
|
@ -1163,4 +1153,21 @@ public class AudibleGUI implements BookListener, ConnectionListener {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginFailed(String url, String html)
|
||||
{
|
||||
|
||||
SWTAsync.slow(new SWTAsync("Login problem...") {
|
||||
public void task() {
|
||||
String message = "There was a problem logging in... Try to view the page in the OpenAudible Browser?";
|
||||
boolean ok = MessageBoxFactory.showGeneralYesNo(null, "Trouble logging in", message);
|
||||
if (ok)
|
||||
browse(url);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -3,7 +3,7 @@ package org.openaudible.desktop.swt.manager;
|
|||
public interface Version {
|
||||
|
||||
String appName = "OpenAudible";
|
||||
String appVersion = "1.1.1";
|
||||
String appVersion = "1.1.2";
|
||||
boolean appDebug = false;
|
||||
String appLink = "http://openaudible.org";
|
||||
String versionLink = "http://openaudible.org/swt_version.json";
|
||||
|
|
|
@ -258,19 +258,38 @@ public class AudibleBrowser {
|
|||
new BrowserFunction(browser, "cookieCallback") {
|
||||
@Override
|
||||
public Object function(Object[] objects) {
|
||||
|
||||
ArrayList<Cookie> list = new ArrayList<>();
|
||||
String u = browser.getUrl();
|
||||
|
||||
if (u.contains("audible.")) {
|
||||
// Get host from url.
|
||||
// https://www.audible.com/
|
||||
String host = "www.audible.com";
|
||||
|
||||
if (u.startsWith("http"))
|
||||
{
|
||||
String[] parts = u.split("/");
|
||||
if (parts!=null && parts.length>2)
|
||||
{
|
||||
if (parts[2].contains("audible"))
|
||||
host = parts[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Object[] keyValuePairs = (Object[]) objects[0];
|
||||
for (Object o : keyValuePairs) {
|
||||
Object arr[] = (Object[]) o;
|
||||
Cookie c = new Cookie("www.audible.com", arr[0].toString(), arr[1].toString());
|
||||
Cookie c = new Cookie(host, arr[0].toString(), arr[1].toString());
|
||||
list.add(c);
|
||||
}
|
||||
cookies = list;
|
||||
} else
|
||||
logger.info("Expected url to include audible, instead: " + u);
|
||||
|
||||
logger.info("cookieCallback: " + list.size());
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
@ -279,8 +298,8 @@ public class AudibleBrowser {
|
|||
new BrowserFunction(browser, "pageInfoCallback") {
|
||||
@Override
|
||||
public Object function(Object[] objects) {
|
||||
ArrayList<Cookie> list = new ArrayList<>();
|
||||
|
||||
String u = browser.getUrl();
|
||||
logger.info("pageInfoCallback: " + u);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -4,6 +4,8 @@ import org.apache.commons.logging.Log;
|
|||
import org.apache.commons.logging.LogFactory;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.MouseAdapter;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
|
@ -12,6 +14,7 @@ import org.openaudible.Audible;
|
|||
import org.openaudible.AudibleAccountPrefs;
|
||||
import org.openaudible.AudibleRegion;
|
||||
import org.openaudible.Directories;
|
||||
import org.openaudible.desktop.swt.gui.GUI;
|
||||
import org.openaudible.desktop.swt.gui.MessageBoxFactory;
|
||||
import org.openaudible.desktop.swt.manager.AudibleGUI;
|
||||
|
||||
|
@ -179,6 +182,7 @@ public class Preferences extends Dialog {
|
|||
createAccountGroup(c);
|
||||
createDirectoryGroup(c);
|
||||
createAutomationGroup(c);
|
||||
createPrefsLocation(c);
|
||||
|
||||
this.getShell().setText("Preferences");
|
||||
populate();
|
||||
|
@ -186,6 +190,26 @@ public class Preferences extends Dialog {
|
|||
return null;
|
||||
}
|
||||
|
||||
private void createPrefsLocation(GridComposite c) {
|
||||
c = new GridComposite(c, SWT.NONE, 2, false, GridData.FILL_HORIZONTAL);
|
||||
|
||||
String loc = Directories.getDir(Directories.META).getAbsolutePath();
|
||||
String name = Directories.META.displayName();
|
||||
Label l = new Label(c, SWT.NONE);
|
||||
l.setText(name+": "+loc);
|
||||
|
||||
GridData gd = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
|
||||
|
||||
Button b = c.newButton(SWT.PUSH, "Show");
|
||||
b.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
GUI.explore(Directories.getDir(Directories.META));
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void createAccountGroup(GridComposite c) {
|
||||
|
||||
Group group = c.newGroup("Audible Account", 3);
|
||||
|
|
|
@ -144,5 +144,12 @@ public class StatusPanel extends GridComposite implements BookListener, Connecti
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loginFailed(String url, String html)
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -90,6 +90,11 @@ public class HTMLUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static File debugFile(String what)
|
||||
{
|
||||
return new File(Directories.getTmpDir(), what);
|
||||
}
|
||||
|
||||
public static String debugNode(DomNode p, String what) {
|
||||
String xml = "";
|
||||
|
||||
|
|
Loading…
Reference in a new issue