From 2c6fa251e67bcd249a3a9bb255285e63dfc1e594 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 6 Apr 2026 19:01:03 +0000 Subject: [PATCH] Address code review feedback: exponential backoff, avatar colors constant, dynamic upload timeout Agent-Logs-Url: https://github.com/thaitien280401-stack/RedditVideoMakerBot/sessions/b2183a86-2887-4db0-82aa-07d9da5aa1be Co-authored-by: thaitien280401-stack <271128961+thaitien280401-stack@users.noreply.github.com> --- uploaders/base_uploader.py | 5 +++++ uploaders/youtube_uploader.py | 4 +++- video_creation/threads_screenshot.py | 18 ++++++++++-------- 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/uploaders/base_uploader.py b/uploaders/base_uploader.py index 0405096..e67b0f1 100644 --- a/uploaders/base_uploader.py +++ b/uploaders/base_uploader.py @@ -3,6 +3,7 @@ Base Uploader - Lớp cơ sở cho tất cả uploaders. """ import os +import time from abc import ABC, abstractmethod from dataclasses import dataclass, field from typing import Optional, List @@ -112,6 +113,10 @@ class BaseUploader(ABC): f"[{self.platform_name}] Lỗi upload (lần {attempt}): {e}", style="bold red", ) + if attempt < max_retries: + backoff = min(2 ** attempt, 60) # Exponential backoff, max 60s + print_substep(f"Chờ {backoff}s trước khi thử lại...", style="bold yellow") + time.sleep(backoff) print_substep(f"Upload {self.platform_name} thất bại sau {max_retries} lần thử!", style="bold red") return None diff --git a/uploaders/youtube_uploader.py b/uploaders/youtube_uploader.py index 332e837..10b4a82 100644 --- a/uploaders/youtube_uploader.py +++ b/uploaders/youtube_uploader.py @@ -150,6 +150,8 @@ class YouTubeUploader(BaseUploader): # Step 2: Upload video file file_size = os.path.getsize(metadata.file_path) + # Dynamic timeout: minimum 120s, add 60s per 100MB + upload_timeout = max(120, 60 * (file_size // (100 * 1024 * 1024) + 1)) with open(metadata.file_path, "rb") as video_file: upload_response = requests.put( upload_url, @@ -158,7 +160,7 @@ class YouTubeUploader(BaseUploader): "Content-Length": str(file_size), }, data=video_file, - timeout=600, # 10 minutes timeout for large files + timeout=upload_timeout, ) upload_response.raise_for_status() diff --git a/video_creation/threads_screenshot.py b/video_creation/threads_screenshot.py index aaea398..af42728 100644 --- a/video_creation/threads_screenshot.py +++ b/video_creation/threads_screenshot.py @@ -40,6 +40,15 @@ THEMES = { }, } +# Avatar color palette for comments +AVATAR_COLORS = [ + (88, 101, 242), # Blue + (237, 66, 69), # Red + (87, 242, 135), # Green + (254, 231, 92), # Yellow + (235, 69, 158), # Pink +] + def _get_font(size: int, bold: bool = False) -> ImageFont.FreeTypeFont: """Load font hỗ trợ tiếng Việt.""" @@ -236,14 +245,7 @@ def create_comment_image( ) # Avatar (smaller for comments) - colors = [ - (88, 101, 242), # Blue - (237, 66, 69), # Red - (87, 242, 135), # Green - (254, 231, 92), # Yellow - (235, 69, 158), # Pink - ] - avatar_color = colors[index % len(colors)] + avatar_color = AVATAR_COLORS[index % len(AVATAR_COLORS)] _draw_avatar(draw, padding, y_cursor, avatar_size, avatar_color) # Username