feat: create new empty playlist via command (#272)

* feat: create new empty playlist via command

- type :newplaylist <name> to create a new playlist

fixes #242

* use full argument string for playlist name

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
This commit is contained in:
Bolli
2020-10-25 17:57:49 +01:00
committed by GitHub
parent 5fb4eb7af2
commit d88ea93a94
3 changed files with 17 additions and 0 deletions

View File

@@ -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 <name>`: Create new playlist with name `<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

View File

@@ -115,6 +115,7 @@ pub enum Command {
ReloadConfig,
Noop,
Insert(Option<String>),
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<Command> {
.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,
}

View File

@@ -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(_, _)