From 8a56450b797c0176228621b62e7e5935269d9818 Mon Sep 17 00:00:00 2001 From: Misaka_Company Date: Mon, 15 Jun 2026 14:11:33 +0800 Subject: [PATCH] Add progress display for S3 upload and transcription polling - Add real-time progress bar with percentage for S3 upload (file size/MB) - Replace repetitive polling output with single-line refreshing status - Show elapsed time and poll count during transcription polling - Add .claude/ to .gitignore Co-Authored-By: Claude --- .gitignore | 4 +++- transcribe_legacy.py | 32 +++++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 6d21059..d37ea01 100644 --- a/.gitignore +++ b/.gitignore @@ -37,4 +37,6 @@ output/ Archive/ # Tools -tools/ \ No newline at end of file +tools/ + +.claude/ \ No newline at end of file diff --git a/transcribe_legacy.py b/transcribe_legacy.py index c59e782..18e3a84 100644 --- a/transcribe_legacy.py +++ b/transcribe_legacy.py @@ -100,8 +100,23 @@ audio_ext = os.path.splitext(audio_file)[1].lstrip(".") audio_name = os.path.splitext(os.path.basename(audio_file))[0] obj_name = f"audio/{uuid.uuid4().hex[:8]}_{os.path.basename(audio_file)}" -print(f"Uploading {audio_file} ...") -s3.upload_file(audio_file, S3_BUCKET, obj_name) +file_size = os.path.getsize(audio_file) +uploaded = [0] # Use list to allow modification in callback + +def upload_callback(bytes_transferred): + uploaded[0] += bytes_transferred + percent = min(100, int(uploaded[0] * 100 / file_size)) + uploaded_mb = uploaded[0] / (1024 * 1024) + total_mb = file_size / (1024 * 1024) + bar_width = 30 + filled = int(bar_width * percent / 100) + bar = "█" * filled + "░" * (bar_width - filled) + print(f"\rUploading [{bar}] {percent}% ({uploaded_mb:.1f}MB / {total_mb:.1f}MB)", end="", flush=True) + +print(f"Uploading {audio_file} ({file_size / (1024 * 1024):.1f}MB) ...") +s3.upload_file(audio_file, S3_BUCKET, obj_name, Callback=upload_callback) +print() # New line after upload completes + url = s3.generate_presigned_url( "get_object", Params={"Bucket": S3_BUCKET, "Key": obj_name}, @@ -131,6 +146,9 @@ print(f"Submit: {status}") if status != "20000000": print(f"FAILED: {resp.headers.get('X-Api-Message', '')}") else: + start_time = time.time() + poll_count = 0 + while True: resp = session.post( QUERY_URL, @@ -156,14 +174,18 @@ else: with open(md_path, "w", encoding="utf-8") as f: f.write(build_markdown(data, audio_file)) - print(f"Done ({len(text)} chars, {len(utterances)} utterances)") + elapsed = int(time.time() - start_time) + print(f"\rDone ({len(text)} chars, {len(utterances)} utterances, elapsed {elapsed}s)") print(f"Saved: {json_path}, {md_path}") break elif code in ("20000001", "20000002"): - print(f" Processing... ({code})") + poll_count += 1 + elapsed = int(time.time() - start_time) + status_msg = "Processing" if code == "20000001" else "Queued" + print(f"\r {status_msg}... (poll {poll_count}, elapsed {elapsed}s) ", end="", flush=True) time.sleep(5) else: - print(f"FAILED: {code} {resp.headers.get('X-Api-Message', '')}") + print(f"\rFAILED: {code} {resp.headers.get('X-Api-Message', '')}") break print("\nAll done.")