diff options
| author | krolxon <krolyxon@tutanota.com> | 2024-04-23 19:16:42 +0530 |
|---|---|---|
| committer | krolxon <krolyxon@tutanota.com> | 2024-04-23 19:16:42 +0530 |
| commit | 05c4b17bc078df9c5694e450b72aecbed9fc5216 (patch) | |
| tree | 4058d28fa9dc0fc9ae212758bce0579b858ea213 /src/connection.rs | |
| parent | a0582ead78fda02e4137a82e100963e88362f252 (diff) | |
damn
Diffstat (limited to 'src/connection.rs')
| -rwxr-xr-x | src/connection.rs | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/connection.rs b/src/connection.rs index f2499e6..4f98beb 100755 --- a/src/connection.rs +++ b/src/connection.rs @@ -10,6 +10,7 @@ pub type Error = Box<dyn std::error::Error>; pub struct Connection { pub conn: Client, pub songs_filenames: Vec<String>, + // pub state: String, } impl Connection { @@ -25,6 +26,7 @@ impl Connection { Ok(Self { conn, songs_filenames, + // state: "Stopped".to_string(), }) } @@ -50,14 +52,22 @@ impl Connection { Ok(()) } + // pub fn update_state(&mut self) { + // match self.conn.status().unwrap().state { + // State::Stop => self.state = "Stopped".to_string(), + // State::Play => self.state = "Playing".to_string(), + // State::Pause => self.state = "Paused".to_string(), + // } + // } + pub fn push(&mut self, song: &Song) -> Result<()> { if self.conn.queue().unwrap().is_empty() { self.conn.push(song).unwrap(); self.conn.play().unwrap(); } else { - self.conn.push(song).unwrap(); - if self.conn.status().unwrap().state == State::Stop { - self.conn.play().unwrap(); + self.conn.push(song)?; + if self.conn.status()?.state == State::Stop { + self.conn.play()?; } self.conn.next().unwrap(); } @@ -65,6 +75,19 @@ impl Connection { Ok(()) } + pub fn push_playlist(&mut self, playlist: &str) -> Result<()> { + let songs: Vec<Song> = self.conn.playlist(playlist)?; + + for song in songs { + if self.songs_filenames.contains(&song.file) { + let song = self.get_song_with_only_filename(&song.file); + self.conn.push(&song)?; + self.conn.play()?; + } + } + Ok(()) + } + pub fn get_song_with_only_filename(&self, filename: &str) -> Song { Song { file: filename.to_string(), @@ -81,7 +104,6 @@ impl Connection { pub fn get_current_song(&mut self) -> Option<String> { self.conn.currentsong().unwrap().unwrap_or_default().title - } pub fn status(&mut self) { let current_song = self.conn.currentsong(); @@ -99,6 +121,19 @@ impl Connection { ); } + pub fn now_playing(&mut self) -> Option<String> { + let song = self.conn.currentsong().unwrap().unwrap_or_default(); + if let Some(s) = song.title { + if let Some(a) = song.artist { + Some(format!("{} - {}", s, a)) + } else { + Some(s) + } + } else { + None + } + } + // Playback controls pub fn pause(&mut self) { self.conn.pause(true).unwrap(); |
