aboutsummaryrefslogtreecommitdiff
path: root/src/connection.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/connection.rs')
-rwxr-xr-xsrc/connection.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/connection.rs b/src/connection.rs
index b84d429..51444dd 100755
--- a/src/connection.rs
+++ b/src/connection.rs
@@ -4,6 +4,8 @@ use simple_dmenu::dmenu;
use std::process::Command;
use std::time::Duration;
+use crate::app::AppResult;
+
pub type Result<T> = core::result::Result<T, Error>;
pub type Error = Box<dyn std::error::Error>;
@@ -143,6 +145,12 @@ impl Connection {
Ok(())
}
+ /// Add given song to playlist
+ pub fn add_to_playlist(&mut self, playlist: &str, song: &Song) -> Result<()> {
+ self.conn.pl_push(playlist, song)?;
+ Ok(())
+ }
+
/// Given a filename, get instance of Song with only filename
pub fn get_song_with_only_filename(&self, filename: &str) -> Song {
Song {
@@ -158,6 +166,21 @@ impl Connection {
}
}
+ /// Given a song name from a directory, it returns the full path of the song in the database
+ pub fn get_full_path(&self, short_path: &str) -> AppResult<String> {
+ let list = self
+ .songs_filenames
+ .iter()
+ .map(|f| f.as_str())
+ .collect::<Vec<&str>>();
+ let (filename, _) = rust_fuzzy_search::fuzzy_search_sorted(&short_path, &list)
+ .get(0)
+ .unwrap()
+ .clone();
+
+ Ok(filename.to_string())
+ }
+
/// Print status to stdout
pub fn status(&mut self) {
let current_song = self.conn.currentsong();