2015-07-19 20:36:14 +00:00
|
|
|
extern crate getopts;
|
2015-07-09 19:08:56 +00:00
|
|
|
extern crate librespot;
|
2015-08-25 21:51:49 +00:00
|
|
|
extern crate env_logger;
|
2016-03-24 09:31:33 +00:00
|
|
|
#[macro_use]
|
|
|
|
extern crate log;
|
2016-09-20 18:59:41 +00:00
|
|
|
extern crate simple_signal;
|
2015-04-25 20:32:07 +00:00
|
|
|
|
2016-04-24 12:29:26 +00:00
|
|
|
use std::process::exit;
|
2015-07-02 17:24:25 +00:00
|
|
|
use std::thread;
|
2015-08-25 21:51:49 +00:00
|
|
|
use std::env;
|
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-09-20 18:59:41 +00:00
|
|
|
use simple_signal::{Signal, Signals};
|
|
|
|
|
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-04-24 08:54:56 +00:00
|
|
|
if env::var("RUST_LOG").is_err() {
|
2016-04-24 11:15:53 +00:00
|
|
|
env::set_var("RUST_LOG", "info,librespot=trace")
|
2015-08-25 21:51:49 +00:00
|
|
|
}
|
|
|
|
env_logger::init().unwrap();
|
|
|
|
|
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) => {
|
2016-04-24 12:29:26 +00:00
|
|
|
error!("Error: {}\n{}", f.to_string(), usage(&args[0], &opts));
|
|
|
|
exit(1)
|
2016-04-24 11:15:53 +00:00
|
|
|
}
|
|
|
|
};
|
2016-03-13 20:45:31 +00:00
|
|
|
|
2016-04-24 12:29:26 +00:00
|
|
|
let session = main_helper::create_session(&matches);
|
|
|
|
let credentials = main_helper::get_credentials(&session, &matches);
|
|
|
|
session.login(credentials).unwrap();
|
2015-05-09 10:07:24 +00:00
|
|
|
|
2016-04-24 12:29:26 +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-09-20 18:59:41 +00:00
|
|
|
Signals::set_handler(&[Signal::Int, Signal::Term],
|
|
|
|
move |signals| {
|
|
|
|
println!("Signal received: {:?}. Say goodbye and exit.", signals);
|
|
|
|
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
|
|
|
}
|