added "logging"
This commit is contained in:
@@ -8,6 +8,17 @@ import json
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
class Tee:
|
||||
def __init__(self, *files):
|
||||
self.files = files
|
||||
def write(self, obj):
|
||||
for f in self.files:
|
||||
f.write(obj)
|
||||
f.flush()
|
||||
def flush(self):
|
||||
for f in self.files:
|
||||
f.flush()
|
||||
|
||||
REQUIRED_TOOLS_MAP = {
|
||||
"ffmpeg": "extra/ffmpeg",
|
||||
"ffprobe": "extra/ffmpeg", # Part of ffmpeg package
|
||||
@@ -20,6 +31,7 @@ REQUIRED_TOOLS_MAP = {
|
||||
}
|
||||
DIR_COMPLETED = Path("completed")
|
||||
DIR_ORIGINAL = Path("original")
|
||||
DIR_LOGS = Path("conv_logs")
|
||||
|
||||
REMUX_CODECS = {"aac", "opus"} # Using a set for efficient lookups
|
||||
# Removed CONVERT_CODECS, now all non-remux codecs will be converted
|
||||
@@ -151,6 +163,7 @@ def main(no_downmix=False):
|
||||
check_tools()
|
||||
DIR_COMPLETED.mkdir(exist_ok=True, parents=True)
|
||||
DIR_ORIGINAL.mkdir(exist_ok=True, parents=True)
|
||||
DIR_LOGS.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
current_dir = Path(".")
|
||||
|
||||
@@ -165,6 +178,16 @@ def main(no_downmix=False):
|
||||
break
|
||||
|
||||
file_path = files_to_process[0]
|
||||
|
||||
# Setup logging
|
||||
log_file_path = DIR_LOGS / f"{file_path.name}.log"
|
||||
log_file = open(log_file_path, 'w', encoding='utf-8')
|
||||
original_stdout = sys.stdout
|
||||
original_stderr = sys.stderr
|
||||
sys.stdout = Tee(original_stdout, log_file)
|
||||
sys.stderr = Tee(original_stderr, log_file)
|
||||
|
||||
try:
|
||||
print("-" * shutil.get_terminal_size(fallback=(80, 24)).columns)
|
||||
print(f"Starting full processing for: {file_path.name}")
|
||||
date = datetime.now()
|
||||
@@ -309,6 +332,11 @@ def main(no_downmix=False):
|
||||
runtime = datetime.now() - date
|
||||
runtime_str = str(runtime).split('.')[0] # Format to remove milliseconds
|
||||
print(f"Total runtime for {file_path.name}: {runtime_str}")
|
||||
finally:
|
||||
# Restore stdout/stderr and close log file
|
||||
sys.stdout = original_stdout
|
||||
sys.stderr = original_stderr
|
||||
log_file.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
import argparse
|
||||
|
||||
Reference in New Issue
Block a user