Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 07-16-2015, 11:40 AM   #1
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Calibredb export

Is there any 'selectivity' to control which subset of files are exported?

For example, I wanted to export epubs to a single folder, but only if the Tag=Science Fiction.


http://manual.calibre-ebook.com/cli/...libredb-export

It looks like I can list IDs, but that's not an easy thing to do

Quote:
Export the books specified by ids (a comma separated list) to the filesystem. The export operation saves all formats of the book, its cover and metadata (in an opf file). You can get id numbers from the list command.
Thanks
phossler is offline   Reply With Quote
Old 07-16-2015, 11:47 AM   #2
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: 44,214
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
As the help says, you get the list of ids by using

calibredb list

for example if you want to get the ids for books by Asimov, you use

calibredb list --search author:asimov
kovidgoyal is offline   Reply With Quote
Advert
Old 07-16-2015, 04:55 PM   #3
eschwartz
Ex-Helpdesk Junkie
eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.eschwartz ought to be getting tired of karma fortunes by now.
 
eschwartz's Avatar
 
Posts: 19,421
Karma: 85397180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
https://github.com/kovidgoyal/calibr...b8f5fac295a6b8
New command: `calibredb search "some-search"` to output a list of ids to use in some other command.

Thanks for the new option, Kovid!
(Much easier than commandline json parsing.)
eschwartz is offline   Reply With Quote
Old 07-16-2015, 08:31 PM   #4
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: 44,214
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You dont actually need to parse JSON to get a list of ids from calibredb list, you can just do, for example:

Code:
calibredb list --search whatever -f title --separator , | cut -d, -f1 | tail -n +2 | awk -vORS=, '{ print $1 }' | sed 's/,$/\n/'
Or on windows, where none of the unix tools are available, you can just use calibre-debug

Code:
calibredb list --search whatever -f title  | calibre-debug -c "import sys; print ','.join(filter(None, [line.partition(' ')[0].strip() for line in sys.stdin][1:]))"
But, I realize this kind of thing is hard for most people, hence calibredb search
kovidgoyal is offline   Reply With Quote
Old 07-16-2015, 08:34 PM   #5
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
As the help says, you get the list of ids by using

calibredb list

for example if you want to get the ids for books by Asimov, you use

calibredb list --search author:asimov
Actually I saw that in the manual but I couldn't figure out how to pass it to 'calibredb export' to only export epub books with certain tags

I did try various command lines, but

calibredb list --search format:=epub and tags:="science fiction"

seems to list non-Science Fiction and then error out
Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	250
Size:	53.7 KB
ID:	140321  
phossler is offline   Reply With Quote
Advert
Old 07-16-2015, 08:36 PM   #6
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: 44,214
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
You need to quote things properly, like this

calibredb list -f title --search 'format:=epub and tags:="science fiction"'

And note that the windows console dies if you output too much too it, which is the cause of the IOError you got.
kovidgoyal is offline   Reply With Quote
Old 07-16-2015, 09:14 PM   #7
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
You need to quote things properly, like this

calibredb list -f title --search 'format:=epub and tags:="science fiction"'
Sorry to be a pest, but I must be doing SOMETHING wrong.

Nothing lists now

I used your example and variations

Thanks
Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	261
Size:	146.9 KB
ID:	140322  

Last edited by phossler; 07-16-2015 at 09:22 PM. Reason: Forgot to say 'Thanks' :-(
phossler is offline   Reply With Quote
Old 07-16-2015, 09:31 PM   #8
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: 44,214
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I forgot, this is windows, I always forget that windows cmd.exe has insane quoting rules -- here you go

calibredb list -f title --search ^"format:=epub and tags:=^"science fiction^"^"
kovidgoyal is offline   Reply With Quote
Old 07-16-2015, 10:01 PM   #9
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
1. Thanks

2. I NEVER would have gotten that, ... but

calibredb list -f title --search ^"format:=epub and tags:=^"science fiction^"^"

is only finding tags = "Science" and not "Science Fiction"

Reading the manual about bracketing parameters with spaces with quotes, and assuming that the ^ is treated as a special escape character, what you provided looks like it should work.

It works great on a 'one word tag', but not one with a space

Can you provide a tweak for cmd.exe's insane quoting rules that works with spaces?

phossler is offline   Reply With Quote
Old 07-16-2015, 10:18 PM   #10
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: 44,214
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Not right now as I dont have access to a windows machine and this is likely to require some trial and error
kovidgoyal is offline   Reply With Quote
Old 07-16-2015, 10:22 PM   #11
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
Thanks -- no problem

I've already trialed and errored some variations that seems reasonable (to me anyways)

I suppose I could just re-tag as "ScienceFiction" but that feels like cheating

(I don't suppose that there's any chance calibredb is not parsing the command line correctly is there???)

Last edited by phossler; 07-16-2015 at 10:45 PM.
phossler is offline   Reply With Quote
Old 07-16-2015, 10:38 PM   #12
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: 44,214
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
No, no chance

IIRC you can use PowerShell which has better quoting rules, so my original recommendation would work

calibredb list -f title --search 'format:=epub and tags:="science fiction"'
kovidgoyal is offline   Reply With Quote
Old 07-17-2015, 10:22 PM   #13
phossler
Wizard
phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.phossler ought to be getting tired of karma fortunes by now.
 
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
1. The new calibredb search option works well and the parameters are intuitive (even using cmd.exe)

>calibredb search "tags:science fiction" format:mobi > SF_MOBI.TXT will return the intersection of "science fiction" and mobi (ID=515 in the screen shot)

Now I just have to figure out how to pass the txt file as a list of IDs to caliber export

2. As a 'By the way' the calibredb list --search ..... does seem to operate differently (other screen shot)

Thanks for the new CLI option
Attached Thumbnails
Click image for larger version

Name:	List.JPG
Views:	271
Size:	50.0 KB
ID:	140344   Click image for larger version

Name:	Search.JPG
Views:	209
Size:	56.1 KB
ID:	140345  
phossler is offline   Reply With Quote
Old 07-17-2015, 11:34 PM   #14
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: 44,214
Karma: 23446406
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
That is because everything after search is assumed to be part of the search expression, whereas when you use --search it has to consume only a *single* argument, which is why you have to enclose the entire search expression in quotes.

I have no idea if this works in cmd.exe, but in most modern shells you can simply do this:

calibredb export `calibredb search whatever`
kovidgoyal is offline   Reply With Quote
Old 07-18-2015, 06:42 AM   #15
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,868
Karma: 7036359
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by phossler View Post
Now I just have to figure out how to pass the txt file as a list of IDs to caliber export
The following works in Win 7 dos box, of course with appropriate changes for your configuration.
Code:
for /f "usebackq" %a in (`calibredb search "tags:science fiction"`) do calibredb export %a --to-dir=bar
And yes it is indeed ugly, but it works.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
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
calibredb exception (another!) ZioNemo Library Management 0 02-05-2014 02:31 PM
calibredb exception ZioNemo Library Management 3 02-04-2014 09:10 PM
calibredb iomari Calibre 6 10-10-2011 08:35 AM


All times are GMT -4. The time now is 03:01 PM.


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