Register Guidelines E-Books Search Today's Posts Mark Forums Read

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

Notices

Reply
 
Thread Tools Search this Thread
Old 07-08-2011, 11:00 AM   #1
jmeb
Junior Member
jmeb began at the beginning.
 
Posts: 2
Karma: 10
Join Date: May 2011
Device: Kindle DX
Batch Converting Ebooks with Calibre and Python

Mornin' all

As part of my venturing into Python I've created a python script that runs on my server to batch convert between different ebook formats using calibre's ebook-convert.

The script looks up all files matching one extension (e.g. .epub) and checks for the same filename with another extension (e.g. .mobi). It there isn't a matching file, it will run ebook-convert to create it.

Some things it includes:
* Handles filenames with spaces
* Takes a couple of different command line arguments
- "--have {epub, mobi, lit, html}": tells it what ebook format you have to convert from
- "--want {epub, mobi, lit, html}": tells it what ebook format you want to convert to
- "-s {/PATH/TO/DIR}": source directory for the ebooks you have
-" -d {/PATH/TO/DIR}": destination directory to check for existing ebooks, and drop conversions into.
* If no commands are supplied it will try to convert epub to mobi in the current directory.

For example:
* "python mbmk.py" : will create an .mobi for every .epub without a .mobi counterpart
* "python mbmk.py --have epub --want html -s ../epubs -d ../htmls" will grab a list of epubs from the ../epub directory, and create an html version in the ../htmls directory if needed.
* "python mbmk.py --have mobi --want lit -s ../mobis" creates .lit versions of mobi files in the ../mobi directory
Its written for a linux box, but should work fine on Mac OSX. Windows I doubt....

Thanks for all the work on Calibre. If anyone has suggestions on improving the script I'd be happy to have them.

The script can be found here: http://pastebin.com/XdPZUdpg
jmeb is offline   Reply With Quote
Old 07-08-2011, 11:59 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: 25,983
Karma: 5036765
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Just to note: You can run your script without the need for a separate python, by just doing:

calibre-debug -e filename.py
kovidgoyal is online now   Reply With Quote
 
Enthusiast
Old 08-07-2012, 10:27 PM   #3
chadberg
Junior Member
chadberg began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Aug 2011
Device: iPad
Great! Now to modify it to automatically read in any supported format, and output my two preferred options....

Thank you!
chadberg is offline   Reply With Quote
Old 11-18-2013, 09:44 AM   #4
naxman
Junior Member
naxman began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Nov 2013
Device: ipad
I an using Windows Vista - I love Calibre, I a still looking for a way to convert my many mobi files to epub as I have moved from a Kindle to an iPad. I want to do this within folders without having to add them all to my Calibre library as the library becomes too large to easily deal with and I won't need some of the documents for some time/ I would like to convert them in the background if possible. Is there a way to do this?
naxman is offline   Reply With Quote
Old 11-18-2013, 09:49 AM   #5
theducks
Grand Sorcerer
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 14,695
Karma: 5643643
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: Galaxy Tab 2, Astak Pocket Pro, K4NT
Quote:
Originally Posted by naxman View Post
I an using Windows Vista - I love Calibre, I a still looking for a way to convert my many mobi files to epub as I have moved from a Kindle to an iPad. I want to do this within folders without having to add them all to my Calibre library as the library becomes too large to easily deal with and I won't need some of the documents for some time/ I would like to convert them in the background if possible. Is there a way to do this?
Too large to deal with?
Tags and Virtual Libraries are the basic tools of Calibre that should male ANY size Library manageable . At least you don't need to write un-flawed python code to do the job
\
theducks is offline   Reply With Quote
Old 11-18-2013, 10:22 AM   #6
naxman
Junior Member
naxman began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Nov 2013
Device: ipad
I see I can do it I suppose but I would lose my file structure as everything is imported into the Calibre library, which was really what I was trying to avoid.
naxman is offline   Reply With Quote
Old 11-18-2013, 11:25 AM   #7
theducks
Grand Sorcerer
theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.theducks ought to be getting tired of karma fortunes by now.
 
theducks's Avatar
 
Posts: 14,695
Karma: 5643643
Join Date: Aug 2009
Location: (The original) Silicon Valley, USA
Device: Galaxy Tab 2, Astak Pocket Pro, K4NT
Quote:
Originally Posted by naxman View Post
I see I can do it I suppose but I would lose my file structure as everything is imported into the Calibre library, which was really what I was trying to avoid.
There is no reason to keep needing YOUR file structure.
Calibre can search/select and DELIVER by far more refined criteria than any STRUCTURE based method can supply

Tags, Author, Publisher,Title(words),Series (sometimes GIGO),Published Date and any other field you might conceive (and populate)
Calibre is a Database. You get to databasey type things that can not be done with a file system only search.
theducks is offline   Reply With Quote
Old 11-18-2013, 12:12 PM   #8
fidvo
Zealot
fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.fidvo ought to be getting tired of karma fortunes by now.
 
Posts: 121
Karma: 775442
Join Date: Jun 2012
Device: none
Quote:
Originally Posted by theducks View Post
There is no reason to keep needing YOUR file structure.
Calibre can search/select and DELIVER by far more refined criteria than any STRUCTURE based method can supply

Tags, Author, Publisher,Title(words),Series (sometimes GIGO),Published Date and any other field you might conceive (and populate)
Calibre is a Database. You get to databasey type things that can not be done with a file system only search.
Although I agree with you, there are a lot of people who are too stubborn to give up their hierarchical file system for a database-driven system. I know, because I was that way myself for the longest time, so I can certainly understand where naxman is coming from.

However, there is a way to compromise. You can use Calibre to convert and still keep your hierarchical file system. It takes some work up front, but you only have to do this once.

The key is to set up a save-to-disk template to re-create your file structure. This may involve setting up custom columns to store the information needed about the folder names, etc.

Once you have everything set up correctly, then to convert a book you would import it into Calibre, populate the columns, convert, and save to disk. If you don't want to maintain a library, delete the book from Calibre afterward.

I ran Calibre like this for a year before I decided to experiment with its library management features, and instantly got hooked.
fidvo is offline   Reply With Quote
Reply

Tags
batch, convert, python

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Python script: batch create mobi's from epubs (if they don't exist) jmeb Conversion 0 05-20-2011 01:14 PM
Classic Batch download of B&N eBooks? mgmueller Barnes & Noble NOOK 5 02-08-2010 12:01 PM
Batch Convert Ebooks? April Workshop 7 12-09-2009 03:07 AM
Mobigen Mass Batch conversion of HTML-Single-File ebooks to .mobi ebooks cklammer Kindle Formats 9 11-20-2009 03:00 AM
Crash while batch converting epubs under windows AprilHare Calibre 3 04-26-2009 03:46 AM


All times are GMT -4. The time now is 05:53 AM.


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