Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to download a video from a user's post using API #925

Open
Diegolzgz opened this issue Feb 2, 2025 · 1 comment
Open

How to download a video from a user's post using API #925

Diegolzgz opened this issue Feb 2, 2025 · 1 comment

Comments

@Diegolzgz
Copy link

I tried this but not working

def download_video_blob(blob_ref, save_path, access_jwt):
"""
Descarga el vídeo utilizando el endpoint /xrpc/com.atproto.sync.getBlob.
Se espera que blob_ref sea el valor del campo '$link' en el objeto video (de tipo blob).
"""
endpoint = f"{BLUESKY_API_BASE_URL}/xrpc/com.atproto.sync.getBlob"
headers = {
'Authorization': f'Bearer {access_jwt}',
'Accept': 'application/octet-stream'
}
params = {"ref": blob_ref}
try:
print(f"Descargando vídeo con blob reference: {blob_ref}")
response = send_request("GET", endpoint, headers=headers, params=params, stream=True)
with open(save_path, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
f.write(chunk)
print(f"Vídeo descargado exitosamente en: {save_path}")
except Exception as e:
print(f"Error descargando el vídeo blob: {e}")

def process_post(item, access_jwt, csv_writer, headers_auth, image_folder, video_folder, profile_cache, image_counts, video_counts):
[.....]
video_link = "N/A"
embed_obj = record.get("embed", {})
if embed_obj.get("$type", "").startswith("app.bsky.embed.video"):
video_obj = embed_obj.get("video", {})
if video_obj:
blob_ref = video_obj.get("ref", {}).get("$link")
if blob_ref:
video_counts[username] = video_counts.get(username, 0) + 1
video_filename = os.path.join(video_folder, f"{username}_{video_counts[username]}.mp4")
download_video_blob(blob_ref, video_filename, access_jwt)
video_link = blob_ref
else:
print("No se encontró el blob reference del vídeo.")
else:
print("No se encontró el objeto video en el embed.")
else:
uri = base_post.get("uri", "")
last_part = uri.split("/")[-1] if uri else ""
[...]

@Diegolzgz
Copy link
Author

Response: 400 Client Error: Bad Request for url: https://bsky.social/xrpc/com.atproto.sync.getBlob?ref=xxxxxxxxxxxxxxxxxxxxxxxxx_video.ref.$link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant