improve videos
This commit is contained in:
51
bsky_post.py
51
bsky_post.py
@@ -347,6 +347,9 @@ def upload_video(
|
||||
return None
|
||||
|
||||
|
||||
# ============================================================
|
||||
# Post
|
||||
# ============================================================
|
||||
# ============================================================
|
||||
# Post
|
||||
# ============================================================
|
||||
@@ -359,25 +362,39 @@ def post_to_bsky(
|
||||
alt_text: str = "",
|
||||
) -> bool:
|
||||
rich_text = make_rich(text)
|
||||
embed = None
|
||||
|
||||
if image_path:
|
||||
image = upload_image(client, image_path, alt_text=alt_text)
|
||||
if not image:
|
||||
logging.error("❌ Aborting post: image upload failed.")
|
||||
return False
|
||||
embed = models.AppBskyEmbedImages.Main(images=[image])
|
||||
|
||||
elif video_path:
|
||||
video = upload_video(client, video_path, alt_text=alt_text)
|
||||
if not video:
|
||||
logging.error("❌ Aborting post: video upload failed.")
|
||||
return False
|
||||
embed = video
|
||||
|
||||
try:
|
||||
logging.info(f"🚀 Sending post (langs={langs}, text={text!r})")
|
||||
result = client.send_post(text=rich_text, embed=embed, langs=langs)
|
||||
# --- VIDEO POSTING ---
|
||||
if video_path:
|
||||
logging.info(f"🎬 Preparing video upload: {video_path}")
|
||||
with open(video_path, "rb") as f:
|
||||
video_data = f.read()
|
||||
|
||||
logging.info(f"🚀 Sending video post (this may take a moment to process)...")
|
||||
# client.send_video automatically handles the video service upload and processing wait
|
||||
result = client.send_video(
|
||||
text=rich_text,
|
||||
video=video_data,
|
||||
video_alt=alt_text,
|
||||
langs=langs
|
||||
)
|
||||
|
||||
# --- IMAGE POSTING ---
|
||||
elif image_path:
|
||||
image = upload_image(client, image_path, alt_text=alt_text)
|
||||
if not image:
|
||||
logging.error("❌ Aborting post: image upload failed.")
|
||||
return False
|
||||
|
||||
embed = models.AppBskyEmbedImages.Main(images=[image])
|
||||
logging.info(f"🚀 Sending image post...")
|
||||
result = client.send_post(text=rich_text, embed=embed, langs=langs)
|
||||
|
||||
# --- TEXT ONLY POSTING ---
|
||||
else:
|
||||
logging.info(f"🚀 Sending text post...")
|
||||
result = client.send_post(text=rich_text, langs=langs)
|
||||
|
||||
uri = getattr(result, "uri", None)
|
||||
logging.info(f"✅ Post published! URI: {uri}")
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user