Advertisement
rfog

Calibre batch convert ePub->Mobi command line in parallel

Jun 21st, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. #!/usr/bin/python
  2. #change number 6 to desired number of parallel processes
  3. #original credit: Kovid Goyal, Calibre author.
  4.  
  5. import os, time, glob, subprocess
  6.  
  7. files = glob.glob('*.epub')
  8.  
  9. workers = []
  10. while files or workers:
  11.     while len(workers) < 6 and files:
  12.         f = files[0]
  13.         files = files[1:]
  14.         w = subprocess.Popen(['/Applications/calibre.app/Contents/MacOS/ebook-convert', f, os.path.splitext(f)[0]+'.mobi'])
  15.         workers.append(w)
  16.     for w in list(workers):
  17.         if w.poll() is not None:
  18.             workers.remove(w)
  19.     time.sleep(0.1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement