Generate encoder arguments in separate method

This commit is contained in:
George Lacey 2025-01-18 18:13:18 +00:00
parent eca3ba4a64
commit 860417488f

View File

@ -27,29 +27,37 @@ class Worker:
shutil.copy(file.path, output_path)
log.info("ART", f"Successfully copied {output_path}")
except FileExistsError:
pass
log.warning("ART", f"File exists: {output_path}")
except Exception:
log.error("ART", f"{file.path} failed to copy")
def transcode_audio(self, track, encoder, log):
enc_filename = encoder.parts[-1]
track_output = track.output_file(self.output_root, self.extension)
if track_output.exists():
log.info("AUD", f"Skipped {track_output}")
return
self.create_directories(track)
if enc_filename == "opusenc.exe":
additional_args = ('--bitrate', '128', '--music')
subprocess_args = (str(encoder),) + additional_args + (str(track.path), str(track_output))
elif enc_filename == "qaac64.exe":
additional_args = (str(track), '-o', str(track_output), '--threading')
subprocess_args = (str(encoder),) + additional_args
encoder_args = self.encoder_args(encoder, track, log)
try:
subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
subprocess.run(encoder_args, capture_output=True, text=True, check=True)
log.info("AUD", f"Transcoded '{track}' successfully.")
except Exception:
log.error("AUD", f"ERROR: Transcoding of '{track}' failed.")
def encoder_args(self, encoder, track, log):
track_output = track.output_file(self.output_root, self.extension)
enc_filename = encoder.parts[-1]
encoder_args = ""
if enc_filename == "opusenc.exe":
additional_args = ('--bitrate', '128', '--music')
encoder_args = (str(encoder),) + additional_args + (str(track.path), str(track_output))
elif enc_filename == "qaac64.exe":
additional_args = (str(track), '-o', str(track_output), '--threading')
encoder_args = (str(encoder),) + additional_args
else:
log.error("AUD", f"Encoder {encoder} not recognised.")
return encoder_args
def create_directories(self, track: File):
if not track.artist_out(self.output_root).exists():
try: