mirror of
https://github.com/TeamPiped/piped-rust-sdk.git
synced 2024-08-14 23:56:06 +00:00
commit
fb51fef974
4 changed files with 50 additions and 2 deletions
|
@ -36,3 +36,7 @@ path = "search_channel.rs"
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "comments"
|
name = "comments"
|
||||||
path = "comments.rs"
|
path = "comments.rs"
|
||||||
|
|
||||||
|
[[example]]
|
||||||
|
name = "bulk_feed"
|
||||||
|
path = "bulk_feed.rs"
|
||||||
|
|
19
examples/bulk_feed.rs
Normal file
19
examples/bulk_feed.rs
Normal file
|
@ -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);
|
||||||
|
}
|
|
@ -9,8 +9,7 @@ pub struct PipedClient {
|
||||||
pub instance: String,
|
pub instance: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
const USER_AGENT: &'static str =
|
const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0";
|
||||||
"Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0";
|
|
||||||
|
|
||||||
impl PipedClient {
|
impl PipedClient {
|
||||||
pub fn new<S: AsRef<str>>(httpclient: &Client, instance: S) -> PipedClient {
|
pub fn new<S: AsRef<str>>(httpclient: &Client, instance: S) -> PipedClient {
|
||||||
|
@ -61,6 +60,31 @@ impl PipedClient {
|
||||||
Ok(channel)
|
Ok(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn bulk_feed<S: AsRef<str>, I: IntoIterator<Item = S>>(
|
||||||
|
&self,
|
||||||
|
ids: I,
|
||||||
|
) -> Result<Vec<RelatedStream>> {
|
||||||
|
let resp = &self
|
||||||
|
.httpclient
|
||||||
|
.get(format!(
|
||||||
|
"{}/feed/unauthenticated?channels={}",
|
||||||
|
&self.instance,
|
||||||
|
ids.into_iter()
|
||||||
|
.map(|s| s.as_ref().to_owned())
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(",")
|
||||||
|
))
|
||||||
|
.header("User-Agent", USER_AGENT)
|
||||||
|
.send()
|
||||||
|
.await?
|
||||||
|
.text()
|
||||||
|
.await?;
|
||||||
|
|
||||||
|
let videos: Vec<RelatedStream> = serde_json::from_str(resp.as_str())?;
|
||||||
|
|
||||||
|
Ok(videos)
|
||||||
|
}
|
||||||
|
|
||||||
pub async fn channel_continuation<S: AsRef<str>>(
|
pub async fn channel_continuation<S: AsRef<str>>(
|
||||||
&self,
|
&self,
|
||||||
id: S,
|
id: S,
|
||||||
|
|
|
@ -49,6 +49,7 @@ pub struct RelatedStream {
|
||||||
pub uploader_verified: bool,
|
pub uploader_verified: bool,
|
||||||
pub duration: i32,
|
pub duration: i32,
|
||||||
pub views: i64,
|
pub views: i64,
|
||||||
|
pub uploaded: i64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
|
Loading…
Reference in a new issue