🖼️ Add thumbnail generation to YouTube upload (widescreen only)

- 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
This commit is contained in:
2025-07-25 19:13:47 -07:00
parent 961c43fbd5
commit 0c8e8f2661

View File

@ -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: