From d14a1f6d9dfe04fc7edf086d8e9d5f0b1aabb401 Mon Sep 17 00:00:00 2001 From: Guillem Hernandez Sola Date: Fri, 8 May 2026 09:22:03 +0200 Subject: [PATCH] Fet --- bsky_post.py | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/bsky_post.py b/bsky_post.py index 601c68e..44410bf 100644 --- a/bsky_post.py +++ b/bsky_post.py @@ -318,6 +318,7 @@ def upload_image( logging.error(f"❌ Failed to upload image: {repr(e)}") return None + def upload_video_and_wait( client: Client, video_data: bytes, @@ -326,22 +327,32 @@ def upload_video_and_wait( try: logging.info("🎬 Uploading video to Bluesky Video Service...") - # 1. Upload the video (this goes to the dedicated video service) - # Note: In newer atproto versions, you can use client.upload_blob for videos too, - # but you MUST poll the video job status afterwards. - response = client.app.bsky.video.upload_video(video_data) + # Create a temporary client pointing to the official Bluesky service + # just for the video upload, using the same session token. + video_client = Client(base_url="https://bsky.social") + + # We must manually set the session so it knows who we are + if client.me: + # Re-use the existing authentication token + video_client.login(client.me.handle, client._session.app_password) + else: + logging.error("❌ Main client is not logged in.") + return None + + # 1. Upload the video to the official service + response = video_client.app.bsky.video.upload_video(video_data) job_id = response.job_id logging.info(f"⏳ Video uploaded! Job ID: {job_id}. Waiting for processing...") - # 2. Poll the job status + # 2. Poll the job status using the video client while True: - status_resp = client.app.bsky.video.get_job_status({'job_id': job_id}) + status_resp = video_client.app.bsky.video.get_job_status({'job_id': job_id}) state = status_resp.job_status.state if state == 'JOB_STATE_COMPLETED': logging.info("✅ Processing complete! Waiting 10s for CDN propagation...") - time.sleep(10) # Give the CDN time to distribute the file + time.sleep(10) return models.AppBskyEmbedVideo.Main( video=status_resp.job_status.blob, @@ -352,13 +363,12 @@ def upload_video_and_wait( return None logging.info(" ...still processing...") - time.sleep(3) # Wait 3 seconds before checking again + time.sleep(3) except Exception as e: logging.error(f"❌ Failed to upload/process video: {repr(e)}") return None - # ============================================================ # Post # ============================================================