modified: src/main.rs
new file: src/sobjects.rs
This commit is contained in:
parent
41a78013f1
commit
17e3f8881e
13
src/main.rs
13
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<dyn std::error::Error>> {
|
||||
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<Option<String>, Box<dyn Error>> {
|
||||
async fn get_playlists(user_id: u64, client_id: String, app_version: String) -> Result<CloudPlaylists, Box<dyn Error>> {
|
||||
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<Option<String>, Box<dyn Error>> {
|
||||
|
44
src/sobjects.rs
Normal file
44
src/sobjects.rs
Normal file
@ -0,0 +1,44 @@
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct CloudPlaylists {
|
||||
pub collection: Vec<CloudPlaylist>
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct CloudPlaylist {
|
||||
pub artwork_url: Option<String>,
|
||||
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<CloudTrack>
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct CloudTrack {
|
||||
pub artwork_url: Option<String>,
|
||||
pub created_at: Option<String>,
|
||||
pub description: Option<String>,
|
||||
pub duration: Option<u32>,
|
||||
pub genre: Option<String>,
|
||||
pub id: u64,
|
||||
pub permalink_url: Option<String>,
|
||||
pub title: Option<String>,
|
||||
pub uri: Option<String>,
|
||||
pub media: Option<CloudTranscodings>
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct CloudTranscodings {
|
||||
pub transcodings: Vec<CloudTranscoding>
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize)]
|
||||
pub struct CloudTranscoding {
|
||||
pub duration: u32,
|
||||
pub preset: String,
|
||||
pub quality: String,
|
||||
pub url: String
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user