Skip to content

Instantly share code, notes, and snippets.

@vaind
Created July 14, 2019 08:54
Show Gist options
  • Save vaind/14061727a20400dea625cecf5ddc3132 to your computer and use it in GitHub Desktop.
Save vaind/14061727a20400dea625cecf5ddc3132 to your computer and use it in GitHub Desktop.
Convert e-books from epub to mobi - recursive & parallelized python script
#!/usr/bin/python3
import os, time, glob, subprocess
files = glob.iglob('./**/*.epub', recursive=True)
workers = []
while files or workers:
files = list(files)
while len(workers) < 4 and files:
f = files[0]
files = files[1:]
mobi = os.path.splitext(f)[0]+'.mobi'
if not os.path.isfile(mobi):
w = subprocess.Popen(['ebook-convert', f, mobi])
workers.append(w)
for w in list(workers):
if w.poll() is not None:
workers.remove(w)
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment