Skip to content

Commit 7876f19

Browse files
committed
chore: FMT.
1 parent 980dc5d commit 7876f19

File tree

6 files changed

+36
-30
lines changed

6 files changed

+36
-30
lines changed

player/src/rusty_backend/decoder/mod.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::time::Duration;
66

77
use super::Source;
88

9-
use self::{symphonia::SymphoniaDecoder};
9+
use self::symphonia::SymphoniaDecoder;
1010
use ::symphonia::core::io::{MediaSource, MediaSourceStream};
1111
mod symphonia;
1212

@@ -18,9 +18,7 @@ impl Decoder {
1818
/// Builds a new decoder.
1919
///
2020
/// Attempts to automatically detect the format of the source of data.
21-
pub fn new_decoder(
22-
data: File,
23-
) -> Result<SymphoniaDecoder, DecoderError> {
21+
pub fn new_decoder(data: File) -> Result<SymphoniaDecoder, DecoderError> {
2422
let mss = MediaSourceStream::new(
2523
Box::new(data) as Box<dyn MediaSource>,
2624
::symphonia::core::io::MediaSourceStreamOptions::default(),

player/src/rusty_backend/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ pub use sink::Sink;
2222
pub use source::Source;
2323
pub use stream::{OutputStream, OutputStreamHandle, PlayError, StreamError};
2424

25+
use std::fs::File;
2526
use std::path::Path;
2627
use std::sync::Arc;
2728
use std::time::Duration;
28-
use std::{fs::File};
2929

3030
use self::stream::CpalDeviceExt;
3131

@@ -167,8 +167,7 @@ impl Player {
167167
self.stop(guard);
168168
let file = File::open(path).map_err(PlayError::Io)?;
169169
//println!("{:?}", path);
170-
let decoder =
171-
Decoder::new_decoder(file).map_err(PlayError::DecoderError)?;
170+
let decoder = Decoder::new_decoder(file).map_err(PlayError::DecoderError)?;
172171
self.data.total_duration = decoder.total_duration();
173172
self.sink.append(decoder);
174173
Ok(())
@@ -201,7 +200,7 @@ impl Player {
201200
}
202201
}
203202
pub fn seek_bw(&self) {
204-
let mut new_pos = self.elapsed() as f64 - 5.0;
203+
let mut new_pos = self.elapsed() as f64 - 5.0;
205204
if new_pos < 0.0 {
206205
new_pos = 0.0;
207206
}

player/src/rusty_backend/queue.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,7 @@ where
6161
where
6262
T: Source<Item = S> + Send + 'static,
6363
{
64-
*self.next_sounds
65-
.lock()
66-
.unwrap()
67-
= Some(Box::new(source) as Box<_>);
64+
*self.next_sounds.lock().unwrap() = Some(Box::new(source) as Box<_>);
6865
}
6966

7067
/// Sets whether the queue stays alive if there's no more sound to play.
@@ -188,16 +185,15 @@ where
188185
///
189186
/// This method is separate so that it is not inlined.
190187
fn go_next(&mut self) -> Result<(), ()> {
191-
192188
let next = {
193189
let mut next = self.input.next_sounds.lock().unwrap();
194190

195191
if next.is_none() {
196192
if self.input.keep_alive_if_empty.load(Ordering::Acquire) {
197193
// Play a short silence in order to avoid spinlocking.
198194
let silence = Zero::<S>::new(1, 44100); // TODO: meh
199-
200-
Box::new(silence.take_duration(Duration::from_millis(10))) as Box<_>
195+
196+
Box::new(silence.take_duration(Duration::from_millis(10))) as Box<_>
201197
} else {
202198
return Err(());
203199
}

player/src/rusty_backend/sink.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,17 @@ impl Sink {
8787
}
8888
}
8989
elapsed.store(src.elapsed().as_secs() as u32, Ordering::Relaxed);
90-
src.inner_mut().set_factor(controls.volume.load(Ordering::Relaxed));
90+
src.inner_mut()
91+
.set_factor(controls.volume.load(Ordering::Relaxed));
9192
src.inner_mut()
9293
.inner_mut()
9394
.set_paused(controls.pause.load(Ordering::Relaxed));
9495
}
9596
})
9697
.convert_samples::<f32>();
9798
self.sound_playing.store(true, Ordering::Relaxed);
98-
self.queue_tx.append(Done::new(source, self.sound_playing.clone()));
99+
self.queue_tx
100+
.append(Done::new(source, self.sound_playing.clone()));
99101
}
100102

101103
/// Gets the volume of the sound.

player/src/rusty_backend/stream.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl OutputStreamHandle {
8282
}
8383

8484
/// Plays a sound once. Returns a `Sink` that can be used to control the sound.
85-
pub fn play_once<R>(&self, input:std::fs::File ) -> Result<Sink, PlayError>
85+
pub fn play_once<R>(&self, input: std::fs::File) -> Result<Sink, PlayError>
8686
where
8787
R: Read + Seek + Send + Sync + 'static,
8888
{

ytpapi2/src/lib.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::{
2-
path::Path, string::FromUtf8Error, time::{SystemTime, UNIX_EPOCH}
2+
path::Path,
3+
string::FromUtf8Error,
4+
time::{SystemTime, UNIX_EPOCH},
35
};
46

57
use json_extractor::{
@@ -48,20 +50,22 @@ fn get_headers() -> HeaderMap {
4850
}
4951

5052
#[cfg(test)]
51-
fn get_account_id() -> Option<String>{
53+
fn get_account_id() -> Option<String> {
5254
let file = std::fs::read_to_string("../account_id.txt").unwrap();
5355
let account_id = match std::fs::read_to_string(file) {
5456
Ok(id) => Some(id),
5557
Err(_) => None,
5658
};
57-
return account_id;
59+
return account_id;
5860
}
5961

6062
#[test]
6163
fn advanced_like() {
6264
use tokio::runtime::Runtime;
6365
Runtime::new().unwrap().block_on(async {
64-
let ytm = YoutubeMusicInstance::new(get_headers(), get_account_id()).await.unwrap();
66+
let ytm = YoutubeMusicInstance::new(get_headers(), get_account_id())
67+
.await
68+
.unwrap();
6569
println!("{}", ytm.compute_sapi_hash());
6670
let search = ytm
6771
.get_library(&Endpoint::MusicLibraryLanding, 0)
@@ -77,7 +81,9 @@ fn advanced_like() {
7781
fn advanced_test() {
7882
use tokio::runtime::Runtime;
7983
Runtime::new().unwrap().block_on(async {
80-
let ytm = YoutubeMusicInstance::new(get_headers(), get_account_id()).await.unwrap();
84+
let ytm = YoutubeMusicInstance::new(get_headers(), get_account_id())
85+
.await
86+
.unwrap();
8187
let search = ytm.search("j'ai la danse qui va avec", 0).await.unwrap();
8288
assert_eq!(search.videos.is_empty(), false);
8389
assert_eq!(search.playlists.is_empty(), false);
@@ -90,7 +96,9 @@ fn advanced_test() {
9096
fn home_test() {
9197
use tokio::runtime::Runtime;
9298
Runtime::new().unwrap().block_on(async {
93-
let ytm = YoutubeMusicInstance::new(get_headers(), get_account_id()).await.unwrap();
99+
let ytm = YoutubeMusicInstance::new(get_headers(), get_account_id())
100+
.await
101+
.unwrap();
94102
let search = ytm.get_home(0).await.unwrap();
95103
println!("{:?}", search.playlists);
96104
assert_eq!(search.playlists.is_empty(), false);
@@ -111,7 +119,7 @@ pub struct YoutubeMusicInstance {
111119
innertube_api_key: String,
112120
client_version: String,
113121
cookies: String,
114-
account_id: Option<String>
122+
account_id: Option<String>,
115123
}
116124

117125
impl YoutubeMusicInstance {
@@ -148,7 +156,10 @@ impl YoutubeMusicInstance {
148156
.unwrap(),
149157
);
150158
}
151-
let account_path = path.parent().unwrap_or(Path::new("../")).join("account_id.txt");
159+
let account_path = path
160+
.parent()
161+
.unwrap_or(Path::new("../"))
162+
.join("account_id.txt");
152163
let account_id = match tokio::fs::read_to_string(account_path).await {
153164
Ok(mut id) => {
154165
if id.ends_with("\n") {
@@ -158,7 +169,7 @@ impl YoutubeMusicInstance {
158169
}
159170
}
160171
Some(id)
161-
},
172+
}
162173
Err(_) => None, //don't care if there is no files or nothing in the file
163174
};
164175
Self::new(headers, account_id).await
@@ -217,7 +228,7 @@ impl YoutubeMusicInstance {
217228
innertube_api_key: innertube_api_key.to_string(),
218229
client_version: client_version.to_string(),
219230
cookies,
220-
account_id
231+
account_id,
221232
})
222233
}
223234
fn compute_sapi_hash(&self) -> String {
@@ -281,7 +292,7 @@ impl YoutubeMusicInstance {
281292
None => format!(
282293
r#"{{"context":{{"client":{{"clientName":"WEB_REMIX","clientVersion":"{}"}}}}}}"#,
283294
self.client_version
284-
)
295+
),
285296
};
286297
reqwest::Client::new()
287298
.post(&url)
@@ -319,7 +330,7 @@ impl YoutubeMusicInstance {
319330
None => format!(
320331
r#"{{"context":{{"client":{{"clientName":"WEB_REMIX","clientVersion":"{}"}}}},"{endpoint_key}":"{endpoint_param}"}}"#,
321332
self.client_version
322-
)
333+
),
323334
};
324335
reqwest::Client::new()
325336
.post(&url)

0 commit comments

Comments
 (0)