|
@@ -1,9 +1,7 @@
|
|
|
use getopts;
|
|
|
use rpassword;
|
|
|
-use std::fs::File;
|
|
|
-use std::io::{stdout, Read, Write};
|
|
|
+use std::io::{stdout, Write};
|
|
|
use std::path::PathBuf;
|
|
|
-use std::path::Path;
|
|
|
use std::process::exit;
|
|
|
|
|
|
use audio_backend::{BACKENDS, Sink};
|
|
@@ -12,7 +10,6 @@ use cache::{Cache, DefaultCache, NoCache};
|
|
|
use player::Player;
|
|
|
use session::{Bitrate, Config, Session};
|
|
|
use version;
|
|
|
-use APPKEY;
|
|
|
|
|
|
pub fn find_backend(name: Option<&str>) -> &'static (Fn() -> Box<Sink> + Send + Sync) {
|
|
|
match name {
|
|
@@ -37,27 +34,10 @@ pub fn find_backend(name: Option<&str>) -> &'static (Fn() -> Box<Sink> + Send +
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-pub fn load_appkey<P: AsRef<Path>>(path: Option<P>) -> Vec<u8> {
|
|
|
- path.map(|path| {
|
|
|
- let mut file = File::open(path).expect("Could not open app key.");
|
|
|
-
|
|
|
- let mut data = Vec::new();
|
|
|
- file.read_to_end(&mut data).unwrap();
|
|
|
-
|
|
|
- data
|
|
|
- }).or_else(|| APPKEY.map(ToOwned::to_owned)).unwrap()
|
|
|
-}
|
|
|
-
|
|
|
pub fn add_session_arguments(opts: &mut getopts::Options) {
|
|
|
opts.optopt("c", "cache", "Path to a directory where files will be cached.", "CACHE")
|
|
|
.reqopt("n", "name", "Device name", "NAME")
|
|
|
.optopt("b", "bitrate", "Bitrate (96, 160 or 320). Defaults to 160", "BITRATE");
|
|
|
-
|
|
|
- if APPKEY.is_none() {
|
|
|
- opts.reqopt("a", "appkey", "Path to a spotify appkey", "APPKEY");
|
|
|
- } else {
|
|
|
- opts.optopt("a", "appkey", "Path to a spotify appkey", "APPKEY");
|
|
|
- };
|
|
|
}
|
|
|
|
|
|
pub fn add_authentication_arguments(opts: &mut getopts::Options) {
|
|
@@ -79,7 +59,6 @@ pub fn create_session(matches: &getopts::Matches) -> Session {
|
|
|
version::commit_date(),
|
|
|
version::short_now());
|
|
|
|
|
|
- let appkey = load_appkey(matches.opt_str("a"));
|
|
|
let name = matches.opt_str("n").unwrap();
|
|
|
let bitrate = match matches.opt_str("b").as_ref().map(String::as_ref) {
|
|
|
None => Bitrate::Bitrate160, // default value
|
|
@@ -98,7 +77,6 @@ pub fn create_session(matches: &getopts::Matches) -> Session {
|
|
|
}).unwrap_or_else(|| Box::new(NoCache) as Box<Cache + Send + Sync>);
|
|
|
|
|
|
let config = Config {
|
|
|
- application_key: appkey,
|
|
|
user_agent: version::version_string(),
|
|
|
device_name: name,
|
|
|
bitrate: bitrate,
|