From fb03e23ae258ac230e762b3cb95522a6e528e504 Mon Sep 17 00:00:00 2001 From: Erik Kaju Date: Fri, 20 Jun 2025 17:49:32 +0300 Subject: [PATCH] remove --username --password arguments that are not supported by underlying librespot library --- src/main.rs | 13 +------------ src/session.rs | 26 +++----------------------- 2 files changed, 4 insertions(+), 35 deletions(-) diff --git a/src/main.rs b/src/main.rs index a059e72..b23e46d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,10 +18,6 @@ struct Opt { help = "A list of Spotify URIs or URLs (songs, podcasts, playlists or albums)" )] tracks: Vec, - #[structopt(short = "u", long = "username", help = "Your Spotify username")] - username: Option, - #[structopt(short = "p", long = "password", help = "Your Spotify password")] - password: Option, #[structopt( short = "d", long = "destination", @@ -92,14 +88,7 @@ async fn main() -> anyhow::Result<()> { eprintln!("Compression level is not supported yet. It will be ignored."); } - let user_name = opt.username.or_else(|| { - println!("No username provided via arguments. Attempting to fetch from latest credentials cache."); - std::fs::read_to_string("credentials.json").ok() - .and_then(|s| serde_json::from_str::(&s).ok()) - .and_then(|v| v.get("username")?.as_str().map(|s| s.to_string())) - }); - - let session = create_session(user_name.unwrap(), opt.password).await?; + let session = create_session().await?; let track = get_tracks(opt.tracks, &session).await?; let downloader = Downloader::new(session); diff --git a/src/session.rs b/src/session.rs index 2f9feba..777d4c9 100644 --- a/src/session.rs +++ b/src/session.rs @@ -2,36 +2,16 @@ use anyhow::Result; use librespot::core::cache::Cache; use librespot::core::config::SessionConfig; use librespot::core::session::Session; -use librespot::discovery::Credentials; -pub async fn create_session(username: String, password: Option) -> Result { +pub async fn create_session() -> Result { let credentials_store = dirs::home_dir().map(|p| p.join(".spotify-dl")); let cache = Cache::new(credentials_store, None, None, None)?; let session_config = SessionConfig::default(); - let credentials = get_credentials(username, password, &cache); - cache.save_credentials(&credentials); + let credentials = cache.credentials().unwrap(); let session = Session::new(session_config, Some(cache)); - session.connect(credentials, false).await?; + session.connect(credentials, true).await?; Ok(session) } - -fn prompt_password() -> Result { - tracing::info!("Spotify password was not provided. Please enter your Spotify password below"); - rpassword::prompt_password("Password: ").map_err(|e| e.into()) -} - -fn get_credentials(username: String, password: Option, cache: &Cache) -> Credentials { - match password { - Some(password) => Credentials::with_password(username, password), - None => cache.credentials().unwrap_or_else(|| { - tracing::warn!("No credentials found in cache"); - Credentials::with_password( - username, - prompt_password().unwrap_or_else(|_| panic!("Failed to get password")), - ) - }), - } -}