From 0c8e8f266129583c50a968207d76a21bc734da22 Mon Sep 17 00:00:00 2001 From: Gramps Date: Fri, 25 Jul 2025 19:13:47 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=96=BC=EF=B8=8F=20Add=20thumbnail=20gener?= =?UTF-8?q?ation=20to=20YouTube=20upload=20(widescreen=20only)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Integrated generate_thumbnail() into upload_video() - Attempted to upload custom thumbnail via thumbnails().set() - Applies only to widescreen videos (not vertical Shorts) - NOTE: Bug present — tries to upload thumbnail before video_id is available - Will fix by reordering after upload in next commit --- modules/yt_poster.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/yt_poster.py b/modules/yt_poster.py index 8cb1f1c..a5b9ee6 100644 --- a/modules/yt_poster.py +++ b/modules/yt_poster.py @@ -18,6 +18,7 @@ from googleapiclient.errors import HttpError from googleapiclient.http import MediaFileUpload from modules.title_utils import generate_montage_title from modules.description_utils import generate_montage_description +from modules.thumbnail_utils import generate_thumbnail from modules.config import DEBUG from dotenv import load_dotenv from datetime import datetime @@ -40,6 +41,14 @@ 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() @@ -83,6 +92,16 @@ 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: + if not is_vertical: + 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.") + # Add to playlist playlist_id = os.getenv("YT_PLAYLIST_ID_SHORTS" if is_vertical else "YT_PLAYLIST_ID_CLIPS") if playlist_id: