2015-07-19 20:36:14 +00:00
|
|
|
extern crate getopts;
|
2015-07-09 19:08:56 +00:00
|
|
|
extern crate librespot;
|
2016-12-31 11:51:44 +00:00
|
|
|
extern crate ctrlc;
|
2015-04-25 20:32:07 +00:00
|
|
|
|
2017-01-05 13:25:14 +00:00
|
|
|
use std::io::{stderr, Write};
|
2016-04-24 12:29:26 +00:00
|
|
|
use std::process::exit;
|
2015-07-02 17:24:25 +00:00
|
|
|
use std::thread;
|
2015-07-19 20:36:14 +00:00
|
|
|
|
2015-07-08 19:50:44 +00:00
|
|
|
use librespot::spirc::SpircManager;
|
2016-04-24 12:29:26 +00:00
|
|
|
use librespot::main_helper;
|
2016-03-16 00:05:05 +00:00
|
|
|
|
2016-03-14 23:41:51 +00:00
|
|
|
fn usage(program: &str, opts: &getopts::Options) -> String {
|
2015-07-19 20:36:14 +00:00
|
|
|
let brief = format!("Usage: {} [options]", program);
|
|
|
|
format!("{}", opts.usage(&brief))
|
|
|
|
}
|
|
|
|
|
2015-04-25 20:32:07 +00:00
|
|
|
fn main() {
|
2016-03-14 23:41:51 +00:00
|
|
|
let mut opts = getopts::Options::new();
|
2016-04-24 12:29:26 +00:00
|
|
|
main_helper::add_session_arguments(&mut opts);
|
|
|
|
main_helper::add_authentication_arguments(&mut opts);
|
|
|
|
main_helper::add_player_arguments(&mut opts);
|
2016-01-02 02:30:24 +00:00
|
|
|
|
2016-04-24 12:29:26 +00:00
|
|
|
let args: Vec<String> = std::env::args().collect();
|
2016-03-14 23:41:51 +00:00
|
|
|
|
2015-07-19 20:36:14 +00:00
|
|
|
let matches = match opts.parse(&args[1..]) {
|
2016-01-02 15:19:39 +00:00
|
|
|
Ok(m) => m,
|
|
|
|
Err(f) => {
|
2017-01-05 13:25:14 +00:00
|
|
|
writeln!(stderr(), "error: {}\n{}", f.to_string(), usage(&args[0], &opts)).unwrap();
|
|
|
|
exit(1);
|
2016-04-24 11:15:53 +00:00
|
|
|
}
|
|
|
|
};
|
2016-03-13 20:45:31 +00:00
|
|
|
|
2017-01-05 13:25:14 +00:00
|
|
|
main_helper::setup_logging(&matches);
|
|
|
|
|
2017-01-06 16:06:14 +00:00
|
|
|
let session = main_helper::create_session(&matches);
|
|
|
|
let credentials = main_helper::get_credentials(&session, &matches);
|
2016-04-24 12:29:26 +00:00
|
|
|
session.login(credentials).unwrap();
|
2015-05-09 10:07:24 +00:00
|
|
|
|
2017-01-06 16:06:14 +00:00
|
|
|
let player = main_helper::create_player(&session, &matches);
|
2016-03-20 16:16:11 +00:00
|
|
|
|
2016-03-13 22:35:09 +00:00
|
|
|
let spirc = SpircManager::new(session.clone(), player);
|
2016-09-20 18:59:41 +00:00
|
|
|
let spirc_signal = spirc.clone();
|
2016-01-02 15:19:39 +00:00
|
|
|
thread::spawn(move || spirc.run());
|
2016-12-31 11:51:44 +00:00
|
|
|
|
|
|
|
ctrlc::set_handler(move || {
|
|
|
|
spirc_signal.send_goodbye();
|
|
|
|
exit(0);
|
|
|
|
});
|
2015-07-02 17:24:25 +00:00
|
|
|
|
2016-01-01 23:16:12 +00:00
|
|
|
loop {
|
|
|
|
session.poll();
|
|
|
|
}
|
2015-07-01 17:49:03 +00:00
|
|
|
}
|