mirror of
				https://github.com/TeamPiped/piped-rust-sdk.git
				synced 2024-08-14 23:56:06 +00:00 
			
		
		
		
	Bulk feed loading
This commit is contained in:
		
							parent
							
								
									23f987f100
								
							
						
					
					
						commit
						e1051004e6
					
				
					 4 changed files with 50 additions and 2 deletions
				
			
		| 
						 | 
				
			
			@ -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,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -49,6 +49,7 @@ pub struct RelatedStream {
 | 
			
		|||
    pub uploader_verified: bool,
 | 
			
		||||
    pub duration: i32,
 | 
			
		||||
    pub views: i64,
 | 
			
		||||
    pub uploaded: i64,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Debug, Deserialize)]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue