feat: add search suggestions
This commit is contained in:
parent
bbaa6cdb90
commit
77960170bb
3 changed files with 48 additions and 2 deletions
|
|
@ -1,4 +1,4 @@
|
|||
use serde::Serialize;
|
||||
use serde::{de::IgnoredAny, Serialize};
|
||||
|
||||
use crate::{
|
||||
deobfuscate::Deobfuscator,
|
||||
|
|
@ -79,6 +79,32 @@ impl RustyPipeQuery {
|
|||
)
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn search_suggestion(self, query: &str) -> Result<Vec<String>, Error> {
|
||||
let url = url::Url::parse_with_params("https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&gs_rn=64&gs_ri=youtube&ds=yt&cp=1&gs_id=4&xhr=t&xssi=t",
|
||||
&[("hl", self.opts.lang.to_string()), ("gl", self.opts.country.to_string()), ("q", query.to_string())]
|
||||
).map_err(|_| Error::Other("could not build url".into()))?;
|
||||
|
||||
let response = self
|
||||
.client
|
||||
.http_request_txt(self.client.inner.http.get(url).build()?)
|
||||
.await?;
|
||||
|
||||
let trimmed = response.get(5..).ok_or_else(|| {
|
||||
Error::Extraction(ExtractionError::InvalidData(
|
||||
"could not get string slice".into(),
|
||||
))
|
||||
})?;
|
||||
|
||||
let parsed = serde_json::from_str::<(
|
||||
IgnoredAny,
|
||||
Vec<(String, IgnoredAny, IgnoredAny)>,
|
||||
IgnoredAny,
|
||||
)>(trimmed)
|
||||
.map_err(|e| Error::Extraction(ExtractionError::InvalidData(e.to_string().into())))?;
|
||||
|
||||
Ok(parsed.1.into_iter().map(|item| item.0).collect())
|
||||
}
|
||||
}
|
||||
|
||||
impl MapResponse<SearchResult> for response::Search {
|
||||
|
|
|
|||
Reference in a new issue