use bytes::Bytes;
use crate::config::Config;
use crate::error::OpenAIError;
use crate::spec::videos::{
CreateVideoRequest, DeletedVideoResource, RemixVideoRequest, VideoListResource, VideoResource,
};
use crate::{Client, RequestOptions};
pub struct Videos<'c, C: Config> {
client: &'c Client<C>,
pub(crate) request_options: RequestOptions,
}
impl<'c, C: Config> Videos<'c, C> {
pub fn new(client: &'c Client<C>) -> Self {
Self {
client,
request_options: RequestOptions::new(),
}
}
#[crate::byot(
T0 = Clone,
R = serde::de::DeserializeOwned,
where_clause = "reqwest::multipart::Form: crate::traits::AsyncTryFrom<T0, Error = OpenAIError>",
)]
pub async fn create(&self, request: CreateVideoRequest) -> Result<VideoResource, OpenAIError> {
self.client
.post_form("/videos", request, &self.request_options)
.await
}
#[crate::byot(T0 = std::fmt::Display, T1 = serde::Serialize, R = serde::de::DeserializeOwned)]
pub async fn remix(
&self,
video_id: &str,
request: RemixVideoRequest,
) -> Result<VideoResource, OpenAIError> {
self.client
.post(
&format!("/videos/{video_id}/remix"),
request,
&self.request_options,
)
.await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn retrieve(&self, video_id: &str) -> Result<VideoResource, OpenAIError> {
self.client
.get(&format!("/videos/{}", video_id), &self.request_options)
.await
}
#[crate::byot(T0 = std::fmt::Display, R = serde::de::DeserializeOwned)]
pub async fn delete(&self, video_id: &str) -> Result<DeletedVideoResource, OpenAIError> {
self.client
.delete(&format!("/videos/{}", video_id), &self.request_options)
.await
}
#[crate::byot(R = serde::de::DeserializeOwned)]
pub async fn list(&self) -> Result<VideoListResource, OpenAIError> {
self.client.get("/videos", &self.request_options).await
}
pub async fn download_content(&self, video_id: &str) -> Result<Bytes, OpenAIError> {
let (bytes, _headers) = self
.client
.get_raw(
&format!("/videos/{video_id}/content"),
&self.request_options,
)
.await?;
Ok(bytes)
}
}