08-06-2019, 06:50 AM | #1 |
Junior Member
Posts: 9
Karma: 10
Join Date: Aug 2019
Device: PocketBook Touch Lux 3
|
Get filepath with bash or python
Hi everyone,
Excuse me for posting this seemingly very simple question, but I've already spent quite some time now to find out how to obtain the filepath of a book using either the caliber CLI or the database API. I would like to use the calibre database to quicklaunch a book with ulauncher without opening the full calibre gui. For this I would like to implement the functionality in the "Tracker recoll docfetcher locate search" plugin. Anybody knows a quick way to obtain the filepath using calibre tools? (unfortunately I am only a hobbyist trying to learn python but understanding the calibre design is still quite overwhelming) Thanks! |
08-06-2019, 07:37 AM | #2 |
null operator (he/him)
Posts: 20,570
Karma: 26954694
Join Date: Mar 2012
Location: Sydney Australia
Device: none
|
Have a look at the calibrespy plugin, you'll find what I think you're looking for in calibrespy_dialog.py at about line 1965
BR |
08-06-2019, 08:42 AM | #3 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
calibredb list -f formats --for-machine
or using a python API, assuming you already have a db object Code:
db.new_api.format_files(book_id) |
10-23-2019, 10:16 AM | #4 |
Junior Member
Posts: 9
Karma: 10
Join Date: Aug 2019
Device: PocketBook Touch Lux 3
|
Ah... hi guys! Sorry I never saw your answers before. I think I never got notified about it.
Anyway thanks for your answers. In the meantime I got the extension working. If you like you can find it here https://github.com/dalanicolai/gnome-tracker-extension. Despite its name, it is actually a quite versatile deep file search extension and it includes a cb keyword to search directly in the calibre database file. @kovidgoyal Thanks for creating calibre and share it. It is a truly awesome software obviously! (Just want to launch some books quickly sometimes without opening the calibre gui first) |
10-23-2019, 11:02 AM | #5 |
Junior Member
Posts: 9
Karma: 10
Join Date: Aug 2019
Device: PocketBook Touch Lux 3
|
@kovidgoyal
Maybe I can ask you two more small question also, if you have time for it. Otherwise do not mind about answering at all, because the extension is working fine already. 1. I did not know from where to get the calibre library path unambiguously. For example it could be possible that a foreign user, like me, has accidently two calibre folders (two different languages) in his home directory. I figured out that probably I get the correct used library path from the global.py file in the .config/calibre folder. I am hoping that this file always contains the correct in use calibre library path (in general). 2. I did not find an easy way to use some AND operator in sqlite. I want to be able to enter two query words that are contained either in the title or in the author_sort columns (I could not find simply an author column). I ended up using a subquery as follows: results = c.execute('select title, author_sort, path from books where (title like "%{}%" or author_sort like "%{}%") and id in (select id from books where title like "%{}%" or author_sort like "%{}%")'.format(queries[1], queries[1], queries[0], queries[0])) I was hoping you remember how you would nicely execute a query like this in sqlite. Sorry I am only learning things by myself from the internet. Again do not mind about answering if it costs too much time. I just assume you must be quite an expert and you can answer these question by heart. In any case... thanks again! |
10-23-2019, 11:07 AM | #6 |
Junior Member
Posts: 9
Karma: 10
Join Date: Aug 2019
Device: PocketBook Touch Lux 3
|
@kovidgoyal
Of course I did not see your message before I implemented this. I realize now that probably you use a similar solution as I did (with the subquery) using the python db api. |
10-23-2019, 12:09 PM | #7 |
creator of calibre
Posts: 43,858
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
global.py.json does indeed store the last opened library in calibre. Note that there is no "correct" library since you can have as many libraries as you want in calibre.
|
10-25-2019, 08:29 AM | #8 |
Junior Member
Posts: 9
Karma: 10
Join Date: Aug 2019
Device: PocketBook Touch Lux 3
|
Last opened library was indeed what I was looking for. Thanks!
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Python 2 to Python 3, Polyglot & Plugins | DaltonST | Calibre | 18 | 04-24-2019 12:10 AM |
FBReader update: hash vs filepath difficulties. | taratears | Android Devices | 0 | 04-29-2017 05:00 PM |
bash error | iomari | Calibre | 2 | 08-19-2013 01:40 PM |
Tell which kindle model from a filepath? | stepk | Kindle Developer's Corner | 17 | 05-15-2013 08:54 AM |
An available bash 4.2 for KT | silverzhao | Kindle Developer's Corner | 2 | 02-06-2013 10:37 AM |