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)}")
|
logging.error(f"❌ Failed to upload image: {repr(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def upload_video_and_wait(
|
def upload_video_and_wait(
|
||||||
client: Client,
|
client: Client,
|
||||||
video_data: bytes,
|
video_data: bytes,
|
||||||
@@ -326,22 +327,32 @@ def upload_video_and_wait(
|
|||||||
try:
|
try:
|
||||||
logging.info("🎬 Uploading video to Bluesky Video Service...")
|
logging.info("🎬 Uploading video to Bluesky Video Service...")
|
||||||
|
|
||||||
# 1. Upload the video (this goes to the dedicated video service)
|
# Create a temporary client pointing to the official Bluesky service
|
||||||
# Note: In newer atproto versions, you can use client.upload_blob for videos too,
|
# just for the video upload, using the same session token.
|
||||||
# but you MUST poll the video job status afterwards.
|
video_client = Client(base_url="https://bsky.social")
|
||||||
response = client.app.bsky.video.upload_video(video_data)
|
|
||||||
|
# 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
|
job_id = response.job_id
|
||||||
|
|
||||||
logging.info(f"⏳ Video uploaded! Job ID: {job_id}. Waiting for processing...")
|
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:
|
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
|
state = status_resp.job_status.state
|
||||||
|
|
||||||
if state == 'JOB_STATE_COMPLETED':
|
if state == 'JOB_STATE_COMPLETED':
|
||||||
logging.info("✅ Processing complete! Waiting 10s for CDN propagation...")
|
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(
|
return models.AppBskyEmbedVideo.Main(
|
||||||
video=status_resp.job_status.blob,
|
video=status_resp.job_status.blob,
|
||||||
@@ -352,13 +363,12 @@ def upload_video_and_wait(
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
logging.info(" ...still processing...")
|
logging.info(" ...still processing...")
|
||||||
time.sleep(3) # Wait 3 seconds before checking again
|
time.sleep(3)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(f"❌ Failed to upload/process video: {repr(e)}")
|
logging.error(f"❌ Failed to upload/process video: {repr(e)}")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
# ============================================================
|
# ============================================================
|
||||||
# Post
|
# Post
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user