Download a specific time range from a YouTube video as an MP4 clip
How to run this route from Python with the Ouro SDK.
API access requires an API key. Create one in Settings โ API Keys, then set OURO_API_KEY in your environment. Install the SDK with pip install ouro-py.
POST /video/youtube-clipParameters and request body schema for this route.
Optional name for the file asset. If not provided, uses the video title.
End time in HH:MM:SS or MM:SS format
Start time in HH:MM:SS or MM:SS format
The YouTube video URL
Each run saves these to Ouro. Read them by name from action.final_data.
execute returns an action: the record of this run, with its status, response, and any assets it created.
To avoid blocking on a slow run, start it without waiting and collect the result later.
By default a failed run comes back as an action with status error. Pass raise_on_error=True to raise an exception instead.
Every run is saved as an action. List yours, or read the logs of a single run. See the Python SDK reference for everything an action carries.
import os
from ouro import Ouro
ouro = Ouro(api_key=os.environ.get("OURO_API_KEY"))
# The ID also works, and stays the same if the route is renamed: "3f49c64c-f927-4d98-b89d-d518e75e15d3"
route = ouro.routes.retrieve("hermes/download-a-clip-from-youtube")
action = route.execute(
body={
"end_time": "00:01:10",
"start_time": "00:00:00",
"youtube_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
},
)
print(action.status) # "success" or "error"
print(action.final_data)
# Assets the run created are keyed by output name
file = action.final_data["file"]
print(file["id"])# Returns as soon as the run is accepted
action = route.execute(
body={
"end_time": "00:01:10",
"start_time": "00:00:00",
"youtube_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
},
wait=False,
)
print(action.id, action.status)
# Later, even from another process
action = ouro.routes.poll_action(str(action.id), poll_interval=5, timeout=1800)
print(action.final_data)from ouro import ExternalServiceError, RouteExecutionError
try:
action = route.execute(
body={
"end_time": "00:01:10",
"start_time": "00:00:00",
"youtube_url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
},
raise_on_error=True,
)
except ExternalServiceError as exc:
# The API behind this route failed
print(exc.status_code, exc.retryable)
except RouteExecutionError as exc:
print(exc.action_id, exc.status, exc.response)
except TimeoutError as exc:
# Still running on Ouro; pick it up again later
action = ouro.routes.poll_action(exc.action_id, timeout=None)route = ouro.routes.retrieve("hermes/download-a-clip-from-youtube")
# Your runs of this route
actions = route.read_actions()
for action in actions:
print(action.id, action.status, action.created_at)
# One run and its logs
action = ouro.routes.retrieve_action("your-action-id")
for entry in action.read_logs(chronological=True):
print(entry.level, entry.message)Execution
Usage
1 callView history