Jump to content

Search Calibre Library


Recommended Posts

Hey Folks,

 

I'm wondering if anybody has a workflow that works similar to the Bookends workflow, which would enabling the searching of a Calibre library within Alfred. If not, does anybody have suggestions on what would be required in the workflow to do this? I'm thinking that the calibredb terminal commands would be helpful, but I'm not clear on how to get a workflow to play with that, particularly within Alfred, rather than as a mere jumping-off point for Terminal. Any help is appreciated!

Link to comment

You’ll need to parse the output of calibredb list to a format that can be understood by a Script Filter.


But alright, you want to call the workflow, and it shows a list of all your books — title, author, and year. You then start typing, and your books are filtered to only show the ones that match your search. That is somewhat trivial to accomplish, but what should happen then? What happens when you ↩ on a result?

Link to comment

metadata.db is SQLite and it's worth querying that instead. I'm not sure if it's worth modifying it; I don't know if that's recommended but you could check. Reading the DB, you should be able to then open any book in any viewer or editor of your choice, or possibly send commands to calibre if that is exposed.

 

My current workflow in progress uses the Python library Peewee with SQLite and PostgreSQL; it's very pleasant to work with. A script filter could query the DB for authors, list of books, or just books and authors. deanishe's alfred-workflow framework is also wonderful for various needs such as returning results to Alfred. I'm a bit new with Alfred so I'm not sure if it's possible, but it seems not yet. What would be great is for example: press return to open book, cmd-return to reveal in finder, shift-cmd to edit metadata, cmd-option return to edit book, etc. For now, it seems you'd need separate filters for each command.

 

 

Edited by h2ner
Link to comment
1 hour ago, h2ner said:

metadata.db is SQLite and it's worth querying that instead.

 

You make it sound like that’s a superior option. Why would it be better to parse the database directly when they give you tools to specifically handle that? Not only are those tools simpler to use (smaller and more immediate commands), they’re officially supported, meaning they’re less prone to errors and will continued to work if they ever change the database format. They even let you output the list in a machine-friendlier format (JSON).

 

1 hour ago, h2ner said:

I'm not sure if it's worth modifying it; I don't know if that's recommended but you could check.

 

It is not recommended. They specifically warn about modifying the database without informing the GUI even with their own tools. Said tools do inform the GUI, unless you specifically tell them not to.

 

For the needs of this workflow as defined now, querying the database is strictly worse.

Edited by vitor
Link to comment
On 12/24/2016 at 10:44 AM, vitor said:

You’ll need to parse the output of calibredb list to a format that can be understood by a Script Filter.


But alright, you want to call the workflow, and it shows a list of all your books — title, author, and year. You then start typing, and your books are filtered to only show the ones that match your search. That is somewhat trivial to accomplish, but what should happen then? What happens when you ↩ on a result?

 

Thanks for the response, vitor. To be honest, I mostly just want to be able to search through a list of books in my library to see what I already have. I make extensive use of my University's library, sometimes downloading eBook copies of books that I haven't read, likely won't read, but would like to have around. Then I forget what I've downloaded, and come across a book and wonder, "do I have this?" Right now I seem forced to open Calibre and search; Alfred will only show the folder in the Calibre Library, but not the PDFs/ePubs themselves.

 

That said, I suppose if I'm going through the effort, I might as well put in some functionality. Primarily what I do is either (a) convert a book to MOBI to read on my Kindle, (b) and/or email the file. So I suppose I'd (1) parse output of calibredb list into a format understood by Script Filter; (2) pass selected object on via opt/ctrl/cmd designators to a selected terminal script...should work, yes?

 

 

 

1 hour ago, h2ner said:

metadata.db is SQLite and it's worth querying that instead. I'm not sure if it's worth modifying it; I don't know if that's recommended but you could check. Reading the DB, you should be able to then open any book in any viewer or editor of your choice, or possibly send commands to calibre if that is exposed.

 

My current workflow in progress uses the Python library Peewee with SQLite and PostgreSQL; it's very pleasant to work with. A script filter could query the DB for authors, list of books, or just books and authors. deanishe's alfred-workflow framework is also wonderful for various needs such as returning results to Alfred. I'm a bit new with Alfred so I'm not sure if it's possible, but it seems not yet. What would be great is for example: press return to open book, cmd-return to reveal in finder, shift-cmd to edit metadata, cmd-option return to edit book, etc. For now, it seems you'd need separate filters for each command.

 

 

 

Thanks, h2ner. I've used Alfred for a while, but am still (and will likely ever be) a coding newb. I'll stick with vitor's approach, as SQLite scares me!

Link to comment
6 hours ago, calebaharrison said:

Alfred will only show the folder in the Calibre Library, but not the PDFs/ePubs themselves.

 

That's not right. Alfred should be able to find your ePubs/PDFs etc. just fine: an Alfred File Filter is how I search my Calibre library.

 

I assumed you needed access to the tags or some other metadata, and that's why you're after accessing Calibre's database directly.

Edited by deanishe
Link to comment
21 hours ago, deanishe said:

 

That's not right. Alfred should be able to find your ePubs/PDFs etc. just fine: an Alfred File Filter is how I search my Calibre library.

 

I assumed you needed access to the tags or some other metadata, and that's why you're after accessing Calibre's database directly.

 

I'm guessing by "that's not right," you mean "that's not what should be happening." I agree! Oddly, if .e.g, I search for a book called "Steering the Craft," Alfred will return the Calibre folder in which it resides, but not the eBook itself. Only if I search with the extension (e.g., '.mobi Steering the Craft) will it return the file itself. (Most likely, this is Alfred behaving correctly, and I am misunderstanding the interactions of tweaks I might have made to its search functioning.) At any rate, I will try the File Filter approach (restricting scope to the Calibre library), and do something more in-depth another day. Thanks!

Link to comment

I think you haven't quite apprehended The Alfred Way. You'll get the best results from Alfred by keeping your default result scope small (to keep searches fast and relevant), and then adding File Filters for specific types of files and/or specific directories.

 

So rather than adding your Calibre library to your default Search Scope (and ePub/mobi filetypes via the Advanced… button), you should create a File Filter pointed at your Calibre library configured to find .epub, .mobi, .pdf etc. files.

 

Edited by deanishe
add a "specific" to be more specific
Link to comment
  • 2 years later...
  • 4 years later...

I've been happily using @deanishe's workflow above to search within the Calibre app using Alfred 4. But I've just installed Alfred 5, and the workflow doesn't seem to work there. It brings Calibre to the front but doesn't search - and doesn't highlight the search-bar in Calibre, so I think the script must be failing at the point where it uses Cmd-F to enter the search-bar. I've checked all the variables and they are the same in both version of Alfred.

 

I've had a look at a couple of other workflows that have been posted but can't get any of them to work in Alfred 5 either.

 

Would anyone with more expertise than me be willing to try to fix this?

Link to comment

Welcome @DED,

 

When reporting issues, please include your exact installed versions of:

  • The Workflow.
  • Alfred.
  • macOS.

In addition to:

  • The debugger output. Perform the failing action, click “Copy” on the top right and paste it here.
  • Details on what you did, what happened, and what you expected to happen.

That information is crucial to understand what could be going on.

 

Same thing for any other workflow you’re having trouble with. Also, make sure to look in the Alfred Gallery as well, as workflows which are no longer maintained may have alternatives there.

Link to comment

Thanks for the reply. I was playing around with some other new things in Alfred 5 and I don't know what I've changed to make the Calibre search works, but now it works. I suspect it was something in Mac Accessibility, but I can't be sure.

Link to comment
58 minutes ago, DED said:

I suspect it was something in Mac Accessibility

 

That is likely. Nothing in Alfred 5 broke workflow functionally, so lack of permissions from the system is a good guess. Glad you’re sorted!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...