Add recursive file search to convert command

Signed-off-by: nathom <nathanthomas707@gmail.com>
This commit is contained in:
nathom 2021-07-14 23:25:45 -07:00
parent f7e633812a
commit 10e129e1a0

View file

@ -413,15 +413,21 @@ def convert(ctx, **kwargs):
"remove_source": not kwargs.get("keep_source", False), "remove_source": not kwargs.get("keep_source", False),
} }
if os.path.isdir(kwargs["path"]): if os.path.isdir(kwargs["path"]):
import itertools
from pathlib import Path
dirname = kwargs["path"] dirname = kwargs["path"]
audio_extensions = ("flac", "m4a", "aac", "opus", "mp3", "ogg")
path_obj = Path(dirname)
audio_files = (
path.as_posix()
for path in itertools.chain.from_iterable(
(path_obj.rglob(f"*.{ext}") for ext in audio_extensions)
)
)
with concurrent.futures.ThreadPoolExecutor() as executor: with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [] futures = []
audio_extensions = ("flac", "m4a", "aac", "opus", "mp3", "ogg")
audio_files = (
f
for f in os.listdir(kwargs["path"])
if any(f.endswith(ext) for ext in audio_extensions)
)
for file in audio_files: for file in audio_files:
futures.append( futures.append(
executor.submit( executor.submit(
@ -436,7 +442,7 @@ def convert(ctx, **kwargs):
desc="Converting", desc="Converting",
): ):
# Only show loading bar # Only show loading bar
pass future.result()
elif os.path.isfile(kwargs["path"]): elif os.path.isfile(kwargs["path"]):
codec_map[codec](filename=kwargs["path"], **converter_args).convert() codec_map[codec](filename=kwargs["path"], **converter_args).convert()