Encode multiple tracks concurrently
This commit is contained in:
parent
4633505b98
commit
a65b6dd6e3
16
src/main.py
16
src/main.py
|
@ -3,6 +3,7 @@ import subprocess
|
||||||
import shutil
|
import shutil
|
||||||
from subprocess import CalledProcessError
|
from subprocess import CalledProcessError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from multiprocessing import Pool
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
|
@ -30,15 +31,22 @@ def skip_album(path: Path):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def transcode(transcode_list: list, encoder: Path):
|
def transcode(transcode_list: list, encoder: Path, workers=8):
|
||||||
|
worker_args = [(row[0], row[1], encoder) for row in transcode_list]
|
||||||
|
with Pool(workers) as p:
|
||||||
|
print(p.starmap_async(transcode_worker, worker_args))
|
||||||
|
p.close()
|
||||||
|
p.join()
|
||||||
|
|
||||||
|
|
||||||
|
def transcode_worker(in_track, out_track, encoder):
|
||||||
additional_args = ('--bitrate', '128', '--music')
|
additional_args = ('--bitrate', '128', '--music')
|
||||||
for in_track, out_track in transcode_list:
|
|
||||||
subprocess_args = (str(encoder),) + additional_args + (in_track, out_track)
|
subprocess_args = (str(encoder),) + additional_args + (in_track, out_track)
|
||||||
try:
|
try:
|
||||||
result = subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
|
result = subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
|
||||||
|
return f"Transcoded '{in_track}' successfully"
|
||||||
except CalledProcessError:
|
except CalledProcessError:
|
||||||
print(f"ERROR: Transcoding of '{in_track}' failed with errors:")
|
return f"ERROR: Transcoding of '{in_track}' failed with errors:\n{result.stderr}"
|
||||||
print(result.stderr)
|
|
||||||
|
|
||||||
|
|
||||||
def main(input_dir: Path, output_dir: Path, encoder: Path):
|
def main(input_dir: Path, output_dir: Path, encoder: Path):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user