feat: make get_visitor_data() public
This commit is contained in:
parent
44f6a7a4a5
commit
2c9402aff6
2 changed files with 2 additions and 20 deletions
|
|
@ -79,7 +79,6 @@ pub async fn run_test(
|
||||||
|
|
||||||
let rp = RustyPipe::new();
|
let rp = RustyPipe::new();
|
||||||
let pb = ProgressBar::new(n as u64);
|
let pb = ProgressBar::new(n as u64);
|
||||||
let http = reqwest::Client::default();
|
|
||||||
pb.set_style(
|
pb.set_style(
|
||||||
ProgressStyle::with_template(
|
ProgressStyle::with_template(
|
||||||
"{msg} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len}",
|
"{msg} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len}",
|
||||||
|
|
@ -91,9 +90,8 @@ pub async fn run_test(
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let rp = rp.clone();
|
let rp = rp.clone();
|
||||||
let pb = pb.clone();
|
let pb = pb.clone();
|
||||||
let http = http.clone();
|
|
||||||
async move {
|
async move {
|
||||||
let visitor_data = get_visitor_data(&http).await;
|
let visitor_data = rp.query().get_visitor_data().await.unwrap();
|
||||||
let query = rp.query().visitor_data(&visitor_data);
|
let query = rp.query().visitor_data(&visitor_data);
|
||||||
let is_present = match ab {
|
let is_present = match ab {
|
||||||
ABTest::AttributedTextDescription => attributed_text_description(&query).await,
|
ABTest::AttributedTextDescription => attributed_text_description(&query).await,
|
||||||
|
|
@ -133,22 +131,6 @@ pub async fn run_test(
|
||||||
(count, vd_present, vd_absent)
|
(count, vd_present, vd_absent)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_visitor_data(http: &reqwest::Client) -> String {
|
|
||||||
let resp = http.get("https://www.youtube.com").send().await.unwrap();
|
|
||||||
resp.headers()
|
|
||||||
.get_all(reqwest::header::SET_COOKIE)
|
|
||||||
.iter()
|
|
||||||
.find_map(|c| {
|
|
||||||
if let Ok(cookie) = c.to_str() {
|
|
||||||
if let Some(after) = cookie.strip_prefix("__Secure-YEC=") {
|
|
||||||
return after.split_once(';').map(|s| s.0.to_owned());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
})
|
|
||||||
.unwrap()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn run_all_tests(n: usize, concurrency: usize) -> Vec<ABTestRes> {
|
pub async fn run_all_tests(n: usize, concurrency: usize) -> Vec<ABTestRes> {
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1259,7 +1259,7 @@ impl RustyPipeQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a YouTube visitor data cookie, which is necessary for certain requests
|
/// Get a YouTube visitor data cookie, which is necessary for certain requests
|
||||||
async fn get_visitor_data(&self) -> Result<String, Error> {
|
pub async fn get_visitor_data(&self) -> Result<String, Error> {
|
||||||
match &self.opts.visitor_data {
|
match &self.opts.visitor_data {
|
||||||
Some(vd) => Ok(vd.clone()),
|
Some(vd) => Ok(vd.clone()),
|
||||||
None => self.client.get_visitor_data().await,
|
None => self.client.get_visitor_data().await,
|
||||||
|
|
|
||||||
Reference in a new issue