librespot/src/main.rs

61 lines
1.5 KiB
Rust
Raw Normal View History

extern crate getopts;
2015-07-09 19:08:56 +00:00
extern crate librespot;
extern crate env_logger;
2016-03-24 09:31:33 +00:00
#[macro_use]
extern crate log;
extern crate ctrlc;
2015-04-25 20:32:07 +00:00
use std::process::exit;
use std::thread;
use std::env;
use librespot::spirc::SpircManager;
use librespot::main_helper;
2016-03-16 00:05:05 +00:00
fn usage(program: &str, opts: &getopts::Options) -> String {
let brief = format!("Usage: {} [options]", program);
format!("{}", opts.usage(&brief))
}
2015-04-25 20:32:07 +00:00
fn main() {
if env::var("RUST_LOG").is_err() {
2016-12-31 13:30:01 +00:00
env::set_var("RUST_LOG", "mdns=info,librespot=trace")
}
env_logger::init().unwrap();
let mut opts = getopts::Options::new();
main_helper::add_session_arguments(&mut opts);
main_helper::add_authentication_arguments(&mut opts);
main_helper::add_player_arguments(&mut opts);
main_helper::add_program_arguments(&mut opts);
2016-01-02 02:30:24 +00:00
let args: Vec<String> = std::env::args().collect();
let matches = match opts.parse(&args[1..]) {
2016-01-02 15:19:39 +00:00
Ok(m) => m,
Err(f) => {
error!("Error: {}\n{}", f.to_string(), usage(&args[0], &opts));
exit(1)
2016-04-24 11:15:53 +00:00
}
};
let session = main_helper::create_session(&matches);
let credentials = main_helper::get_credentials(&session, &matches);
session.login(credentials).unwrap();
let player = main_helper::create_player(&session, &matches);
let spirc = SpircManager::new(session.clone(), player);
let spirc_signal = spirc.clone();
2016-01-02 15:19:39 +00:00
thread::spawn(move || spirc.run());
ctrlc::set_handler(move || {
spirc_signal.send_goodbye();
exit(0);
});
2016-01-01 23:16:12 +00:00
loop {
session.poll();
}
2015-07-01 17:49:03 +00:00
}