feat: add search
This commit is contained in:
parent
6251ec1bd9
commit
ecb84e32e1
19 changed files with 710 additions and 106 deletions
|
|
@ -1,7 +1,7 @@
|
|||
use crate::error::Result;
|
||||
|
||||
use crate::model::{
|
||||
ChannelPlaylist, ChannelVideo, Comment, Paginator, PlaylistVideo, RecommendedVideo,
|
||||
ChannelPlaylist, ChannelVideo, Comment, Paginator, PlaylistVideo, RecommendedVideo, SearchItem,
|
||||
};
|
||||
|
||||
use super::RustyPipeQuery;
|
||||
|
|
@ -225,3 +225,47 @@ impl Paginator<Comment> {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Paginator<SearchItem> {
|
||||
pub async fn next(&self, query: RustyPipeQuery) -> Result<Option<Self>> {
|
||||
Ok(match &self.ctoken {
|
||||
Some(ctoken) => Some(query.search_continuation(ctoken).await?),
|
||||
None => None,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn extend(&mut self, query: RustyPipeQuery) -> Result<bool> {
|
||||
match self.next(query).await {
|
||||
Ok(Some(paginator)) => {
|
||||
let mut items = paginator.items;
|
||||
self.items.append(&mut items);
|
||||
self.ctoken = paginator.ctoken;
|
||||
Ok(true)
|
||||
}
|
||||
Ok(None) => Ok(false),
|
||||
Err(e) => Err(e),
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn extend_pages(&mut self, query: RustyPipeQuery, n_pages: usize) -> Result<()> {
|
||||
for _ in 0..n_pages {
|
||||
match self.extend(query.clone()).await {
|
||||
Ok(false) => break,
|
||||
Err(e) => return Err(e),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn extend_limit(&mut self, query: RustyPipeQuery, n_items: usize) -> Result<()> {
|
||||
while self.items.len() < n_items {
|
||||
match self.extend(query.clone()).await {
|
||||
Ok(false) => break,
|
||||
Err(e) => return Err(e),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue