Created
November 22, 2025 00:09
-
-
Save hcarter333/b5ea606288516afb763059768d6646bb to your computer and use it in GitHub Desktop.
Retrieves thumbnails or sprite sheets for a list of Sora videos specified by video_id
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import requests | |
| VIDEO_IDS=["video_6920b2a68f408190b7fa0825034000d908416d7cf080c917" | |
| ] | |
| def download_sora_asset(video_id: str, filename: str, variant: str = "video"): | |
| """ | |
| Download a Sora video asset by video_id and save to filename. | |
| Args: | |
| video_id (str): The Sora video ID (e.g., "video_123abc"). | |
| filename (str): Output filename (e.g., "scene1.mp4"). | |
| variant (str): One of: video, thumbnail, preview, gif, cover_image | |
| """ | |
| api_key = os.environ["OPENAI_API_KEY"] | |
| url = f"https://api.openai.com/v1/videos/{video_id}/content?variant={variant}" | |
| headers = { | |
| "Authorization": f"Bearer {api_key}", | |
| } | |
| print(f"Downloading {variant} for {video_id} → {filename}") | |
| response = requests.get(url, headers=headers, stream=True) | |
| response.raise_for_status() | |
| with open(filename, "wb") as f: | |
| for chunk in response.iter_content(chunk_size=8192): | |
| if chunk: | |
| f.write(chunk) | |
| print(f"Saved {filename}") | |
| def main(): | |
| print("Starting downloads...\n") | |
| for video_id in VIDEO_IDS: | |
| filename = f"07_mulder_scully_silhouettes_2.mp4" # auto output filename | |
| download_sora_asset(video_id, filename, variant="video") | |
| print("\nAll downloads complete.") | |
| if __name__ == "__main__": | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment