recycleactor commited on
Commit
3d3f780
·
verified ·
1 Parent(s): d7ba09d

Upload 2 files

Browse files
Files changed (2) hide show
  1. src/api.rs +10 -5
  2. src/main.rs +15 -4
src/api.rs CHANGED
@@ -75,10 +75,12 @@ impl APIClient {
75
  let builder = Client::builder();
76
 
77
  let cookie = format!("arl={}; Domain=.deezer.com", arl);
 
78
  let url = "https://www.deezer.com".parse::<Url>().unwrap();
79
 
80
  let jar = Jar::default();
81
  jar.add_cookie_str(&cookie, &url);
 
82
  let builder = builder.cookie_provider(Arc::new(jar));
83
 
84
  Self {
@@ -104,14 +106,18 @@ impl APIClient {
104
  check_form = &self.check_form;
105
  }
106
 
107
- let json: DeezerResponse = self
108
- .client
109
- .post("https://www.deezer.com/ajax/gw-light.php")
 
 
 
 
110
  .query(&[
111
  ("method", method),
112
  ("input", "3"),
113
  ("api_version", "1.0"),
114
- ("api_token", check_form)
115
  ])
116
  .header(ACCEPT, "*/*")
117
  .header("Origin", "https://www.deezer.com")
@@ -122,7 +128,6 @@ impl APIClient {
122
  "User-Agent",
123
  "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0",
124
  )
125
- .json(params)
126
  .send()
127
  .await?
128
  .json()
 
75
  let builder = Client::builder();
76
 
77
  let cookie = format!("arl={}; Domain=.deezer.com", arl);
78
+ let comeback = "comeback=1; Domain=.deezer.com";
79
  let url = "https://www.deezer.com".parse::<Url>().unwrap();
80
 
81
  let jar = Jar::default();
82
  jar.add_cookie_str(&cookie, &url);
83
+ jar.add_cookie_str(comeback, &url);
84
  let builder = builder.cookie_provider(Arc::new(jar));
85
 
86
  Self {
 
106
  check_form = &self.check_form;
107
  }
108
 
109
+ let url = "https://www.deezer.com/ajax/gw-light.php";
110
+ let req = if method == "deezer.getUserData" {
111
+ self.client.get(url)
112
+ } else {
113
+ self.client.post(url).json(params)
114
+ };
115
+ let json: DeezerResponse = req
116
  .query(&[
117
  ("method", method),
118
  ("input", "3"),
119
  ("api_version", "1.0"),
120
+ ("api_token", check_form),
121
  ])
122
  .header(ACCEPT, "*/*")
123
  .header("Origin", "https://www.deezer.com")
 
128
  "User-Agent",
129
  "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0",
130
  )
 
131
  .send()
132
  .await?
133
  .json()
src/main.rs CHANGED
@@ -382,8 +382,13 @@ async fn gw_light_call(
382
  api_token: &str,
383
  params: serde_json::Value,
384
  ) -> Result<serde_json::Value, String> {
385
- let r = client
386
- .post("https://www.deezer.com/ajax/gw-light.php")
 
 
 
 
 
387
  .query(&[
388
  ("method", method),
389
  ("input", "3"),
@@ -399,12 +404,16 @@ async fn gw_light_call(
399
  "User-Agent",
400
  "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0",
401
  )
402
- .json(&params)
403
  .send()
404
  .await
405
  .map_err(|_| "network".to_string())?;
406
 
407
- let json: GwResp = r.json().await.map_err(|_| "parse".to_string())?;
 
 
 
 
 
408
 
409
  if let Some(error) = json.error.as_object() {
410
  for (code, message) in error {
@@ -424,6 +433,8 @@ async fn login(Json(req): Json<LoginReq>) -> impl IntoResponse {
424
  return json_error(StatusCode::BAD_REQUEST, "Email and password_md5 required");
425
  }
426
  let jar = Jar::default();
 
 
427
  let client = reqwest::Client::builder()
428
  .cookie_provider(Arc::new(jar))
429
  .timeout(std::time::Duration::from_secs(15))
 
382
  api_token: &str,
383
  params: serde_json::Value,
384
  ) -> Result<serde_json::Value, String> {
385
+ let url = "https://www.deezer.com/ajax/gw-light.php";
386
+ let req = if method == "deezer.getUserData" {
387
+ client.get(url)
388
+ } else {
389
+ client.post(url).json(&params)
390
+ };
391
+ let r = req
392
  .query(&[
393
  ("method", method),
394
  ("input", "3"),
 
404
  "User-Agent",
405
  "Mozilla/5.0 (X11; Linux x86_64; rv:128.0) Gecko/20100101 Firefox/128.0",
406
  )
 
407
  .send()
408
  .await
409
  .map_err(|_| "network".to_string())?;
410
 
411
+ let status = r.status();
412
+ let text = r.text().await.map_err(|_| "read".to_string())?;
413
+ let json: GwResp = serde_json::from_str(&text).map_err(|_| {
414
+ let snip: String = text.chars().take(200).collect();
415
+ format!("parse:{}:{}", status.as_u16(), snip)
416
+ })?;
417
 
418
  if let Some(error) = json.error.as_object() {
419
  for (code, message) in error {
 
433
  return json_error(StatusCode::BAD_REQUEST, "Email and password_md5 required");
434
  }
435
  let jar = Jar::default();
436
+ let url = "https://www.deezer.com".parse::<Url>().unwrap();
437
+ jar.add_cookie_str("comeback=1; Domain=.deezer.com", &url);
438
  let client = reqwest::Client::builder()
439
  .cookie_provider(Arc::new(jar))
440
  .timeout(std::time::Duration::from_secs(15))