From 20ecea65ef74c3720a92a9fc5d6d640edec02bbb Mon Sep 17 00:00:00 2001 From: ThetaDev Date: Mon, 1 May 2023 10:51:12 +0200 Subject: [PATCH] fix: use response model for search suggestion --- src/client/response/mod.rs | 1 + src/client/response/search.rs | 9 ++++++++- src/client/search.rs | 10 +++------- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/client/response/mod.rs b/src/client/response/mod.rs index f334062..5a58082 100644 --- a/src/client/response/mod.rs +++ b/src/client/response/mod.rs @@ -33,6 +33,7 @@ pub(crate) use player::Player; pub(crate) use playlist::Playlist; pub(crate) use playlist::PlaylistCont; pub(crate) use search::Search; +pub(crate) use search::SearchSuggestion; pub(crate) use trends::Startpage; pub(crate) use trends::Trending; pub(crate) use url_endpoint::ResolvedUrl; diff --git a/src/client/response/search.rs b/src/client/response/search.rs index 92fc978..cea4f86 100644 --- a/src/client/response/search.rs +++ b/src/client/response/search.rs @@ -1,4 +1,4 @@ -use serde::Deserialize; +use serde::{de::IgnoredAny, Deserialize}; use serde_with::{json::JsonString, serde_as}; use super::{video_item::YouTubeListRendererWrap, ResponseContext}; @@ -24,3 +24,10 @@ pub(crate) struct Contents { pub(crate) struct TwoColumnSearchResultsRenderer { pub primary_contents: YouTubeListRendererWrap, } + +#[derive(Debug, Deserialize)] +pub(crate) struct SearchSuggestion( + IgnoredAny, + pub Vec<(String, IgnoredAny, IgnoredAny)>, + IgnoredAny, +); diff --git a/src/client/search.rs b/src/client/search.rs index d48f5d7..a0b93d3 100644 --- a/src/client/search.rs +++ b/src/client/search.rs @@ -1,4 +1,4 @@ -use serde::{de::IgnoredAny, Serialize}; +use serde::Serialize; use crate::{ error::{Error, ExtractionError}, @@ -79,12 +79,8 @@ impl RustyPipeQuery { .http_request_txt(self.client.inner.http.get(url).build()?) .await?; - let parsed = serde_json::from_str::<( - IgnoredAny, - Vec<(String, IgnoredAny, IgnoredAny)>, - IgnoredAny, - )>(&response) - .map_err(|e| Error::Extraction(ExtractionError::InvalidData(e.to_string().into())))?; + let parsed = serde_json::from_str::(&response) + .map_err(|e| Error::Extraction(ExtractionError::InvalidData(e.to_string().into())))?; Ok(parsed.1.into_iter().map(|item| item.0).collect()) }