Merge pull request #6 from Tubefeeder/bulk-feed

Bulk feed loading
This commit is contained in:
Kavin 2022-09-29 19:11:19 +01:00 committed by GitHub
commit fb51fef974
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 50 additions and 2 deletions

View file

@ -36,3 +36,7 @@ path = "search_channel.rs"
[[example]]
name = "comments"
path = "comments.rs"
[[example]]
name = "bulk_feed"
path = "bulk_feed.rs"

19
examples/bulk_feed.rs Normal file
View 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);
}

View file

@ -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<S: AsRef<str>>(httpclient: &Client, instance: S) -> PipedClient {
@ -61,6 +60,31 @@ impl PipedClient {
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>>(
&self,
id: S,

View file

@ -49,6 +49,7 @@ pub struct RelatedStream {
pub uploader_verified: bool,
pub duration: i32,
pub views: i64,
pub uploaded: i64,
}
#[derive(Debug, Deserialize)]