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>
pull/2482/head
copilot-swe-agent[bot] 6 months ago committed by GitHub
parent 00a37231b8
commit 2c6fa251e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -3,6 +3,7 @@ Base Uploader - Lớp cơ sở cho tất cả uploaders.
""" """
import os import os
import time
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Optional, List from typing import Optional, List
@ -112,6 +113,10 @@ class BaseUploader(ABC):
f"[{self.platform_name}] Lỗi upload (lần {attempt}): {e}", f"[{self.platform_name}] Lỗi upload (lần {attempt}): {e}",
style="bold red", 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") print_substep(f"Upload {self.platform_name} thất bại sau {max_retries} lần thử!", style="bold red")
return None return None

@ -150,6 +150,8 @@ class YouTubeUploader(BaseUploader):
# Step 2: Upload video file # Step 2: Upload video file
file_size = os.path.getsize(metadata.file_path) 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: with open(metadata.file_path, "rb") as video_file:
upload_response = requests.put( upload_response = requests.put(
upload_url, upload_url,
@ -158,7 +160,7 @@ class YouTubeUploader(BaseUploader):
"Content-Length": str(file_size), "Content-Length": str(file_size),
}, },
data=video_file, data=video_file,
timeout=600, # 10 minutes timeout for large files timeout=upload_timeout,
) )
upload_response.raise_for_status() upload_response.raise_for_status()

@ -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: def _get_font(size: int, bold: bool = False) -> ImageFont.FreeTypeFont:
"""Load font hỗ trợ tiếng Việt.""" """Load font hỗ trợ tiếng Việt."""
@ -236,14 +245,7 @@ def create_comment_image(
) )
# Avatar (smaller for comments) # Avatar (smaller for comments)
colors = [ avatar_color = AVATAR_COLORS[index % len(AVATAR_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)]
_draw_avatar(draw, padding, y_cursor, avatar_size, avatar_color) _draw_avatar(draw, padding, y_cursor, avatar_size, avatar_color)
# Username # Username

Loading…
Cancel
Save