ff
This commit is contained in:
42
bsky_post.py
42
bsky_post.py
@@ -327,27 +327,23 @@ def upload_video_and_wait(
|
||||
alt_text: str = ""
|
||||
) -> models.AppBskyEmbedVideo.Main | None:
|
||||
try:
|
||||
logging.info("🎬 Requesting Service Auth for Video Upload...")
|
||||
|
||||
# 1. Get a Service Auth token from your home PDS
|
||||
VIDEO_SERVICE_DID = "did:web:video.bsky.app"
|
||||
auth_response = client.com.atproto.server.get_service_auth({
|
||||
|
||||
# --- Token #1: bound to uploadVideo ---
|
||||
logging.info("🎬 Requesting Service Auth for Video Upload...")
|
||||
upload_auth = client.com.atproto.server.get_service_auth({
|
||||
'aud': VIDEO_SERVICE_DID,
|
||||
'exp': int(time.time()) + 60 * 30, # Token valid for 30 mins
|
||||
'lxm': 'app.bsky.video.uploadVideo',
|
||||
'exp': int(time.time()) + 60 * 30,
|
||||
})
|
||||
service_auth_token = auth_response.token
|
||||
|
||||
logging.info("🎬 Uploading video to Bluesky Video Service...")
|
||||
|
||||
# 2. Upload the video using standard HTTP requests
|
||||
upload_url = "https://video.bsky.app/xrpc/app.bsky.video.uploadVideo"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {service_auth_token}",
|
||||
"Content-Type": "video/mp4" # Assuming mp4, adjust if needed
|
||||
upload_headers = {
|
||||
"Authorization": f"Bearer {upload_auth.token}",
|
||||
"Content-Type": "video/mp4",
|
||||
}
|
||||
|
||||
# The endpoint expects the raw bytes in the body
|
||||
upload_resp = requests.post(upload_url, headers=headers, data=video_data)
|
||||
logging.info("🎬 Uploading video to Bluesky Video Service...")
|
||||
upload_url = "https://video.bsky.app/xrpc/app.bsky.video.uploadVideo"
|
||||
upload_resp = requests.post(upload_url, headers=upload_headers, data=video_data)
|
||||
|
||||
if upload_resp.status_code != 200:
|
||||
logging.error(f"❌ Video upload failed: {upload_resp.status_code} - {upload_resp.text}")
|
||||
@@ -360,12 +356,19 @@ def upload_video_and_wait(
|
||||
|
||||
logging.info(f"⏳ Video uploaded! Job ID: {job_id}. Waiting for processing...")
|
||||
|
||||
# 3. Poll the job status
|
||||
# --- Token #2: bound to getJobStatus ---
|
||||
status_auth = client.com.atproto.server.get_service_auth({
|
||||
'aud': VIDEO_SERVICE_DID,
|
||||
'lxm': 'app.bsky.video.getJobStatus',
|
||||
'exp': int(time.time()) + 60 * 30,
|
||||
})
|
||||
status_headers = {"Authorization": f"Bearer {status_auth.token}"}
|
||||
|
||||
status_url = "https://video.bsky.app/xrpc/app.bsky.video.getJobStatus"
|
||||
params = {"jobId": job_id}
|
||||
|
||||
while True:
|
||||
status_resp = requests.get(status_url, headers=headers, params=params)
|
||||
status_resp = requests.get(status_url, headers=status_headers, params=params)
|
||||
|
||||
if status_resp.status_code != 200:
|
||||
logging.error(f"❌ Failed to get job status: {status_resp.status_code} - {status_resp.text}")
|
||||
@@ -378,10 +381,7 @@ def upload_video_and_wait(
|
||||
logging.info("✅ Processing complete! Waiting 10s for CDN propagation...")
|
||||
time.sleep(10)
|
||||
|
||||
# Construct the blob object exactly as the SDK expects it
|
||||
blob_dict = job_status.get("blob")
|
||||
|
||||
# Convert the raw dictionary into the SDK's BlobRef model
|
||||
blob_ref = models.BlobRef.from_dict(blob_dict)
|
||||
|
||||
return models.AppBskyEmbedVideo.Main(
|
||||
|
||||
Reference in New Issue
Block a user