Created
July 14, 2019 08:54
-
-
Save vaind/14061727a20400dea625cecf5ddc3132 to your computer and use it in GitHub Desktop.
Convert e-books from epub to mobi - recursive & parallelized python script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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