Add support for qaac encoder
This commit is contained in:
parent
6eefe16c4b
commit
f6ab663343
20
src/main.py
20
src/main.py
|
@ -31,7 +31,7 @@ def skip_album(path: Path):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def transcode(transcode_list: list, encoder: Path, workers=8):
|
def transcode(transcode_list: list, encoder: Path, workers=16):
|
||||||
worker_args = [(row[0], row[1], encoder) for row in transcode_list]
|
worker_args = [(row[0], row[1], encoder) for row in transcode_list]
|
||||||
with Pool(workers) as p:
|
with Pool(workers) as p:
|
||||||
results = p.starmap_async(transcode_worker, worker_args)
|
results = p.starmap_async(transcode_worker, worker_args)
|
||||||
|
@ -42,22 +42,30 @@ def transcode(transcode_list: list, encoder: Path, workers=8):
|
||||||
|
|
||||||
|
|
||||||
def transcode_worker(in_track, out_track, encoder):
|
def transcode_worker(in_track, out_track, encoder):
|
||||||
|
enc_filename = encoder.parts[-1]
|
||||||
|
if enc_filename == "opusenc.exe":
|
||||||
additional_args = ('--bitrate', '128', '--music')
|
additional_args = ('--bitrate', '128', '--music')
|
||||||
subprocess_args = (str(encoder),) + additional_args + (in_track, out_track)
|
subprocess_args = (str(encoder),) + additional_args + (in_track, out_track)
|
||||||
|
elif enc_filename == "qaac64.exe":
|
||||||
|
additional_args = (in_track, '-o', out_track, '--threading')
|
||||||
|
subprocess_args = (str(encoder),) + additional_args
|
||||||
try:
|
try:
|
||||||
subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
|
subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
|
||||||
return f"Transcoded '{in_track}' successfully."
|
return f"Transcoded '{in_track}' successfully."
|
||||||
except CalledProcessError:
|
except Exception:
|
||||||
return f"ERROR: Transcoding of '{in_track}' failed."
|
return f"ERROR: Transcoding of '{in_track}' failed."
|
||||||
|
|
||||||
|
|
||||||
def main(input_dir: Path, output_dir: Path, encoder: Path):
|
def main(input_dir: Path, output_dir: Path, encoder: Path, out_extension: str = 'opus'):
|
||||||
|
enc_filename = encoder.parts[-1]
|
||||||
|
if enc_filename == "qaac64.exe":
|
||||||
|
out_extension = "m4a"
|
||||||
transcode_list = []
|
transcode_list = []
|
||||||
file_whitelist = ['.jpg', '.jpeg', '.png']
|
file_whitelist = ['.jpg', '.jpeg', '.png']
|
||||||
for artist in input_dir.iterdir():
|
for artist in input_dir.iterdir():
|
||||||
if artist.is_dir():
|
if artist.is_dir():
|
||||||
artist_out = Path(output_dir) / artist.name
|
artist_out = Path(output_dir) / artist.name
|
||||||
if skip_all_albums(artist):
|
if False: #skip_all_albums(artist):
|
||||||
print(f"Skipping '{artist.parts[-1]}'")
|
print(f"Skipping '{artist.parts[-1]}'")
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
|
@ -65,7 +73,7 @@ def main(input_dir: Path, output_dir: Path, encoder: Path):
|
||||||
for album in artist.iterdir():
|
for album in artist.iterdir():
|
||||||
if album.is_dir():
|
if album.is_dir():
|
||||||
album_out = artist_out / album.parts[-1]
|
album_out = artist_out / album.parts[-1]
|
||||||
if skip_album(album):
|
if album_out.exists():
|
||||||
print(f"Skipping '{artist.parts[-1]} / {album.parts[-1]}'")
|
print(f"Skipping '{artist.parts[-1]} / {album.parts[-1]}'")
|
||||||
else:
|
else:
|
||||||
album_out.mkdir()
|
album_out.mkdir()
|
||||||
|
@ -73,7 +81,7 @@ def main(input_dir: Path, output_dir: Path, encoder: Path):
|
||||||
open(done_file, 'a').close()
|
open(done_file, 'a').close()
|
||||||
for file in album.iterdir():
|
for file in album.iterdir():
|
||||||
if file.is_file() and file.suffix.lower() == '.flac':
|
if file.is_file() and file.suffix.lower() == '.flac':
|
||||||
transcode_list.append((str(file), str(album_out / f"{file.stem}.opus")))
|
transcode_list.append((str(file), str(album_out / f"{file.stem}.{out_extension}")))
|
||||||
elif file.is_file() and file.suffix.lower() in file_whitelist:
|
elif file.is_file() and file.suffix.lower() in file_whitelist:
|
||||||
shutil.copy(file, album_out / file.name)
|
shutil.copy(file, album_out / file.name)
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user