Fet
This commit is contained in:
28
bsky_post.py
28
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
|
||||
# ============================================================
|
||||
|
||||
Reference in New Issue
Block a user