|
| 1 | +# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from typing import Type, Optional, cast |
| 6 | + |
| 7 | +import httpx |
| 8 | + |
| 9 | +from .language import ( |
| 10 | + Language, |
| 11 | + AsyncLanguage, |
| 12 | + LanguageWithRawResponse, |
| 13 | + AsyncLanguageWithRawResponse, |
| 14 | + LanguageWithStreamingResponse, |
| 15 | + AsyncLanguageWithStreamingResponse, |
| 16 | +) |
| 17 | +from ...._types import NOT_GIVEN, Body, Query, Headers, NotGiven |
| 18 | +from ...._compat import cached_property |
| 19 | +from ...._resource import SyncAPIResource, AsyncAPIResource |
| 20 | +from ...._response import ( |
| 21 | + to_raw_response_wrapper, |
| 22 | + to_streamed_response_wrapper, |
| 23 | + async_to_raw_response_wrapper, |
| 24 | + async_to_streamed_response_wrapper, |
| 25 | +) |
| 26 | +from ...._wrappers import ResultWrapper |
| 27 | +from ...._base_client import ( |
| 28 | + make_request_options, |
| 29 | +) |
| 30 | +from ....types.stream import CaptionGetResponse |
| 31 | +from .language.language import Language, AsyncLanguage |
| 32 | + |
| 33 | +__all__ = ["Captions", "AsyncCaptions"] |
| 34 | + |
| 35 | + |
| 36 | +class Captions(SyncAPIResource): |
| 37 | + @cached_property |
| 38 | + def language(self) -> Language: |
| 39 | + return Language(self._client) |
| 40 | + |
| 41 | + @cached_property |
| 42 | + def with_raw_response(self) -> CaptionsWithRawResponse: |
| 43 | + return CaptionsWithRawResponse(self) |
| 44 | + |
| 45 | + @cached_property |
| 46 | + def with_streaming_response(self) -> CaptionsWithStreamingResponse: |
| 47 | + return CaptionsWithStreamingResponse(self) |
| 48 | + |
| 49 | + def get( |
| 50 | + self, |
| 51 | + identifier: str, |
| 52 | + *, |
| 53 | + account_id: str, |
| 54 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 55 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 56 | + extra_headers: Headers | None = None, |
| 57 | + extra_query: Query | None = None, |
| 58 | + extra_body: Body | None = None, |
| 59 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 60 | + ) -> Optional[CaptionGetResponse]: |
| 61 | + """ |
| 62 | + Lists the available captions or subtitles for a specific video. |
| 63 | +
|
| 64 | + Args: |
| 65 | + account_id: Identifier |
| 66 | +
|
| 67 | + identifier: A Cloudflare-generated unique identifier for a media item. |
| 68 | +
|
| 69 | + extra_headers: Send extra headers |
| 70 | +
|
| 71 | + extra_query: Add additional query parameters to the request |
| 72 | +
|
| 73 | + extra_body: Add additional JSON properties to the request |
| 74 | +
|
| 75 | + timeout: Override the client-level default timeout for this request, in seconds |
| 76 | + """ |
| 77 | + if not account_id: |
| 78 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 79 | + if not identifier: |
| 80 | + raise ValueError(f"Expected a non-empty value for `identifier` but received {identifier!r}") |
| 81 | + return self._get( |
| 82 | + f"/accounts/{account_id}/stream/{identifier}/captions", |
| 83 | + options=make_request_options( |
| 84 | + extra_headers=extra_headers, |
| 85 | + extra_query=extra_query, |
| 86 | + extra_body=extra_body, |
| 87 | + timeout=timeout, |
| 88 | + post_parser=ResultWrapper[Optional[CaptionGetResponse]]._unwrapper, |
| 89 | + ), |
| 90 | + cast_to=cast(Type[Optional[CaptionGetResponse]], ResultWrapper[CaptionGetResponse]), |
| 91 | + ) |
| 92 | + |
| 93 | + |
| 94 | +class AsyncCaptions(AsyncAPIResource): |
| 95 | + @cached_property |
| 96 | + def language(self) -> AsyncLanguage: |
| 97 | + return AsyncLanguage(self._client) |
| 98 | + |
| 99 | + @cached_property |
| 100 | + def with_raw_response(self) -> AsyncCaptionsWithRawResponse: |
| 101 | + return AsyncCaptionsWithRawResponse(self) |
| 102 | + |
| 103 | + @cached_property |
| 104 | + def with_streaming_response(self) -> AsyncCaptionsWithStreamingResponse: |
| 105 | + return AsyncCaptionsWithStreamingResponse(self) |
| 106 | + |
| 107 | + async def get( |
| 108 | + self, |
| 109 | + identifier: str, |
| 110 | + *, |
| 111 | + account_id: str, |
| 112 | + # Use the following arguments if you need to pass additional parameters to the API that aren't available via kwargs. |
| 113 | + # The extra values given here take precedence over values defined on the client or passed to this method. |
| 114 | + extra_headers: Headers | None = None, |
| 115 | + extra_query: Query | None = None, |
| 116 | + extra_body: Body | None = None, |
| 117 | + timeout: float | httpx.Timeout | None | NotGiven = NOT_GIVEN, |
| 118 | + ) -> Optional[CaptionGetResponse]: |
| 119 | + """ |
| 120 | + Lists the available captions or subtitles for a specific video. |
| 121 | +
|
| 122 | + Args: |
| 123 | + account_id: Identifier |
| 124 | +
|
| 125 | + identifier: A Cloudflare-generated unique identifier for a media item. |
| 126 | +
|
| 127 | + extra_headers: Send extra headers |
| 128 | +
|
| 129 | + extra_query: Add additional query parameters to the request |
| 130 | +
|
| 131 | + extra_body: Add additional JSON properties to the request |
| 132 | +
|
| 133 | + timeout: Override the client-level default timeout for this request, in seconds |
| 134 | + """ |
| 135 | + if not account_id: |
| 136 | + raise ValueError(f"Expected a non-empty value for `account_id` but received {account_id!r}") |
| 137 | + if not identifier: |
| 138 | + raise ValueError(f"Expected a non-empty value for `identifier` but received {identifier!r}") |
| 139 | + return await self._get( |
| 140 | + f"/accounts/{account_id}/stream/{identifier}/captions", |
| 141 | + options=make_request_options( |
| 142 | + extra_headers=extra_headers, |
| 143 | + extra_query=extra_query, |
| 144 | + extra_body=extra_body, |
| 145 | + timeout=timeout, |
| 146 | + post_parser=ResultWrapper[Optional[CaptionGetResponse]]._unwrapper, |
| 147 | + ), |
| 148 | + cast_to=cast(Type[Optional[CaptionGetResponse]], ResultWrapper[CaptionGetResponse]), |
| 149 | + ) |
| 150 | + |
| 151 | + |
| 152 | +class CaptionsWithRawResponse: |
| 153 | + def __init__(self, captions: Captions) -> None: |
| 154 | + self._captions = captions |
| 155 | + |
| 156 | + self.get = to_raw_response_wrapper( |
| 157 | + captions.get, |
| 158 | + ) |
| 159 | + |
| 160 | + @cached_property |
| 161 | + def language(self) -> LanguageWithRawResponse: |
| 162 | + return LanguageWithRawResponse(self._captions.language) |
| 163 | + |
| 164 | + |
| 165 | +class AsyncCaptionsWithRawResponse: |
| 166 | + def __init__(self, captions: AsyncCaptions) -> None: |
| 167 | + self._captions = captions |
| 168 | + |
| 169 | + self.get = async_to_raw_response_wrapper( |
| 170 | + captions.get, |
| 171 | + ) |
| 172 | + |
| 173 | + @cached_property |
| 174 | + def language(self) -> AsyncLanguageWithRawResponse: |
| 175 | + return AsyncLanguageWithRawResponse(self._captions.language) |
| 176 | + |
| 177 | + |
| 178 | +class CaptionsWithStreamingResponse: |
| 179 | + def __init__(self, captions: Captions) -> None: |
| 180 | + self._captions = captions |
| 181 | + |
| 182 | + self.get = to_streamed_response_wrapper( |
| 183 | + captions.get, |
| 184 | + ) |
| 185 | + |
| 186 | + @cached_property |
| 187 | + def language(self) -> LanguageWithStreamingResponse: |
| 188 | + return LanguageWithStreamingResponse(self._captions.language) |
| 189 | + |
| 190 | + |
| 191 | +class AsyncCaptionsWithStreamingResponse: |
| 192 | + def __init__(self, captions: AsyncCaptions) -> None: |
| 193 | + self._captions = captions |
| 194 | + |
| 195 | + self.get = async_to_streamed_response_wrapper( |
| 196 | + captions.get, |
| 197 | + ) |
| 198 | + |
| 199 | + @cached_property |
| 200 | + def language(self) -> AsyncLanguageWithStreamingResponse: |
| 201 | + return AsyncLanguageWithStreamingResponse(self._captions.language) |
0 commit comments