Compare commits
No commits in common. "965197cd6a7186b558b677d3f298f1ceb3d21263" and "eca3ba4a64f46101fd6fab6e396fd267224463c6" have entirely different histories.
965197cd6a
...
eca3ba4a64
|
@ -1,7 +1,6 @@
|
||||||
DEBUG=0
|
INFO=0
|
||||||
INFO=5
|
WARNING=5
|
||||||
WARNING=10
|
ERROR=10
|
||||||
ERROR=20
|
|
||||||
|
|
||||||
from .log import Log
|
from .log import Log
|
||||||
from .logcat import LogCat
|
from .logcat import LogCat
|
||||||
|
|
|
@ -2,11 +2,11 @@ from datetime import datetime
|
||||||
from multiprocessing import Lock
|
from multiprocessing import Lock
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from queue import Queue, Empty
|
from queue import Queue, Empty
|
||||||
from . import DEBUG, INFO, WARNING, ERROR
|
from . import INFO, WARNING, ERROR
|
||||||
|
|
||||||
|
|
||||||
class Log(object):
|
class Log(object):
|
||||||
def __init__(self, path, queue=None, print_output=True, timeout=1, level=DEBUG):
|
def __init__(self, path, queue=None, print_output=True, timeout=1, level=WARNING):
|
||||||
self.__terminated = False
|
self.__terminated = False
|
||||||
self.level = level
|
self.level = level
|
||||||
self.file_lock = Lock()
|
self.file_lock = Lock()
|
||||||
|
@ -78,9 +78,4 @@ class Log(object):
|
||||||
self.set_log_file()
|
self.set_log_file()
|
||||||
with self.file_lock:
|
with self.file_lock:
|
||||||
with open(self.log_file, mode='a') as log_file:
|
with open(self.log_file, mode='a') as log_file:
|
||||||
for line in log_msg_list:
|
log_file.writelines(log_msg_list)
|
||||||
try:
|
|
||||||
log_file.write(line)
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error writing line{line}")
|
|
||||||
print(e)
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from multiprocessing import Queue
|
from multiprocessing import Queue
|
||||||
from . import DEBUG, INFO, WARNING, ERROR
|
from . import INFO, WARNING, ERROR
|
||||||
|
|
||||||
|
|
||||||
class LogCat(object):
|
class LogCat(object):
|
||||||
|
@ -13,9 +13,6 @@ class LogCat(object):
|
||||||
time = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
|
time = datetime.now().strftime("%Y-%m-%dT%H:%M:%S")
|
||||||
self.queue.put((level, f"{self.level_string(level)} | {time} - {self.category.upper()}.{function.upper()}: {message}"))
|
self.queue.put((level, f"{self.level_string(level)} | {time} - {self.category.upper()}.{function.upper()}: {message}"))
|
||||||
|
|
||||||
def debug(self, function: str, message: str) -> None:
|
|
||||||
self._write(DEBUG, function, message)
|
|
||||||
|
|
||||||
def info(self, function: str, message: str) -> None:
|
def info(self, function: str, message: str) -> None:
|
||||||
self._write(INFO, function, message)
|
self._write(INFO, function, message)
|
||||||
|
|
||||||
|
@ -27,9 +24,7 @@ class LogCat(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def level_string(level: int) -> str:
|
def level_string(level: int) -> str:
|
||||||
if level == DEBUG:
|
if level == INFO:
|
||||||
return "DEBG"
|
|
||||||
elif level == INFO:
|
|
||||||
return "INFO"
|
return "INFO"
|
||||||
elif level == WARNING:
|
elif level == WARNING:
|
||||||
return "WARN"
|
return "WARN"
|
||||||
|
|
|
@ -27,37 +27,29 @@ class Worker:
|
||||||
shutil.copy(file.path, output_path)
|
shutil.copy(file.path, output_path)
|
||||||
log.info("ART", f"Successfully copied {output_path}")
|
log.info("ART", f"Successfully copied {output_path}")
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
log.warning("ART", f"File exists: {output_path}")
|
pass
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("ART", f"{file.path} failed to copy")
|
log.error("ART", f"{file.path} failed to copy")
|
||||||
|
|
||||||
def transcode_audio(self, track, encoder, log):
|
def transcode_audio(self, track, encoder, log):
|
||||||
|
enc_filename = encoder.parts[-1]
|
||||||
track_output = track.output_file(self.output_root, self.extension)
|
track_output = track.output_file(self.output_root, self.extension)
|
||||||
if track_output.exists():
|
if track_output.exists():
|
||||||
log.info("AUD", f"Skipped {track_output}")
|
log.info("AUD", f"Skipped {track_output}")
|
||||||
return
|
return
|
||||||
self.create_directories(track)
|
self.create_directories(track)
|
||||||
encoder_args = self.encoder_args(encoder, track, log)
|
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
|
||||||
try:
|
try:
|
||||||
subprocess.run(encoder_args, capture_output=True, text=True, check=True)
|
subprocess.run(subprocess_args, capture_output=True, text=True, check=True)
|
||||||
log.info("AUD", f"Transcoded '{track}' successfully.")
|
log.info("AUD", f"Transcoded '{track}' successfully.")
|
||||||
except Exception:
|
except Exception:
|
||||||
log.error("AUD", f"ERROR: Transcoding of '{track}' failed.")
|
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):
|
def create_directories(self, track: File):
|
||||||
if not track.artist_out(self.output_root).exists():
|
if not track.artist_out(self.output_root).exists():
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user