Skip to content
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

Is it possible to download and open the book automatically when it’s on the cloud? #13

Open
realliyifei opened this issue Sep 12, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@realliyifei
Copy link

Apple Books always stores some books back to the iCloud if we don't use them for a long time.

image

Is it possible to download and open the book automatically when it’s on the cloud (just like what happens when we click the book in the books app)? Now the workflow works nothing on the non-local books.

image

@codycodes
Copy link
Owner

So AFAIK it really depends on which part of the cloud it's on, but at least partially it seems, yes! Up to now I've intentionally added the message to ensure the user knows they can just go into the app and download the book locally first, which is accomplished simply by checking in the Books database if there's a path to the book or not, and then checking if the path actually exists (which it doesn't if it's on your iCloud Drive but hasn't been downloaded locally):

alfred-books/src/book.py

Lines 57 to 60 in 53202bc

if row['ZPATH'] is not None:
book = Book(
title=row['ZTITLE'],
path=row['ZPATH'] if os.path.exists(row['ZPATH']) else None,

It is very interesting because using Spotlight search, you can actually open these books directly from iCloud; they will be downloaded and then have a path that exists; then Alfred Books will work as normal. I actually found a utility that can do this, which may be able to simulate or replicate the behavior of what is happening in Spotlight: brctl

It's a built-in utility which I've tested and works; it allows you to download an iCloud file using the path to it, which we have from the Books database. Unfortunately I don't yet know a good way to determine "when" the file is downloaded, meaning we may just need to poll for if the file exists for a certain time and then take an appropriate action... More info on this utility at this Stack Exchange link.

Now, this doesn't address an elephant in the room, which is if you have books that are stored in iCloud but aren't on your iCloud Drive. I believe this case pops up when you download from the iBooks Store from a separate computer; there is no book in your iCloud Drive because it's hosted on the iBooks Store. In this case, Spotlight will not find the books and Alfred Books currently won't either based on the logic it's currently using. There is a handy 'ZCANREDOWNLOAD' flag in the database which I assume allows you to know whether or not a book can be re-downloaded. In this case I think we need to push a message similar to the one currently displaying that Books needs to be opened first to be able to be opened in Alfred Books.

If we can get the iCloud Drive function working with the brctl command, that will probably take care of the common issue where you have a book on one device, stored in iCloud Drive, but not on the other. We can also just open the books app for books that are actioned but not downloaded and aren't stored on the user's iCloud Drive.

@codycodes codycodes added the enhancement New feature or request label Sep 12, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants