🖼️ 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:
@ -18,6 +18,7 @@ from googleapiclient.errors import HttpError
|
|||||||
from googleapiclient.http import MediaFileUpload
|
from googleapiclient.http import MediaFileUpload
|
||||||
from modules.title_utils import generate_montage_title
|
from modules.title_utils import generate_montage_title
|
||||||
from modules.description_utils import generate_montage_description
|
from modules.description_utils import generate_montage_description
|
||||||
|
from modules.thumbnail_utils import generate_thumbnail
|
||||||
from modules.config import DEBUG
|
from modules.config import DEBUG
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from datetime import datetime
|
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.
|
str: YouTube video URL.
|
||||||
"""
|
"""
|
||||||
try:
|
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
|
from authorize_youtube import get_authenticated_service
|
||||||
youtube = 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}"
|
video_url = f"https://youtu.be/{video_id}"
|
||||||
print(f"✅ Upload complete: {video_url}")
|
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
|
# Add to playlist
|
||||||
playlist_id = os.getenv("YT_PLAYLIST_ID_SHORTS" if is_vertical else "YT_PLAYLIST_ID_CLIPS")
|
playlist_id = os.getenv("YT_PLAYLIST_ID_SHORTS" if is_vertical else "YT_PLAYLIST_ID_CLIPS")
|
||||||
if playlist_id:
|
if playlist_id:
|
||||||
|
|||||||
Reference in New Issue
Block a user