🐛 Fix YouTube thumbnail upload ordering
- 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)
This commit is contained in:
@ -26,6 +26,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
|
|
||||||
def upload_video(file_path: Path, is_vertical: bool, stream_date: str, description: str = None, private: bool = DEBUG) -> str:
|
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.
|
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.
|
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()
|
||||||
|
|
||||||
@ -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}"
|
video_url = f"https://youtu.be/{video_id}"
|
||||||
print(f"✅ Upload complete: {video_url}")
|
print(f"✅ Upload complete: {video_url}")
|
||||||
|
|
||||||
# THEN:
|
# ✅ Thumbnail upload (widescreen only)
|
||||||
if not is_vertical:
|
if not is_vertical:
|
||||||
thumbnail_path = generate_thumbnail(file_path)
|
thumbnail_path = generate_thumbnail(file_path)
|
||||||
if thumbnail_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)
|
media_body=str(thumbnail_path)
|
||||||
).execute()
|
).execute()
|
||||||
print("✅ Custom thumbnail generated and set.")
|
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:
|
||||||
youtube.playlistItems().insert(
|
youtube.playlistItems().insert(
|
||||||
@ -119,7 +112,7 @@ def upload_video(file_path: Path, is_vertical: bool, stream_date: str, descripti
|
|||||||
).execute()
|
).execute()
|
||||||
print(f"✅ Added to playlist: {playlist_id}")
|
print(f"✅ Added to playlist: {playlist_id}")
|
||||||
|
|
||||||
# Set recording date
|
# ✅ Set recording date
|
||||||
parts = stream_date.split(".")
|
parts = stream_date.split(".")
|
||||||
date_obj = datetime(int(parts[0]), int(parts[1]), int(parts[2]))
|
date_obj = datetime(int(parts[0]), int(parts[1]), int(parts[2]))
|
||||||
recording_date = date_obj.strftime("%Y-%m-%dT00:00:00Z")
|
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()
|
).execute()
|
||||||
print(f"✅ Recording date set: {recording_date}")
|
print(f"✅ Recording date set: {recording_date}")
|
||||||
|
|
||||||
# TODO: Thumbnail upload (stub)
|
|
||||||
# generate_thumbnail(file_path) → upload via thumbnails().set()
|
|
||||||
|
|
||||||
return video_url
|
return video_url
|
||||||
|
|
||||||
except HttpError as e:
|
except HttpError as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user