Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre

Notices

Reply
 
Thread Tools Search this Thread
Old 02-22-2022, 08:15 AM   #1
Bertrand
Zealot
Bertrand began at the beginning.
 
Posts: 118
Karma: 10
Join Date: Dec 2008
Location: France
Device: None
CLI - calibredb export : how to export only books with a specific tag ?

calibre 5.37, Windows 10 21H2

I run regularly a batch file to export all my books. It works great but now I'd like to add a second export, but only for books having a specific tag.

Looking at the calibredb doc, I see no options to exclude/include tags.
So, is it possible or not ?

If not, any work around via the command line ?

Thanks.
Bertrand is offline   Reply With Quote
Old 02-22-2022, 11:42 AM   #2
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,000
Karma: 57259778
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Quote:
Originally Posted by Bertrand View Post
calibre 5.37, Windows 10 21H2

I run regularly a batch file to export all my books. It works great but now I'd like to add a second export, but only for books having a specific tag.

Looking at the calibredb doc, I see no options to exclude/include tags.
So, is it possible or not ?

If not, any work around via the command line ?

Thanks.
does this work for you?

Code:
calibredb --search tags:<the-tag-list-here>
theducks is offline   Reply With Quote
Advert
Old 02-23-2022, 05:30 AM   #3
Bertrand
Zealot
Bertrand began at the beginning.
 
Posts: 118
Karma: 10
Join Date: Dec 2008
Location: France
Device: None
Thanks for your answer.
Unfortunately, no, it doesn't work. There's no --search option in the export command.
It would be great to have some kind of filters when exporting.

But, you gave me an idea : according to the doc :
"calibredb search - The output format is useful to feed into other commands that accept a list of ids as input.""

So
Code:
calibredb search tags:"my tag"
give me all the ids I want

then
Code:
calibredb export id1,id2,etc --to-dir "I:\test"
and I get what I want.

Now the problem is, how do I pass this (big!) list of ids to the export command, in a batch file...
I'll have to think about it

Thanks !
Bertrand is offline   Reply With Quote
Old 02-23-2022, 07:41 AM   #4
theducks
Well trained by Cats
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 30,000
Karma: 57259778
Join Date: Aug 2009
Location: The Central Coast of California
Device: Kobo Libra2,Kobo Aura2v1, K4NT(Fixed: New Bat.), Galaxy Tab A
Someone who understands my Sig
I pointed you to an idea, you put it together and learned how to do more
theducks is offline   Reply With Quote
Old 02-23-2022, 04:30 PM   #5
BetterRed
null operator (he/him)
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: 20,699
Karma: 26966376
Join Date: Mar 2012
Location: Sydney Australia
Device: none
Quote:
Originally Posted by Bertrand View Post
. . .
Now the problem is, how do I pass this (big!) list of ids to the export command, in a batch file...
I'll have to think about it

Thanks !
|'d use a (big!) pipe

BR
BetterRed is offline   Reply With Quote
Advert
Old 02-24-2022, 07:46 AM   #6
thiago.eec
Guru
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 946
Karma: 1183425
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by Bertrand View Post
Now the problem is, how do I pass this (big!) list of ids to the export command, in a batch file...
On Windows, the batch file would look like this:

Code:
FOR /F "tokens=*" %%g IN ('calibredb search tags:"my tag"') do (SET IDS=%%g)
calibredb export %IDS% --to-dir "I:\test"
thiago.eec is online now   Reply With Quote
Old 02-24-2022, 10:40 AM   #7
Bertrand
Zealot
Bertrand began at the beginning.
 
Posts: 118
Karma: 10
Join Date: Dec 2008
Location: France
Device: None
Thanks.
That's what I ended up doing, using a for loop (the (big!) pipe didn't worked, thanks BetterRed

Now, it's working... partially.
One problem remains : some of my tags have spaces in their name, and I get strange results, or no result at all (nothing is exported).

For example : "Langue française"
In my library, I have 66 books with this tag, only 9 of them are exported.
"Littérature étrangère", 1057 books, only one book exported.
"Récits de voyages", 67 books, 4 books exported.

All other books having a tag with a single word are correctly exported, so I suspect the space in the name to be the culprit ?

Code:
set destfolder=I:\test
set searchtag="Littérature française"

calibre -s

del /s /q %destfolder% > nul

for /f %%A in ('calibredb search tags:"%searchtag%"') do (
calibredb export %%A ^
 --dont-asciiize --dont-save-cover --dont-write-opf ^
 --to-dir %destfolder% --progress ^
 --template "{author_sort} - {series}{series_index:0>2s|  | - } {title}"
  )
Bertrand is offline   Reply With Quote
Old 02-24-2022, 11:01 AM   #8
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 11,799
Karma: 7029971
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
You need to escape the quotes with backslashes, like this.
Code:
set searchtag=Alternate history
for /f %%A in ('calibredb search tags:\"%searchtag%\"') do (echo %%A)
You probably also want to put an equals in front of %searchtag% to force exact matching, as in
Code:
set searchtag=Alternate history
for /f %%A in ('calibredb search tags:\"=%searchtag%\"') do (echo %%A)
chaley is offline   Reply With Quote
Old 02-25-2022, 07:13 AM   #9
Bertrand
Zealot
Bertrand began at the beginning.
 
Posts: 118
Karma: 10
Join Date: Dec 2008
Location: France
Device: None
Great !
Now everything's fine.

Thanks to all
Bertrand is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mimic the Calibre Export Library using CLI Kevan Library Management 4 06-15-2020 06:44 PM
Preferred formats in calibredb export halloleo Library Management 3 03-30-2020 03:24 AM
Calibredb export phossler Library Management 18 07-18-2015 07:15 PM
CalibreDB Export Progress Indication?? phossler Calibre 2 01-26-2015 09:02 PM
Calibredb export: can I do a subset of books (based on a query)? spedinfargo Calibre 6 02-25-2014 03:18 PM


All times are GMT -4. The time now is 09:33 PM.


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