diff options
author | Rasmus Steinke <rasi@xssn.at> | 2017-09-30 13:24:03 +0200 |
---|---|---|
committer | Rasmus Steinke <rasi@xssn.at> | 2017-09-30 13:24:03 +0200 |
commit | 18fa104cd547395a5ae137d298c30dbbfe5d7331 (patch) | |
tree | 2c04362891e78f5660738e5272556733610a1375 | |
parent | 6736d8c0f6b29c7cd0522f89b21035415cfb860d (diff) | |
download | perl-app-clerk-18fa104cd547395a5ae137d298c30dbbfe5d7331.tar.gz perl-app-clerk-18fa104cd547395a5ae137d298c30dbbfe5d7331.tar.xz |
add track rating support
-rwxr-xr-x | clerk | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -7,7 +7,7 @@ use strict; use utf8; use Config::Simple; use Data::MessagePack; -#use DDP; +use DDP; use Encode qw(decode encode); use File::Basename; use File::Path qw(make_path); @@ -449,17 +449,22 @@ sub ask_to_pick_settings { return backend_call([map { $_ . "\n" } qw/5 10 15 20 25 30/]); } +sub ask_to_pick_ratings { + return backend_call([map { $_ . "\n" } qw/1 2 3 4 5 6 7 8 9 10/]); +} + sub action_db_entries { my ($out) = @_; my @sel = util_parse_selection($out); - my $action = backend_call(["Add\n", "Replace\n"]); + my $action = backend_call(["Add\n", "Replace\n", "---\n", "Rate\n"]); mpd_reachable(); { local $_ = $action; if (/^Add/) { mpd_add_items(\@sel) } elsif (/^Replace/) { mpd_replace_with_items(\@sel) } + elsif (/^Rate/) { mpd_rate_with_items(\@sel) } } } @@ -511,12 +516,23 @@ sub mpd_add_items { $mpd->add($_) for @{$_[0]}; } +sub mpd_rate_items { + my $rating = @_[1]; + chomp $rating; + $mpd->sticker_value("song", "$_", "rating", "$rating") for @{$_[0]}; +} + sub mpd_replace_with_items { $mpd->clear; mpd_add_items(@_); $mpd->play; } +sub mpd_rate_with_items { + my $rating = ask_to_pick_ratings(); + mpd_rate_items(@_, $rating); +} + sub mpd_save_cur_playlist { tzset(); $mpd->save(scalar localtime); |