diff --git a/examples/Cargo.toml b/examples/Cargo.toml index f270c11..a711c04 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -20,3 +20,7 @@ path = "playlist.rs" [[example]] name = "trending" path = "trending.rs" + +[[example]] +name = "video" +path = "video.rs" diff --git a/examples/video.rs b/examples/video.rs new file mode 100644 index 0000000..d71ad97 --- /dev/null +++ b/examples/video.rs @@ -0,0 +1,21 @@ +use piped::piped::PipedClient; +use reqwest::ClientBuilder; + +#[tokio::main] +async fn main() { + let httpclient = ClientBuilder::new() + .user_agent("Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0") + .build() + .unwrap(); + + let instance = "https://pipedapi.kavin.rocks".to_string(); + + let client = PipedClient::new(httpclient, instance); + + let video = client + .get_video_from_id("__hYx6ZzFbQ".to_string()) + .await + .unwrap(); + + println!("{:?}", video); +} diff --git a/piped/src/lib.rs b/piped/src/lib.rs index 90a28f1..cf6b757 100644 --- a/piped/src/lib.rs +++ b/piped/src/lib.rs @@ -112,6 +112,23 @@ pub mod piped { Ok(streams) } + + pub async fn get_video_from_id( + &self, + id: String, + ) -> Result> { + let resp = &self + .httpclient + .get(format!("{}/streams/{}", &self.instance, id)) + .send() + .await? + .text() + .await?; + + let video: VideoInfo = serde_json::from_str(resp.as_str())?; + + Ok(video) + } } #[derive(Deserialize, Debug)] @@ -162,4 +179,55 @@ pub mod piped { pub duration: i32, pub views: i64, } + + #[derive(Debug, Deserialize)] + #[serde(rename_all = "camelCase")] + pub struct VideoInfo { + pub title: String, + pub description: String, + pub upload_date: String, + pub uploader: String, + pub uploader_url: String, + pub uploader_avatar: String, + pub thumbnail_url: String, + pub hls: ::serde_json::Value, + pub duration: i32, + pub views: i64, + pub likes: i64, + pub dislikes: i64, + pub audio_streams: Vec, + pub video_streams: Vec, + pub related_streams: Vec, + pub subtitles: Vec, + pub livestream: bool, + } + + #[derive(Debug, Deserialize)] + #[serde(rename_all = "camelCase")] + pub struct Stream { + pub url: String, + pub format: String, + pub quality: String, + pub mime_type: String, + pub codec: Option, + pub video_only: bool, + pub bitrate: i32, + pub init_start: i32, + pub init_end: i32, + pub index_start: i32, + pub index_end: i32, + pub width: i32, + pub height: i32, + pub fps: i32, + } + + #[derive(Debug, Deserialize)] + #[serde(rename_all = "camelCase")] + pub struct Subtitle { + pub url: String, + pub mime_type: String, + pub name: String, + pub code: String, + pub auto_generated: bool, + } }