From 17e3f8881eb5e4edf36383771aa7048a6cfd4109 Mon Sep 17 00:00:00 2001 From: alterwain Date: Tue, 4 Feb 2025 18:28:37 +0300 Subject: [PATCH] modified: src/main.rs new file: src/sobjects.rs --- src/main.rs | 13 +++++++++---- src/sobjects.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 src/sobjects.rs diff --git a/src/main.rs b/src/main.rs index f2d9dcc..9c1f501 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,9 @@ use std::{collections::HashMap, error::Error, fmt::format, fs::File, io::Write}; use regex::Regex; use reqwest::header::{HOST, ORIGIN, REFERER, USER_AGENT}; +use sobjects::CloudPlaylists; + +mod sobjects; const CHROME_USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36"; const SOUNDCLOUD_API_DOMAIN: &str = "api-v2.soundcloud.com"; @@ -22,8 +25,8 @@ async fn main() -> Result<(), Box> { let client_id = get_client_id().await.unwrap().unwrap(); let user_id: u64 = 774639751; - let mut file = File::create("output.json").unwrap(); - file.write(get_playlists(user_id, client_id, app_version).await.unwrap().unwrap().as_bytes())?; + + println!("Playlists: {:#?}", get_playlists(user_id, client_id, app_version).await.unwrap()); Ok(()) } @@ -40,7 +43,7 @@ async fn get_likes(user_id: u64, client_id: String, app_version: String) -> Resu Ok(Some(resp)) } -async fn get_playlists(user_id: u64, client_id: String, app_version: String) -> Result, Box> { +async fn get_playlists(user_id: u64, client_id: String, app_version: String) -> Result> { let client = reqwest::Client::new(); let resp = client.get(format!("https://{}/users/{}/playlists_without_albums?client_id={}&limit=10&offset=0&linked_partitioning=1&app_version={}&app_locale=en", SOUNDCLOUD_API_DOMAIN, user_id, client_id, app_version)) @@ -50,7 +53,9 @@ async fn get_playlists(user_id: u64, client_id: String, app_version: String) -> .text() .await?; - Ok(Some(resp)) + let playlists: CloudPlaylists = serde_json::from_str(&resp)?; + + Ok(playlists) } async fn get_app() -> Result, Box> { diff --git a/src/sobjects.rs b/src/sobjects.rs new file mode 100644 index 0000000..d29b009 --- /dev/null +++ b/src/sobjects.rs @@ -0,0 +1,44 @@ +#[derive(Debug, serde::Deserialize)] +pub struct CloudPlaylists { + pub collection: Vec +} + +#[derive(Debug, serde::Deserialize)] +pub struct CloudPlaylist { + pub artwork_url: Option, + pub description: String, + pub genre: String, + pub id: u64, + pub permalink_url: String, + pub created_at: String, + pub title: String, + pub track_count: u32, + pub tracks: Vec +} + +#[derive(Debug, serde::Deserialize)] +pub struct CloudTrack { + pub artwork_url: Option, + pub created_at: Option, + pub description: Option, + pub duration: Option, + pub genre: Option, + pub id: u64, + pub permalink_url: Option, + pub title: Option, + pub uri: Option, + pub media: Option +} + +#[derive(Debug, serde::Deserialize)] +pub struct CloudTranscodings { + pub transcodings: Vec +} + +#[derive(Debug, serde::Deserialize)] +pub struct CloudTranscoding { + pub duration: u32, + pub preset: String, + pub quality: String, + pub url: String +} \ No newline at end of file