07-16-2015, 11:40 AM | #1 | |
Wizard
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:
|
|
07-16-2015, 11:47 AM | #2 |
creator of calibre
Posts: 44,317
Karma: 23661992
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 |
Advert | |
|
07-16-2015, 04:55 PM | #3 |
Ex-Helpdesk Junkie
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.) |
07-16-2015, 08:31 PM | #4 |
creator of calibre
Posts: 44,317
Karma: 23661992
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/' 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:]))" |
07-16-2015, 08:34 PM | #5 | |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Quote:
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 |
|
Advert | |
|
07-16-2015, 08:36 PM | #6 |
creator of calibre
Posts: 44,317
Karma: 23661992
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. |
07-16-2015, 09:14 PM | #7 | |
Wizard
Posts: 1,085
Karma: 412718
Join Date: Jan 2009
Location: Valley Forge, PA, USA
Device: Kindle Paperwhite
|
Quote:
Nothing lists now I used your example and variations Thanks Last edited by phossler; 07-16-2015 at 09:22 PM. Reason: Forgot to say 'Thanks' :-( |
|
07-16-2015, 09:31 PM | #8 |
creator of calibre
Posts: 44,317
Karma: 23661992
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^"^" |
07-16-2015, 10:01 PM | #9 |
Wizard
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? |
07-16-2015, 10:18 PM | #10 |
creator of calibre
Posts: 44,317
Karma: 23661992
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
|
07-16-2015, 10:22 PM | #11 |
Wizard
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. |
07-16-2015, 10:38 PM | #12 |
creator of calibre
Posts: 44,317
Karma: 23661992
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"' |
07-17-2015, 10:22 PM | #13 |
Wizard
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 |
07-17-2015, 11:34 PM | #14 |
creator of calibre
Posts: 44,317
Karma: 23661992
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` |
07-18-2015, 06:42 AM | #15 | |
Grand Sorcerer
Posts: 11,931
Karma: 7208979
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Code:
for /f "usebackq" %a in (`calibredb search "tags:science fiction"`) do calibredb export %a --to-dir=bar |
|
Thread Tools | Search this Thread |
|
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 |