Use discovery if username and password are not provided.

This commit is contained in:
Paul Lietar 2016-01-02 02:30:03 +01:00
parent 38351c9a87
commit e35da9c90a

View file

@ -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,14 +50,18 @@ 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 password = matches.opt_str("p").unwrap_or_else(|| { let credentials = username.map(|u| {
print!("Password: "); let password = matches.opt_str("p").unwrap_or_else(|| {
stdout().flush().unwrap(); print!("Password: ");
read_password().unwrap() stdout().flush().unwrap();
read_password().unwrap()
});
(u, password)
}); });
let config = Config { let config = Config {
@ -68,9 +72,13 @@ fn main() {
}; };
let session = Session::new(config); let session = Session::new(config);
//session.login_password(username, password).unwrap();
let mut discovery = DiscoveryManager::new(session.clone()); if let Some((username, password)) = credentials {
discovery.run(); session.login_password(username, password).unwrap();
} else {
let mut discovery = DiscoveryManager::new(session.clone());
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);