add parallization to metadata_audiobooks_library.py
This commit is contained in:
1 parent
1dd80d9a45
commit
95c2f90031
1 file changed
+28
-7
@@ -9,6 +9,7 @@ import json
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||||
|
|
||||||
RED = "\033[91m"
|
RED = "\033[91m"
|
||||||
GREEN = "\033[92m"
|
GREEN = "\033[92m"
|
||||||
@@ -542,13 +543,33 @@ class AudiobookLibrary:
|
|||||||
audiobooks.extend(self.find_name_contains(name))
|
audiobooks.extend(self.find_name_contains(name))
|
||||||
if not name and not path:
|
if not name and not path:
|
||||||
audiobooks = self.audiobooks
|
audiobooks = self.audiobooks
|
||||||
for audiobook in audiobooks:
|
|
||||||
if audiobook.singleFile:
|
jobs = [
|
||||||
continue
|
audiobook
|
||||||
logger.debug(f"Crate m4b file for {audiobook.name}")
|
for audiobook in audiobooks
|
||||||
if self.dry_run:
|
if not audiobook.singleFile
|
||||||
continue
|
]
|
||||||
audiobook.create_m4b_from_book( self.libraryPath,create_m4b_no_delete)
|
|
||||||
|
for audiobook in jobs:
|
||||||
|
logger.debug(f"Create m4b file for {audiobook.name}")
|
||||||
|
|
||||||
|
if not self.dry_run:
|
||||||
|
with ThreadPoolExecutor(max_workers=8) as executor:
|
||||||
|
futures = {
|
||||||
|
executor.submit(
|
||||||
|
audiobook.create_m4b_from_book,
|
||||||
|
self.libraryPath,
|
||||||
|
create_m4b_no_delete,
|
||||||
|
): audiobook
|
||||||
|
for audiobook in jobs
|
||||||
|
}
|
||||||
|
|
||||||
|
for future in as_completed(futures):
|
||||||
|
audiobook = futures[future]
|
||||||
|
try:
|
||||||
|
future.result()
|
||||||
|
except Exception:
|
||||||
|
logger.exception(f"Failed to create m4b for {audiobook.name}")
|
||||||
|
|
||||||
def ffmpeg_escape(path: Path) -> str:
|
def ffmpeg_escape(path: Path) -> str:
|
||||||
return str(path.resolve()).replace("'", r"'\''")
|
return str(path.resolve()).replace("'", r"'\''")
|
||||||
|
|||||||
Reference in new issue
Block a user