Transcode files using specified encoder
This commit is contained in:
parent
19a70dd2e7
commit
a6cdc8d31e
15
src/main.py
15
src/main.py
|
@ -1,4 +1,6 @@
|
||||||
import argparse
|
import argparse
|
||||||
|
import subprocess
|
||||||
|
from subprocess import CalledProcessError
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
|
||||||
|
@ -28,9 +30,14 @@ def skip_album(path: Path):
|
||||||
|
|
||||||
|
|
||||||
def transcode(transcode_list: list, encoder: Path):
|
def transcode(transcode_list: list, encoder: Path):
|
||||||
additional_args = ('--bitrate 128', '--music')
|
additional_args = ('--bitrate', '128', '--music')
|
||||||
for in_track, out_track in transcode_list:
|
for in_track, out_track in transcode_list:
|
||||||
print((in_track, out_track) + additional_args)
|
subprocess_args = (str(encoder),) + additional_args + (in_track, out_track)
|
||||||
|
try:
|
||||||
|
result = subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
|
||||||
|
except CalledProcessError:
|
||||||
|
print(f"ERROR: Transcoding of '{in_track}' failed with errors:")
|
||||||
|
print(result.stderr)
|
||||||
|
|
||||||
|
|
||||||
def main(input_dir: Path, output_dir: Path, encoder: Path):
|
def main(input_dir: Path, output_dir: Path, encoder: Path):
|
||||||
|
@ -50,9 +57,11 @@ def main(input_dir: Path, output_dir: Path, encoder: Path):
|
||||||
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()
|
||||||
|
# todo: copy files not on blacklist
|
||||||
|
# todo: create blacklist
|
||||||
for track in album.iterdir():
|
for track in album.iterdir():
|
||||||
if track.is_file() and track.suffix.lower() == '.flac':
|
if track.is_file() and track.suffix.lower() == '.flac':
|
||||||
transcode_list.append((str(track), str(album_out / f"{track.name}.opus")))
|
transcode_list.append((str(track), str(album_out / f"{track.stem}.opus")))
|
||||||
else:
|
else:
|
||||||
print(f"Warning, skipping non-dir '{album}' found in artist '{artist.parts[-1]}'")
|
print(f"Warning, skipping non-dir '{album}' found in artist '{artist.parts[-1]}'")
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in New Issue
Block a user