diff --git a/codegen/src/abtest.rs b/codegen/src/abtest.rs index eadf73e..f1d8cbb 100644 --- a/codegen/src/abtest.rs +++ b/codegen/src/abtest.rs @@ -79,7 +79,6 @@ pub async fn run_test( let rp = RustyPipe::new(); let pb = ProgressBar::new(n as u64); - let http = reqwest::Client::default(); pb.set_style( ProgressStyle::with_template( "{msg} [{elapsed_precise}] [{wide_bar:.cyan/blue}] {pos}/{len}", @@ -91,9 +90,8 @@ pub async fn run_test( .map(|_| { let rp = rp.clone(); let pb = pb.clone(); - let http = http.clone(); 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 is_present = match ab { ABTest::AttributedTextDescription => attributed_text_description(&query).await, @@ -133,22 +131,6 @@ pub async fn run_test( (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 { let mut results = Vec::new(); diff --git a/src/client/mod.rs b/src/client/mod.rs index c5999ef..7eb83d1 100644 --- a/src/client/mod.rs +++ b/src/client/mod.rs @@ -1259,7 +1259,7 @@ impl RustyPipeQuery { } /// Get a YouTube visitor data cookie, which is necessary for certain requests - async fn get_visitor_data(&self) -> Result { + pub async fn get_visitor_data(&self) -> Result { match &self.opts.visitor_data { Some(vd) => Ok(vd.clone()), None => self.client.get_visitor_data().await,