feat: add visitor data to paginator, trends: mapping tests
This commit is contained in:
parent
9ced819abe
commit
2b70badd4e
6 changed files with 5803 additions and 19 deletions
|
|
@ -71,4 +71,57 @@ paginator!(
|
|||
RustyPipeQuery::channel_playlists_continuation
|
||||
);
|
||||
paginator!(SearchItem, RustyPipeQuery::search_continuation);
|
||||
paginator!(SearchVideo, RustyPipeQuery::startpage_continuation);
|
||||
|
||||
impl Paginator<SearchVideo> {
|
||||
pub async fn next(&self, query: RustyPipeQuery) -> Result<Option<Self>, Error> {
|
||||
Ok(match (&self.ctoken, &self.visitor_data) {
|
||||
(Some(ctoken), Some(visitor_data)) => {
|
||||
Some(query.startpage_continuation(ctoken, visitor_data).await?)
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
pub async fn extend(&mut self, query: RustyPipeQuery) -> Result<bool, Error> {
|
||||
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<(), Error> {
|
||||
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<(), Error> {
|
||||
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