Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Conversion

Notices

Reply
 
Thread Tools Search this Thread
Old 08-12-2014, 02:00 AM   #16
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)
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
Either run this from the directory all the books should go in, or add
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
eschwartz is offline   Reply With Quote
Old 08-12-2014, 02:15 AM   #17
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)
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.
eschwartz is offline   Reply With Quote
Advert
Old 08-12-2014, 02:21 AM   #18
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: 45,299
Karma: 27111240
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
They are not listed by any specific order.
kovidgoyal is offline   Reply With Quote
Old 08-12-2014, 02:24 AM   #19
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
They are not listed by any specific order.
OK.

Perhaps tomorrow I will devote some thought as to how we might return specific formats.

Failing that at least we got something reliably something.
eschwartz is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 02:40 PM.


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