diff --git a/audio/src/fetch.rs b/audio/src/fetch.rs index a7f80902..ef68ed87 100644 --- a/audio/src/fetch.rs +++ b/audio/src/fetch.rs @@ -446,7 +446,7 @@ impl AudioFile { channel_tx: None, stream_shared: None, file_size: file.metadata().unwrap().len() as usize, - } + }; } } } @@ -514,7 +514,10 @@ impl AudioFileFetchDataReceiver { request_length: usize, request_sent_time: Instant, ) -> AudioFileFetchDataReceiver { - let measure_ping_time = shared.number_of_open_requests.load(atomic::Ordering::SeqCst) == 0; + let measure_ping_time = shared + .number_of_open_requests + .load(atomic::Ordering::SeqCst) + == 0; shared .number_of_open_requests @@ -562,7 +565,8 @@ impl Future for AudioFileFetchDataReceiver { if let Some(request_sent_time) = self.request_sent_time { let duration = Instant::now() - request_sent_time; let duration_ms: u64; - if 0.001 * (duration.as_millis() as f64) > MAXIMUM_ASSUMED_PING_TIME_SECONDS + if 0.001 * (duration.as_millis() as f64) + > MAXIMUM_ASSUMED_PING_TIME_SECONDS { duration_ms = (MAXIMUM_ASSUMED_PING_TIME_SECONDS * 1000.0) as u64; } else { @@ -714,8 +718,13 @@ impl AudioFileFetch { ranges_to_request.subtract_range_set(&download_status.requested); for range in ranges_to_request.iter() { - let (_headers, data) = - request_range(&self.session, self.shared.file_id, range.start, range.length).split(); + let (_headers, data) = request_range( + &self.session, + self.shared.file_id, + range.start, + range.length, + ) + .split(); download_status.requested.add_range(range); @@ -749,7 +758,10 @@ impl AudioFileFetch { // download data from after the current read position first let mut tail_end = RangeSet::new(); let read_position = self.shared.read_position.load(atomic::Ordering::Relaxed); - tail_end.add_range(&Range::new(read_position, self.shared.file_size - read_position)); + tail_end.add_range(&Range::new( + read_position, + self.shared.file_size - read_position, + )); let tail_end = tail_end.intersection(&missing_data); if !tail_end.is_empty() { @@ -794,8 +806,9 @@ impl AudioFileFetch { let ping_time_ms: usize = match self.network_response_times_ms.len() { 1 => self.network_response_times_ms[0] as usize, 2 => { - ((self.network_response_times_ms[0] + self.network_response_times_ms[1]) / 2) - as usize + ((self.network_response_times_ms[0] + + self.network_response_times_ms[1]) + / 2) as usize } 3 => { let mut times = self.network_response_times_ms.clone(); @@ -863,10 +876,12 @@ impl AudioFileFetch { self.download_range(request.start, request.length); } Ok(Async::Ready(Some(StreamLoaderCommand::RandomAccessMode()))) => { - *(self.shared.download_strategy.lock().unwrap()) = DownloadStrategy::RandomAccess(); + *(self.shared.download_strategy.lock().unwrap()) = + DownloadStrategy::RandomAccess(); } Ok(Async::Ready(Some(StreamLoaderCommand::StreamMode()))) => { - *(self.shared.download_strategy.lock().unwrap()) = DownloadStrategy::Streaming(); + *(self.shared.download_strategy.lock().unwrap()) = + DownloadStrategy::Streaming(); } Ok(Async::Ready(Some(StreamLoaderCommand::Close()))) => { return Ok(Async::Ready(())); @@ -908,15 +923,20 @@ impl Future for AudioFileFetch { } if let DownloadStrategy::Streaming() = self.get_download_strategy() { - let number_of_open_requests = - self.shared.number_of_open_requests.load(atomic::Ordering::SeqCst); + let number_of_open_requests = self + .shared + .number_of_open_requests + .load(atomic::Ordering::SeqCst); let max_requests_to_send = MAX_PREFETCH_REQUESTS - min(MAX_PREFETCH_REQUESTS, number_of_open_requests); if max_requests_to_send > 0 { let bytes_pending: usize = { let download_status = self.shared.download_status.lock().unwrap(); - download_status.requested.minus(&download_status.downloaded).len() + download_status + .requested + .minus(&download_status.downloaded) + .len() }; let ping_time_seconds = @@ -924,9 +944,11 @@ impl Future for AudioFileFetch { let download_rate = self.session.channel().get_download_rate_estimate(); let desired_pending_bytes = max( - (PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * self.shared.stream_data_rate as f64) + (PREFETCH_THRESHOLD_FACTOR + * ping_time_seconds + * self.shared.stream_data_rate as f64) as usize, + (FAST_PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * download_rate as f64) as usize, - (FAST_PREFETCH_THRESHOLD_FACTOR * ping_time_seconds * download_rate as f64) as usize, ); if bytes_pending < desired_pending_bytes { @@ -1003,7 +1025,9 @@ impl Read for AudioFileStreaming { .unwrap() .0; } - let available_length = download_status.downloaded.contained_length_from_value(offset); + let available_length = download_status + .downloaded + .contained_length_from_value(offset); assert!(available_length > 0); drop(download_status); diff --git a/audio/src/range_set.rs b/audio/src/range_set.rs index 448c0971..44955388 100644 --- a/audio/src/range_set.rs +++ b/audio/src/range_set.rs @@ -113,7 +113,8 @@ impl RangeSet { // the new range starts after anything we already passed and ends before the next range starts (they don't touch) -> insert it. self.ranges.insert(index, range.clone()); return; - } else if range.start <= self.ranges[index].end() && self.ranges[index].start <= range.end() + } else if range.start <= self.ranges[index].end() + && self.ranges[index].start <= range.end() { // the new range overlaps (or touches) the first range. They are to be merged. // In addition we might have to merge further ranges in as well. @@ -161,7 +162,9 @@ impl RangeSet { if range.end() <= self.ranges[index].start { // the remaining ranges are past the one to subtract. -> we're done. return; - } else if range.start <= self.ranges[index].start && self.ranges[index].start < range.end() { + } else if range.start <= self.ranges[index].start + && self.ranges[index].start < range.end() + { // the range to subtract started before the current range and reaches into the current range // -> we have to remove the beginning of the range or the entire range and do the same for following ranges. @@ -223,8 +226,14 @@ impl RangeSet { other_index += 1; } else { // the two intervals overlap. Add the union and advance the index of the one that ends first. - let new_start = max(self.ranges[self_index].start, other.ranges[other_index].start); - let new_end = min(self.ranges[self_index].end(), other.ranges[other_index].end()); + let new_start = max( + self.ranges[self_index].start, + other.ranges[other_index].start, + ); + let new_end = min( + self.ranges[self_index].end(), + other.ranges[other_index].end(), + ); assert!(new_start <= new_end); result.add_range(&Range::new(new_start, new_end - new_start)); if self.ranges[self_index].end() <= other.ranges[other_index].end() { diff --git a/connect/src/spirc.rs b/connect/src/spirc.rs index 29e6b1d8..ea24f6b8 100644 --- a/connect/src/spirc.rs +++ b/connect/src/spirc.rs @@ -796,12 +796,19 @@ impl SpircTask { self.resolve_uri(&radio_uri) } - fn resolve_autoplay_uri(&self, uri: &str) -> Box> { + fn resolve_autoplay_uri( + &self, + uri: &str, + ) -> Box> { let query_uri = format!("hm://autoplay-enabled/query?uri={}", uri); let request = self.session.mercury().get(query_uri); Box::new(request.and_then(move |response| { if response.status_code == 200 { - let data = response.payload.first().expect("Empty autoplay uri").to_vec(); + let data = response + .payload + .first() + .expect("Empty autoplay uri") + .to_vec(); let autoplay_uri = String::from_utf8(data).unwrap(); Ok(autoplay_uri) } else { @@ -811,7 +818,10 @@ impl SpircTask { })) } - fn resolve_uri(&self, uri: &str) -> Box> { + fn resolve_uri( + &self, + uri: &str, + ) -> Box> { let request = self.session.mercury().get(uri); Box::new(request.and_then(move |response| { @@ -900,7 +910,8 @@ impl SpircTask { let track = { let mut track_ref = self.state.get_track()[index as usize].clone(); let mut track_id = self.get_spotify_id_for_track(&track_ref); - while track_id.is_err() || track_id.unwrap().audio_type == SpotifyAudioType::NonPlayable { + while track_id.is_err() || track_id.unwrap().audio_type == SpotifyAudioType::NonPlayable + { warn!( "Skipping track <{:?}> at position [{}] of {}", track_ref.get_uri(), diff --git a/core/src/proxytunnel.rs b/core/src/proxytunnel.rs index 2b9df5a8..ea84bc88 100644 --- a/core/src/proxytunnel.rs +++ b/core/src/proxytunnel.rs @@ -58,7 +58,7 @@ impl Future for ProxyTunnel { let status = match response.parse(&buf) { Ok(status) => status, Err(err) => { - return Err(io::Error::new(io::ErrorKind::Other, err.description())) + return Err(io::Error::new(io::ErrorKind::Other, err.description())); } }; diff --git a/examples/playlist_tracks.rs b/examples/playlist_tracks.rs index 3e4202d5..fc288d18 100644 --- a/examples/playlist_tracks.rs +++ b/examples/playlist_tracks.rs @@ -1,4 +1,3 @@ - use env_logger; use std::env; use tokio_core::reactor::Core; @@ -7,7 +6,7 @@ use librespot::core::authentication::Credentials; use librespot::core::config::SessionConfig; use librespot::core::session::Session; use librespot::core::spotify_id::SpotifyId; -use librespot::metadata::{Metadata, Track, Playlist}; +use librespot::metadata::{Metadata, Playlist, Track}; fn main() { env_logger::init(); @@ -26,16 +25,16 @@ fn main() { let uri_split = args[3].split(":"); let uri_parts: Vec<&str> = uri_split.collect(); - println!("{}, {}, {}",uri_parts[0], uri_parts[1], uri_parts[2]); - + println!("{}, {}, {}", uri_parts[0], uri_parts[1], uri_parts[2]); + let plist_uri = SpotifyId::from_base62(uri_parts[2]).unwrap(); - + let session = core .run(Session::connect(session_config, credentials, None, handle)) .unwrap(); let plist = core.run(Playlist::get(&session, plist_uri)).unwrap(); - println!("{:?}",plist); + println!("{:?}", plist); for track_id in plist.tracks { let plist_track = core.run(Track::get(&session, track_id)).unwrap(); println!("track: {} ", plist_track.name); diff --git a/metadata/src/lib.rs b/metadata/src/lib.rs index 6ba32f4d..d4bd797c 100644 --- a/metadata/src/lib.rs +++ b/metadata/src/lib.rs @@ -301,7 +301,6 @@ impl Metadata for Playlist { } fn parse(msg: &Self::Message, _: &Session) -> Self { - let tracks = msg .get_contents() .get_items() @@ -312,9 +311,13 @@ impl Metadata for Playlist { SpotifyId::from_base62(uri_parts[2]).unwrap() }) .collect::>(); - + if tracks.len() != msg.get_length() as usize { - warn!("Got {} tracks, but the playlist should contain {} tracks.", tracks.len(), msg.get_length()); + warn!( + "Got {} tracks, but the playlist should contain {} tracks.", + tracks.len(), + msg.get_length() + ); } Playlist { diff --git a/playback/src/player.rs b/playback/src/player.rs index eab8f43e..ba61471f 100644 --- a/playback/src/player.rs +++ b/playback/src/player.rs @@ -525,7 +525,10 @@ impl PlayerInternal { if let Some(stream_loader_controller) = self.state.stream_loader_controller() { stream_loader_controller.set_stream_mode(); } - if let PlayerState::Playing { bytes_per_second, .. } = self.state { + if let PlayerState::Playing { + bytes_per_second, .. + } = self.state + { if let Some(stream_loader_controller) = self.state.stream_loader_controller() { // Request our read ahead range let request_data_length = max( @@ -599,7 +602,10 @@ impl PlayerInternal { .iter() .map(|alt_id| AudioItem::get_audio_item(&self.session, *alt_id)); let alternatives = future::join_all(alternatives).wait().unwrap(); - alternatives.into_iter().find(|alt| alt.available).map(Cow::Owned) + alternatives + .into_iter() + .find(|alt| alt.available) + .map(Cow::Owned) } else { None } @@ -677,8 +683,12 @@ impl PlayerInternal { let play_from_beginning = position == 0; let key = self.session.audio_key().request(spotify_id, file_id); - let encrypted_file = - AudioFile::open(&self.session, file_id, bytes_per_second, play_from_beginning); + let encrypted_file = AudioFile::open( + &self.session, + file_id, + bytes_per_second, + play_from_beginning, + ); let encrypted_file = encrypted_file.wait().unwrap(); diff --git a/protocol/build.rs b/protocol/build.rs index 3b632f65..3ea25e75 100644 --- a/protocol/build.rs +++ b/protocol/build.rs @@ -23,10 +23,9 @@ fn main() { let name; if line.starts_with("pub mod ") { - name = &line[8..len-1]; // Remove keywords and semi-colon - } - else { - name = &line[4..len-1]; // Remove keywords and semi-colon + name = &line[8..len - 1]; // Remove keywords and semi-colon + } else { + name = &line[4..len - 1]; // Remove keywords and semi-colon } // Build the paths to relevant files. diff --git a/src/main.rs b/src/main.rs index 52452d44..f94a2ef8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use futures::sync::mpsc::UnboundedReceiver; use futures::{Async, Future, Poll, Stream}; -use sha1::{Digest, Sha1}; use log::{error, info, trace, warn}; +use sha1::{Digest, Sha1}; use std::env; use std::io::{self, stderr, Write}; use std::mem; diff --git a/src/player_event_handler.rs b/src/player_event_handler.rs index a4ef4daf..03bae147 100644 --- a/src/player_event_handler.rs +++ b/src/player_event_handler.rs @@ -1,5 +1,5 @@ -use log::info; use librespot::playback::player::PlayerEvent; +use log::info; use std::collections::HashMap; use std::io; use std::process::Command;