rfog icon

Calibre batch convert ePub->Mobi command line in parallel

rfog | PRO | 06/21/19 07:57:00 PM UTC | 0 ⭐ | 586 👁️ | Never ⏰ | []
Python |

530 B

|

None

|

0 👍

/

0 👎

#!/usr/bin/python
#change number 6 to desired number of parallel processes
#original credit: Kovid Goyal, Calibre author.
 
import os, time, glob, subprocess
 
files = glob.glob('*.epub')
 
workers = []
while files or workers:
    while len(workers) < 6 and files:
        f = files[0]
        files = files[1:]
        w = subprocess.Popen(['/Applications/calibre.app/Contents/MacOS/ebook-convert', f, os.path.splitext(f)[0]+'.mobi'])
        workers.append(w)
    for w in list(workers):
        if w.poll() is not None:
            workers.remove(w)
    time.sleep(0.1)

Comments