fix: use xhr mode for search suggestions
This commit is contained in:
parent
11b754f299
commit
f420200f52
1 changed files with 10 additions and 12 deletions
|
|
@ -1,5 +1,3 @@
|
||||||
use std::borrow::Cow;
|
|
||||||
|
|
||||||
use serde::{de::IgnoredAny, Serialize};
|
use serde::{de::IgnoredAny, Serialize};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
|
@ -66,26 +64,26 @@ impl RustyPipeQuery {
|
||||||
|
|
||||||
/// Get YouTube search suggestions
|
/// Get YouTube search suggestions
|
||||||
pub async fn search_suggestion<S: AsRef<str>>(&self, query: S) -> Result<Vec<String>, Error> {
|
pub async fn search_suggestion<S: AsRef<str>>(&self, query: S) -> 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",
|
let url = url::Url::parse_with_params(
|
||||||
&[("hl", self.opts.lang.to_string()), ("gl", self.opts.country.to_string()), ("q", query.as_ref().to_owned())]
|
"https://suggestqueries-clients6.youtube.com/complete/search?client=youtube&xhr=t",
|
||||||
).map_err(|_| Error::Other("could not build url".into()))?;
|
&[
|
||||||
|
("hl", self.opts.lang.to_string()),
|
||||||
|
("gl", self.opts.country.to_string()),
|
||||||
|
("q", query.as_ref().to_owned()),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
.map_err(|_| Error::Other("could not build url".into()))?;
|
||||||
|
|
||||||
let response = self
|
let response = self
|
||||||
.client
|
.client
|
||||||
.http_request_txt(self.client.inner.http.get(url).build()?)
|
.http_request_txt(self.client.inner.http.get(url).build()?)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let trimmed = response
|
|
||||||
.get(5..)
|
|
||||||
.ok_or(Error::Extraction(ExtractionError::InvalidData(
|
|
||||||
Cow::Borrowed("could not get string slice"),
|
|
||||||
)))?;
|
|
||||||
|
|
||||||
let parsed = serde_json::from_str::<(
|
let parsed = serde_json::from_str::<(
|
||||||
IgnoredAny,
|
IgnoredAny,
|
||||||
Vec<(String, IgnoredAny, IgnoredAny)>,
|
Vec<(String, IgnoredAny, IgnoredAny)>,
|
||||||
IgnoredAny,
|
IgnoredAny,
|
||||||
)>(trimmed)
|
)>(&response)
|
||||||
.map_err(|e| Error::Extraction(ExtractionError::InvalidData(e.to_string().into())))?;
|
.map_err(|e| Error::Extraction(ExtractionError::InvalidData(e.to_string().into())))?;
|
||||||
|
|
||||||
Ok(parsed.1.into_iter().map(|item| item.0).collect())
|
Ok(parsed.1.into_iter().map(|item| item.0).collect())
|
||||||
|
|
|
||||||
Reference in a new issue