From 59eed99c85957c193dba53e7311f960a6b8e916c Mon Sep 17 00:00:00 2001 From: krolxon Date: Fri, 26 Apr 2024 23:10:08 +0530 Subject: add to playlist feature --- src/connection.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/connection.rs') 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 = core::result::Result; pub type Error = Box; @@ -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 { + let list = self + .songs_filenames + .iter() + .map(|f| f.as_str()) + .collect::>(); + 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(); -- cgit v1.2.3