ff
This commit is contained in:
26
bsky_post.py
26
bsky_post.py
@@ -327,12 +327,21 @@ def upload_video_and_wait(
|
|||||||
alt_text: str = ""
|
alt_text: str = ""
|
||||||
) -> models.AppBskyEmbedVideo.Main | None:
|
) -> models.AppBskyEmbedVideo.Main | None:
|
||||||
try:
|
try:
|
||||||
VIDEO_SERVICE_DID = "did:web:video.bsky.app"
|
# --- Resolve PDS host + DID dynamically ---
|
||||||
|
# The Client stores the service URL it logged into
|
||||||
|
pds_base = str(client._base_url).rstrip("/") # e.g. https://eurosky.social
|
||||||
|
|
||||||
# --- Token #1: bound to uploadVideo ---
|
# Derive the DID from the hostname (works for did:web PDSes)
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
host = urlparse(pds_base).netloc
|
||||||
|
service_did = f"did:web:{host}"
|
||||||
|
|
||||||
|
logging.info(f"🎬 Using video service at {pds_base} (aud={service_did})")
|
||||||
|
|
||||||
|
# --- Token #1: uploadVideo, scoped to *this* PDS ---
|
||||||
logging.info("🎬 Requesting Service Auth for Video Upload...")
|
logging.info("🎬 Requesting Service Auth for Video Upload...")
|
||||||
upload_auth = client.com.atproto.server.get_service_auth({
|
upload_auth = client.com.atproto.server.get_service_auth({
|
||||||
'aud': VIDEO_SERVICE_DID,
|
'aud': service_did,
|
||||||
'lxm': 'app.bsky.video.uploadVideo',
|
'lxm': 'app.bsky.video.uploadVideo',
|
||||||
'exp': int(time.time()) + 60 * 30,
|
'exp': int(time.time()) + 60 * 30,
|
||||||
})
|
})
|
||||||
@@ -341,8 +350,9 @@ def upload_video_and_wait(
|
|||||||
"Content-Type": "video/mp4",
|
"Content-Type": "video/mp4",
|
||||||
}
|
}
|
||||||
|
|
||||||
logging.info("🎬 Uploading video to Bluesky Video Service...")
|
# --- Upload to the PDS, not video.bsky.app ---
|
||||||
upload_url = "https://video.bsky.app/xrpc/app.bsky.video.uploadVideo"
|
upload_url = f"{pds_base}/xrpc/app.bsky.video.uploadVideo"
|
||||||
|
logging.info(f"🎬 Uploading video to {upload_url}...")
|
||||||
upload_resp = requests.post(upload_url, headers=upload_headers, data=video_data)
|
upload_resp = requests.post(upload_url, headers=upload_headers, data=video_data)
|
||||||
|
|
||||||
if upload_resp.status_code != 200:
|
if upload_resp.status_code != 200:
|
||||||
@@ -356,15 +366,15 @@ def upload_video_and_wait(
|
|||||||
|
|
||||||
logging.info(f"⏳ Video uploaded! Job ID: {job_id}. Waiting for processing...")
|
logging.info(f"⏳ Video uploaded! Job ID: {job_id}. Waiting for processing...")
|
||||||
|
|
||||||
# --- Token #2: bound to getJobStatus ---
|
# --- Token #2: getJobStatus ---
|
||||||
status_auth = client.com.atproto.server.get_service_auth({
|
status_auth = client.com.atproto.server.get_service_auth({
|
||||||
'aud': VIDEO_SERVICE_DID,
|
'aud': service_did,
|
||||||
'lxm': 'app.bsky.video.getJobStatus',
|
'lxm': 'app.bsky.video.getJobStatus',
|
||||||
'exp': int(time.time()) + 60 * 30,
|
'exp': int(time.time()) + 60 * 30,
|
||||||
})
|
})
|
||||||
status_headers = {"Authorization": f"Bearer {status_auth.token}"}
|
status_headers = {"Authorization": f"Bearer {status_auth.token}"}
|
||||||
|
|
||||||
status_url = "https://video.bsky.app/xrpc/app.bsky.video.getJobStatus"
|
status_url = f"{pds_base}/xrpc/app.bsky.video.getJobStatus"
|
||||||
params = {"jobId": job_id}
|
params = {"jobId": job_id}
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
|
|||||||
Reference in New Issue
Block a user