diff --git a/examples/Cargo.toml b/examples/Cargo.toml index a2cd572..692609b 100644 --- a/examples/Cargo.toml +++ b/examples/Cargo.toml @@ -36,3 +36,7 @@ path = "search_channel.rs" [[example]] name = "comments" path = "comments.rs" + +[[example]] +name = "bulk_feed" +path = "bulk_feed.rs" diff --git a/examples/bulk_feed.rs b/examples/bulk_feed.rs new file mode 100644 index 0000000..a1eb9fc --- /dev/null +++ b/examples/bulk_feed.rs @@ -0,0 +1,19 @@ +use piped::PipedClient; +use reqwest::Client; + +const INSTANCE: &'static str = "https://pipedapi.kavin.rocks"; +const CHANNELS: &[&str; 2] = &["UCXuqSBlHAE6Xw-yeJA0Tunw", "UCdBK94H6oZT2Q7l0-b0xmMg"]; + +#[tokio::main] +async fn main() { + let httpclient = Client::new(); + + let client = PipedClient::new(&httpclient, INSTANCE); + + let videos = client + .bulk_feed(CHANNELS) + .await + .unwrap(); + + println!("{:#?}", videos); +} diff --git a/piped/src/client.rs b/piped/src/client.rs index 3a8c511..515fa85 100644 --- a/piped/src/client.rs +++ b/piped/src/client.rs @@ -9,8 +9,7 @@ pub struct PipedClient { pub instance: String, } -const USER_AGENT: &'static str = - "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"; +const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"; impl PipedClient { pub fn new>(httpclient: &Client, instance: S) -> PipedClient { @@ -61,6 +60,31 @@ impl PipedClient { Ok(channel) } + pub async fn bulk_feed, I: IntoIterator>( + &self, + ids: I, + ) -> Result> { + let resp = &self + .httpclient + .get(format!( + "{}/feed/unauthenticated?channels={}", + &self.instance, + ids.into_iter() + .map(|s| s.as_ref().to_owned()) + .collect::>() + .join(",") + )) + .header("User-Agent", USER_AGENT) + .send() + .await? + .text() + .await?; + + let videos: Vec = serde_json::from_str(resp.as_str())?; + + Ok(videos) + } + pub async fn channel_continuation>( &self, id: S, diff --git a/piped/src/structure.rs b/piped/src/structure.rs index 72b1cd4..f527f26 100644 --- a/piped/src/structure.rs +++ b/piped/src/structure.rs @@ -49,6 +49,7 @@ pub struct RelatedStream { pub uploader_verified: bool, pub duration: i32, pub views: i64, + pub uploaded: i64, } #[derive(Debug, Deserialize)]