diff --git a/src/audio_file.rs b/src/audio_file.rs index 630344c0..09fd7822 100644 --- a/src/audio_file.rs +++ b/src/audio_file.rs @@ -219,7 +219,7 @@ impl AudioFileManager { pub fn cache_dir(session: &Session, file_id: FileId) -> PathBuf { let name = file_id.to_base16(); - session.0.config.cache_location.join(&name[0..2]) + session.config().cache_location.join(&name[0..2]) } pub fn cache_path(session: &Session, file_id: FileId) -> PathBuf { diff --git a/src/authentication.rs b/src/authentication.rs index f927850b..6007e162 100644 --- a/src/authentication.rs +++ b/src/authentication.rs @@ -55,14 +55,14 @@ impl Session { cpu_family: protocol::authentication::CpuFamily::CPU_UNKNOWN, os: protocol::authentication::Os::OS_UNKNOWN, system_information_string: "librespot".to_owned(), - device_id: self.0.data.read().unwrap().device_id.clone() + device_id: self.device_id().clone() }, version_string: util::version::version_string(), appkey => { - version: self.0.config.application_key[0] as u32, - devkey: self.0.config.application_key[0x1..0x81].to_vec(), - signature: self.0.config.application_key[0x81..0x141].to_vec(), - useragent: self.0.config.user_agent.clone(), + version: self.config().application_key[0] as u32, + devkey: self.config().application_key[0x1..0x81].to_vec(), + signature: self.config().application_key[0x81..0x141].to_vec(), + useragent: self.config().user_agent.clone(), callback_hash: vec![0; 20], } }); @@ -106,7 +106,7 @@ impl Session { let secret = { let mut data = [0u8; 20]; let mut h = crypto::sha1::Sha1::new(); - h.input(&self.0.data.read().unwrap().device_id.as_bytes()); + h.input(&self.device_id().as_bytes()); h.result(&mut data); data }; diff --git a/src/discovery.rs b/src/discovery.rs index 3449245d..46564eb5 100644 --- a/src/discovery.rs +++ b/src/discovery.rs @@ -42,8 +42,8 @@ impl DiscoveryManager { "statusString": "ERROR-OK", "spotifyError": 0, "version": "2.1.0", - "deviceID": (self.session.0.data.read().unwrap().device_id), - "remoteName": (self.session.0.config.device_name), + "deviceID": (self.session.device_id()), + "remoteName": (self.session.config().device_name), "activeUser": "", "publicKey": (public_key), "deviceType": "UNKNOWN", @@ -118,7 +118,7 @@ impl DiscoveryManager { pub fn run(&mut self) { let server = Server::http("0.0.0.0:8000").unwrap(); - let svc = DNSService::register(Some(&self.session.0.config.device_name), + let svc = DNSService::register(Some(&self.session.config().device_name), "_spotify-connect._tcp", None, None, diff --git a/src/metadata.rs b/src/metadata.rs index 4996e27e..d4a5ddfd 100644 --- a/src/metadata.rs +++ b/src/metadata.rs @@ -71,7 +71,7 @@ impl MetadataTrait for Track { } fn parse(msg: &Self::Message, session: &Session) -> Self { - let country = session.0.data.read().unwrap().country.clone(); + let country = session.country(); let artists = msg.get_artist() .iter() @@ -157,7 +157,7 @@ impl MetadataTrait for Artist { } fn parse(msg: &Self::Message, session: &Session) -> Self { - let country = session.0.data.read().unwrap().country.clone(); + let country = session.country(); let top_tracks = msg.get_top_track() .iter() diff --git a/src/player.rs b/src/player.rs index 17078475..da97fdf8 100644 --- a/src/player.rs +++ b/src/player.rs @@ -168,7 +168,7 @@ impl PlayerInternal { .unwrap(); } - let format = match self.session.0.config.bitrate { + let format = match self.session.config().bitrate { Bitrate::Bitrate96 => FileFormat::OGG_VORBIS_96, Bitrate::Bitrate160 => FileFormat::OGG_VORBIS_160, Bitrate::Bitrate320 => FileFormat::OGG_VORBIS_320, diff --git a/src/session.rs b/src/session.rs index 27d0e616..ba1858ed 100644 --- a/src/session.rs +++ b/src/session.rs @@ -43,7 +43,7 @@ pub struct SessionData { } pub struct SessionInternal { - pub config: Config, + config: Config, pub data: RwLock, mercury: Mutex, @@ -224,4 +224,20 @@ impl Session { pub fn mercury_sub(&self, uri: String) -> mpsc::Receiver { self.0.mercury.lock().unwrap().subscribe(self, uri) } + + pub fn config(&self) -> &Config { + &self.0.config + } + + pub fn username(&self) -> String { + self.0.data.read().unwrap().canonical_username.clone() + } + + pub fn country(&self) -> String { + self.0.data.read().unwrap().country.clone() + } + + pub fn device_id(&self) -> String { + self.0.data.read().unwrap().device_id.clone() + } } diff --git a/src/spirc.rs b/src/spirc.rs index 7f1c72d2..f6ef8d9b 100644 --- a/src/spirc.rs +++ b/src/spirc.rs @@ -41,8 +41,8 @@ struct SpircInternal { impl SpircManager { pub fn new(session: Session, player: Player) -> SpircManager { - let ident = session.0.data.read().unwrap().device_id.clone(); - let name = session.0.config.device_name.clone(); + let ident = session.device_id(); + let name = session.config().device_name.clone(); SpircManager(Arc::new(Mutex::new(SpircInternal { player: player, @@ -350,7 +350,6 @@ impl SpircInternal { } fn uri(&self) -> String { - format!("hm://remote/user/{}", - self.session.0.data.read().unwrap().canonical_username.clone()) + format!("hm://remote/user/{}", self.session.username()) } }