1use crate::{
2 config::Config,
3 error::OpenAIError,
4 types::videos::{
5 CreateVideoRequest, DeletedVideoResource, RemixVideoRequest, VideoListResource,
6 VideoResource,
7 },
8 Client, RequestOptions,
9};
10use bytes::Bytes;
11
12pub struct Videos<'c, C: Config> {
15 client: &'c Client<C>,
16 pub(crate) request_options: RequestOptions,
17}
18
19impl<'c, C: Config> Videos<'c, C> {
20 pub fn new(client: &'c Client<C>) -> Self {
21 Self {
22 client,
23 request_options: RequestOptions::new(),
24 }
25 }
26
27 #[crate::byot(
29 T0 = Clone,
30 R = serde::de::DeserializeOwned,
31 where_clause = "reqwest::multipart::Form: crate::traits::AsyncTryFrom<T0, Error = OpenAIError>",
32 )]
33 pub async fn create(&self, request: CreateVideoRequest) -> Result<VideoResource, OpenAIError> {
34 self.client
35 .post_form("/videos", request, &self.request_options)
36 .await
37 }
38
39 #[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
41 pub async fn remix(
42 &self,
43 video_id: &str,
44 request: RemixVideoRequest,
45 ) -> Result<VideoResource, OpenAIError> {
46 self.client
47 .post(
48 &format!("/videos/{video_id}/remix"),
49 request,
50 &self.request_options,
51 )
52 .await
53 }
54
55 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
57 pub async fn retrieve(&self, video_id: &str) -> Result<VideoResource, OpenAIError> {
58 self.client
59 .get(&format!("/videos/{}", video_id), &self.request_options)
60 .await
61 }
62
63 #[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
65 pub async fn delete(&self, video_id: &str) -> Result<DeletedVideoResource, OpenAIError> {
66 self.client
67 .delete(&format!("/videos/{}", video_id), &self.request_options)
68 .await
69 }
70
71 #[crate::byot(R = serde::de::DeserializeOwned)]
73 pub async fn list(&self) -> Result<VideoListResource, OpenAIError> {
74 self.client.get("/videos", &self.request_options).await
75 }
76
77 pub async fn download_content(&self, video_id: &str) -> Result<Bytes, OpenAIError> {
80 let (bytes, _headers) = self
81 .client
82 .get_raw(
83 &format!("/videos/{video_id}/content"),
84 &self.request_options,
85 )
86 .await?;
87 Ok(bytes)
88 }
89}