Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 08-06-2019, 07:50 AM   #1
dalanicolai
Junior Member
dalanicolai began at the beginning.
 
Posts: 5
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!
dalanicolai is offline   Reply With Quote
Old 08-06-2019, 08:37 AM   #2
BetterRed
null operator
BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.BetterRed ought to be getting tired of karma fortunes by now.
 
Posts: 15,450
Karma: 16370000
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
BetterRed is offline   Reply With Quote
Old 08-06-2019, 09:42 AM   #3
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 36,072
Karma: 15014853
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)
kovidgoyal is offline   Reply With Quote
Old 10-23-2019, 11:16 AM   #4
dalanicolai
Junior Member
dalanicolai began at the beginning.
 
Posts: 5
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)
dalanicolai is offline   Reply With Quote
Old 10-23-2019, 12:02 PM   #5
dalanicolai
Junior Member
dalanicolai began at the beginning.
 
Posts: 5
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!
dalanicolai is offline   Reply With Quote
Old 10-23-2019, 12:07 PM   #6
dalanicolai
Junior Member
dalanicolai began at the beginning.
 
Posts: 5
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.
dalanicolai is offline   Reply With Quote
Old 10-23-2019, 01:09 PM   #7
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 36,072
Karma: 15014853
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.
kovidgoyal is offline   Reply With Quote
Old 10-25-2019, 09:29 AM   #8
dalanicolai
Junior Member
dalanicolai began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Aug 2019
Device: PocketBook Touch Lux 3
Last opened library was indeed what I was looking for. Thanks!
dalanicolai is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python 2 to Python 3, Polyglot & Plugins DaltonST Calibre 18 04-24-2019 01:10 AM
FBReader update: hash vs filepath difficulties. taratears Android Devices 0 04-29-2017 06:00 PM
bash error iomari Calibre 2 08-19-2013 02:40 PM
Tell which kindle model from a filepath? stepk Kindle Developer's Corner 17 05-15-2013 09:54 AM
An available bash 4.2 for KT silverzhao Kindle Developer's Corner 2 02-06-2013 11:37 AM


All times are GMT -4. The time now is 09:31 AM.


MobileRead.com is a privately owned, operated and funded community.