From 3d5ec6f844ab20d5ef5e581ecacae100e3c8cbeb Mon Sep 17 00:00:00 2001 From: SadlyNotSappho Date: Tue, 24 Oct 2023 11:54:04 -0700 Subject: [PATCH] why. why is programming the way it is. it is october 2023 not january 1970. fuck this. fuck everything --- Cargo.lock | 13 +++++++++++++ Cargo.toml | 1 + src/main.rs | 31 ++++++++++++++++++++++++------- src/structs.rs | 4 ++-- 4 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e0d36a..c27e71f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -686,6 +686,7 @@ dependencies = [ "serde", "serde_json", "spotify-rs", + "tokio", "which", ] @@ -1332,9 +1333,21 @@ dependencies = [ "num_cpus", "pin-project-lite", "socket2 0.5.4", + "tokio-macros", "windows-sys", ] +[[package]] +name = "tokio-macros" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "tokio-native-tls" version = "0.3.1" diff --git a/Cargo.toml b/Cargo.toml index 4963290..d5a1898 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,5 @@ regex = "1.10.2" serde = { version = "1.0.189", features = ["derive"] } serde_json = "1.0.107" spotify-rs = "0.3.9" +tokio = { version = "1.33.0", features = ["rt-multi-thread", "macros"] } which = "4.4.2" diff --git a/src/main.rs b/src/main.rs index a24e849..962d239 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ -use std::process; - use clap::Parser; -use music_downloader::structs::Spotify; +use music_downloader::{read_config, structs::Spotify}; +use spotify_rs::{ClientCredsClient, ClientCredsFlow}; +use std::process; #[derive(Parser)] #[command(author, version, about, long_about = None)] @@ -16,8 +16,9 @@ struct Cli { config_file: String, } -fn main() { - // check for deps +#[tokio::main] +async fn main() { + // check for deps let ytdlp_exists = which::which("yt-dlp").is_ok(); let ffmpeg_exists = which::which("ffmpeg").is_ok(); if !ytdlp_exists { @@ -30,8 +31,8 @@ fn main() { } // handle args - let args = Cli::parse(); - println!("url: {}", args.url); + let args = Cli::parse(); + // println!("url: {}", args.url); println!("download from: {}", args.download_from); // init config @@ -39,6 +40,22 @@ fn main() { // run??? let spot = Spotify::from_link(&args.url); + println!("{spot:?}"); // TODO: get song info // TODO: add a way to put data in config from cli + + let config = read_config(&args.config_file[..]); + + let auth_flow = ClientCredsFlow::new(config.client_id, config.client_secret); + + println!("\n{auth_flow:?}\n"); + + // Create an authenticate the client + let mut spotify = ClientCredsClient::authenticate(auth_flow).await.unwrap(); + println!("\n{:?}\n", spotify.refresh_token()); + spotify.request_refresh_token().await.unwrap(); + + let album = spotify.album(&spot.id[..]).get().await.unwrap(); + + println!("{album:?}"); } diff --git a/src/structs.rs b/src/structs.rs index 9545375..d0385bc 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -8,12 +8,13 @@ pub struct Config { pub client_id: String, pub client_secret: String, } - +#[derive(Debug)] pub struct Spotify { pub mtype: SpotifyType, pub id: String, } +#[derive(Debug)] pub enum SpotifyType { Album, // album: https://open.spotify.com/album/5MfAxS5zz8MlfROjGQVXhy?si=2BBYm0iVR3m4UlQ3xE8RRg Playlist, // playlist: https://open.spotify.com/playlist/1XsYplOyHG528tYcSaZOhT?si=ef60c1c83a744e29 @@ -25,7 +26,6 @@ pub enum SpotifyType { impl Spotify { pub fn from_link(url: &String) -> Spotify { - println!("{url}"); let re = match Regex::new(r#"(open.spotify.com)\/(?album|playlist|track|artist|episode|show)\/(?[^?]*)"#) { Ok(val) => val, Err(why) => {