mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Use discovery if username and password are not provided.
This commit is contained in:
parent
38351c9a87
commit
e35da9c90a
1 changed files with 17 additions and 9 deletions
14
src/main.rs
14
src/main.rs
|
@ -27,7 +27,7 @@ fn main() {
|
||||||
|
|
||||||
let mut opts = Options::new();
|
let mut opts = Options::new();
|
||||||
opts.reqopt("a", "appkey", "Path to a spotify appkey", "APPKEY");
|
opts.reqopt("a", "appkey", "Path to a spotify appkey", "APPKEY");
|
||||||
opts.reqopt("u", "username", "Username to sign in with", "USERNAME");
|
opts.optopt("u", "username", "Username to sign in with (optional)", "USERNAME");
|
||||||
opts.optopt("p", "password", "Password (optional)", "PASSWORD");
|
opts.optopt("p", "password", "Password (optional)", "PASSWORD");
|
||||||
opts.reqopt("c", "cache", "Path to a directory where files will be cached.", "CACHE");
|
opts.reqopt("c", "cache", "Path to a directory where files will be cached.", "CACHE");
|
||||||
opts.reqopt("n", "name", "Device name", "NAME");
|
opts.reqopt("n", "name", "Device name", "NAME");
|
||||||
|
@ -50,16 +50,20 @@ fn main() {
|
||||||
data
|
data
|
||||||
};
|
};
|
||||||
|
|
||||||
let username = matches.opt_str("u").unwrap();
|
let username = matches.opt_str("u");
|
||||||
let cache_location = matches.opt_str("c").unwrap();
|
let cache_location = matches.opt_str("c").unwrap();
|
||||||
let name = matches.opt_str("n").unwrap();
|
let name = matches.opt_str("n").unwrap();
|
||||||
|
|
||||||
|
let credentials = username.map(|u| {
|
||||||
let password = matches.opt_str("p").unwrap_or_else(|| {
|
let password = matches.opt_str("p").unwrap_or_else(|| {
|
||||||
print!("Password: ");
|
print!("Password: ");
|
||||||
stdout().flush().unwrap();
|
stdout().flush().unwrap();
|
||||||
read_password().unwrap()
|
read_password().unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
(u, password)
|
||||||
|
});
|
||||||
|
|
||||||
let config = Config {
|
let config = Config {
|
||||||
application_key: appkey,
|
application_key: appkey,
|
||||||
user_agent: version_string(),
|
user_agent: version_string(),
|
||||||
|
@ -68,9 +72,13 @@ fn main() {
|
||||||
};
|
};
|
||||||
|
|
||||||
let session = Session::new(config);
|
let session = Session::new(config);
|
||||||
//session.login_password(username, password).unwrap();
|
|
||||||
|
if let Some((username, password)) = credentials {
|
||||||
|
session.login_password(username, password).unwrap();
|
||||||
|
} else {
|
||||||
let mut discovery = DiscoveryManager::new(session.clone());
|
let mut discovery = DiscoveryManager::new(session.clone());
|
||||||
discovery.run();
|
discovery.run();
|
||||||
|
}
|
||||||
|
|
||||||
let player = Player::new(session.clone());
|
let player = Player::new(session.clone());
|
||||||
let mut spirc = SpircManager::new(session.clone(), player);
|
let mut spirc = SpircManager::new(session.clone(), player);
|
||||||
|
|
Loading…
Reference in a new issue