![]() |
#16 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)
|
Kovid changed --for-machine to use JSON output. Since then, I have taken a look at this, and came up with the following.
Requirements -- the command-line tool "jshon" for parsing json. (We could probably work something out with awk/sed, but let's use an actual json tool, why don't we. Much easier.) So let's go ahead and Code:
sudo apt-get install jshon Code:
#!/bin/bash # Save path for JSON list librarylog=/tmp/library-list.json # Generate JSON of library formats calibredb list -s "not formats:\"=EPUB\"" --for-machine -f formats > $librarylog echo "finished saving list of books" # How many books do we have number_of_books=$(jshon -l < $librarylog) ## Let's do the conversion # Loop through all indices of the booklist for ((i=0;i<=number_of_books-1;i++)); do # Where is the book.FMT bookpath=$(jshon -e $i -e "formats" -e 0 -u < $librarylog) # Convert to EPUB and leave in current dir ebook-convert "$bookpath" ".epub" done cd /path/to/savedir to the code. We can give the code acrobatics, and save the format to calibre using the following for loop instead: Code:
# What is the book's id # book_id=$(jshon -e $i -e "id" -u < $librarylog) # Where is the book.FMT bookpath=$(jshon -e $i -e "formats" -e 0 -u < $librarylog) # convert to EPUB and save to temp ebook-convert "$bookpath" "/tmp/${book_id}.epub" # Add new format to calibre book record calibredb add_format "$book_id" "/tmp/${book_id}.epub" Last edited by eschwartz; 08-12-2014 at 09:20 AM. Reason: fixed a typo in the code |
![]() |
![]() |
![]() |
#17 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)
|
Since jshon actually parses the elements of the json, this means handily enough, that it is automatically safe for multi-format books. (We couldn't return anything without making sure it is only one element in the array.) So that gets rid of Kovid's concern in post #12, yay!
However, I have no idea what you will end up using as the base input. I just defaulted to using whatever's first in the list. I have no idea how calibre lists them -- hopefully by your configured preferred input order? Last edited by eschwartz; 08-12-2014 at 02:17 AM. |
![]() |
![]() |
Advert | |
|
![]() |
#18 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,299
Karma: 27111240
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
They are not listed by any specific order.
|
![]() |
![]() |
![]() |
#19 |
Ex-Helpdesk Junkie
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 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)
|
|
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
ebook-meta command doesn't add cover to ePub and mobi | EbokJunkie | Conversion | 8 | 04-28-2014 03:13 AM |
Version 8.41 doesn't add book | killa | Calibre | 0 | 02-28-2012 11:53 AM |
ebook-convert vs windows version | zhoujianfu | Calibre | 12 | 05-21-2010 01:08 PM |
Calibredb add after ebook-convert fails | spullar | Calibre | 5 | 03-04-2010 01:14 PM |
Why doesn't eBook library 3.0 work? | mgmueller | Sony Reader | 30 | 09-20-2009 12:38 PM |