From c60eee65882df5ab40bb7437a986061fd59af5af Mon Sep 17 00:00:00 2001 From: McCloudS <64094529+McCloudS@users.noreply.github.com> Date: Tue, 5 Mar 2024 07:14:28 -0700 Subject: [PATCH] Added timestamps --- subgen/subgen.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/subgen/subgen.py b/subgen/subgen.py index ac371b6..a3d121b 100644 --- a/subgen/subgen.py +++ b/subgen/subgen.py @@ -58,6 +58,7 @@ hf_batch_size = int(os.getenv('HF_BATCH_SIZE', 24)) clear_vram_on_complete = convert_to_bool(os.getenv('CLEAR_VRAM_ON_COMPLETE', True)) compute_type = os.getenv('COMPUTE_TYPE', 'auto') append = convert_to_bool(os.getenv('APPEND', False)) +timestamps = convert_to_bool(os.getenv('TIMESTAMPS', True)) if transcribe_device == "gpu": transcribe_device = "cuda" @@ -68,6 +69,20 @@ files_to_transcribe = [] subextension = f".subgen.{whisper_model.split('.')[0]}.{namesublang}.srt" subextensionSDH = f".subgen.{whisper_model.split('.')[0]}.{namesublang}.sdh.srt" +if timestamps: + # Define a custom class that modifies sys.stdout + class TimestampedStdout: + def __init__(self, stdout): + self.stdout = stdout + def write(self, x): + # Append the timestamp to every printed line + self.stdout.write(x.replace("\n", "\n[%s] " % str(datetime.now()))) + def flush(self): + # Flush the output + self.stdout.flush() + # Replace sys.stdout with the custom class + sys.stdout = TimestampedStdout(sys.stdout) + if debug: logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) else: @@ -76,6 +91,7 @@ else: logging.getLogger("multipart").setLevel(logging.WARNING) logging.getLogger("urllib3").setLevel(logging.WARNING) logging.getLogger("asyncio").setLevel(logging.WARNING) +logging.getLogger("watchfiles").setLevel(logging.WARNING) TIME_OFFSET = 5