From 22a51dc7aeb9d582bd5b5967301a4e4d06e9d6c9 Mon Sep 17 00:00:00 2001 From: Gramps Date: Fri, 25 Jul 2025 19:15:49 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20YouTube=20thumbnail=20uplo?= =?UTF-8?q?ad=20ordering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Moved generate_thumbnail() and thumbnails().set() to run after video upload - Now waits for video_id before attempting thumbnail upload - Applies only to widescreen videos (Shorts still skip thumbnails) --- modules/yt_poster.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/modules/yt_poster.py b/modules/yt_poster.py index a5b9ee6..3cd99c1 100644 --- a/modules/yt_poster.py +++ b/modules/yt_poster.py @@ -26,6 +26,7 @@ from pathlib import Path load_dotenv() + def upload_video(file_path: Path, is_vertical: bool, stream_date: str, description: str = None, private: bool = DEBUG) -> str: """ Uploads a video to YouTube, assigns to playlist, sets recording date, and optionally uploads a thumbnail. @@ -41,14 +42,6 @@ def upload_video(file_path: Path, is_vertical: bool, stream_date: str, descripti str: YouTube video URL. """ try: - thumbnail_path = generate_thumbnail(file_path) - if thumbnail_path: - youtube.thumbnails().set( - videoId=video_id, - media_body=str(thumbnail_path) - ).execute() - print("✅ Custom thumbnail generated and set.") - from authorize_youtube import get_authenticated_service youtube = get_authenticated_service() @@ -92,7 +85,7 @@ def upload_video(file_path: Path, is_vertical: bool, stream_date: str, descripti video_url = f"https://youtu.be/{video_id}" print(f"✅ Upload complete: {video_url}") - # THEN: + # ✅ Thumbnail upload (widescreen only) if not is_vertical: thumbnail_path = generate_thumbnail(file_path) if thumbnail_path: @@ -101,8 +94,8 @@ def upload_video(file_path: Path, is_vertical: bool, stream_date: str, descripti media_body=str(thumbnail_path) ).execute() print("✅ Custom thumbnail generated and set.") - - # Add to playlist + + # ✅ Add to playlist playlist_id = os.getenv("YT_PLAYLIST_ID_SHORTS" if is_vertical else "YT_PLAYLIST_ID_CLIPS") if playlist_id: youtube.playlistItems().insert( @@ -119,7 +112,7 @@ def upload_video(file_path: Path, is_vertical: bool, stream_date: str, descripti ).execute() print(f"✅ Added to playlist: {playlist_id}") - # Set recording date + # ✅ Set recording date parts = stream_date.split(".") date_obj = datetime(int(parts[0]), int(parts[1]), int(parts[2])) recording_date = date_obj.strftime("%Y-%m-%dT00:00:00Z") @@ -135,9 +128,6 @@ def upload_video(file_path: Path, is_vertical: bool, stream_date: str, descripti ).execute() print(f"✅ Recording date set: {recording_date}") - # TODO: Thumbnail upload (stub) - # generate_thumbnail(file_path) → upload via thumbnails().set() - return video_url except HttpError as e: