View Single Post
Old 07-23-2014, 01:47 AM   #11
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: 85400180
Join Date: Nov 2012
Location: The Beaten Path, USA, Roundworld, This Side of Infinity
Device: Kindle Touch fw5.3.7 (Wifi only)
Quote:
Originally Posted by kovidgoyal View Post
You're doing it wrong

You want to start with calibredb list to get a list of all books and their ids,

calibredb list -f formats

Then iterate over the books, converting them, sending the converted output to a temp file ad add the temp file like this

calibredb add_format book_id tmpfile


...

something like this...
Code:
#!/bin/bash

# Search for which books we want. Find books that aren't in EPUB yet.
calibre-search='not formats:"=EPUB"'
regex="(\d+) \[([^\]]*)\]"
# Search calibredb, iterate over each result.
calibredb list -s "$calibre-search" -f formats | while read line; do
# Extract info from lines into bash_rematch
    [[ "$line" =~ "$regex" ]]
    ebook-convert "${BASH_REMATCH[2]}" "/tmp/converted.epub"
    calibredb add_format "${BASH_REMATCH[1]}" "/tmp/converted.epub"
done
eschwartz is offline   Reply With Quote