diff --git a/README.md b/README.md index adc310c..cc9f678 100644 --- a/README.md +++ b/README.md @@ -115,6 +115,7 @@ are supported: * `previous`/`next`: Play previous/next track * `clear`: Clear playlist * `share [current | selected]`: Copies a sharable URL of either the selected item or the currernt song to the system clipboard +* `newplaylist `: Create new playlist with name `` The screens can be opened with `queue`, `search`, `playlists` and `log`, whereas `search` can be supplied with a search term that will be entered after opening diff --git a/src/command.rs b/src/command.rs index 0390442..e51324a 100644 --- a/src/command.rs +++ b/src/command.rs @@ -115,6 +115,7 @@ pub enum Command { ReloadConfig, Noop, Insert(Option), + NewPlaylist(String), } impl fmt::Display for Command { @@ -171,6 +172,7 @@ impl fmt::Display for Command { Command::Help => "help".to_string(), Command::ReloadConfig => "reload".to_string(), Command::Insert(_) => "insert".to_string(), + Command::NewPlaylist(name) => format!("new playlist {}", name), }; write!(f, "{}", repr) } @@ -360,6 +362,13 @@ pub fn parse(input: &str) -> Option { .map(|url| Command::Insert(Some((*url).to_string()))) } } + "newplaylist" => { + if !args.is_empty() { + Some(Command::NewPlaylist(args.join(" "))) + } else { + None + } + } "noop" => Some(Command::Noop), _ => None, } diff --git a/src/commands.rs b/src/commands.rs index edac43c..09c3fb3 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -184,6 +184,13 @@ impl CommandManager { self.register_keybindings(s); Ok(None) } + Command::NewPlaylist(name) => { + match self.spotify.create_playlist(name, None, None) { + Some(_) => self.library.update_library(), + None => error!("could not create playlist {}", name), + } + Ok(None) + } Command::Search(_) | Command::Jump(_) | Command::Move(_, _)