diff options
author | Rasmus Steinke <rasi@xssn.at> | 2017-09-20 21:10:41 +0200 |
---|---|---|
committer | Rasmus Steinke <rasi@xssn.at> | 2017-09-20 21:10:41 +0200 |
commit | ecbff20c398724fa32b191b6d34634a940e047ef (patch) | |
tree | c9d86dd0102a8d37e0a512c71920e179c518905b /clerk | |
parent | 4bb0b52dbb4e00adad7e5c67215383df5f000d6b (diff) | |
download | perl-app-clerk-ecbff20c398724fa32b191b6d34634a940e047ef.tar.gz perl-app-clerk-ecbff20c398724fa32b191b6d34634a940e047ef.tar.xz |
add possibility to add rated songs in random dialog
Diffstat (limited to 'clerk')
-rwxr-xr-x | clerk | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -17,6 +17,7 @@ use File::stat; use Try::Tiny; use FindBin '$Bin'; use FindBin '$Script'; +use List::Util qw(min); use Getopt::Std; use HTTP::Date; use IPC::Run qw( timeout start ); @@ -204,7 +205,7 @@ sub backend_call { "--bind=esc:$random,alt-a:toggle-all,alt-n:deselect-all", "--with-nth=$fields" ], - rofi => [ "rofi", "-width", "1800", "-matching", "regex", "-dmenu", "-kb-row-tab", "", "-kb-move-word-forward", "", "-kb-accept-alt", "Tab", "-multi-select", "-no-levensthein-sort", "-i", "-p", "> " , "-filter", $minimal ] + rofi => [ "rofi", "-width", "2400", "-lines", "40", "-matching", "regex", "-dmenu", "-kb-row-tab", "", "-kb-move-word-forward", "", "-kb-accept-alt", "Tab", "-multi-select", "-no-levensthein-sort", "-i", "-p", "> " , "-filter", $minimal ] ); my $handle = start $backends{$backend} // die('backend not found'), \$input, \$out; $input = join "", (@{$in}); @@ -264,7 +265,7 @@ sub random { my @queue_cmd = ('tmux', 'findw', '-t', 'music', 'queue'); try { $mpd->close(); }; $mpd->{socket}->close; - my @action_items = ("Album\n", "Tracks\n", "Settings\n"); + my @action_items = ("Album\n", "Tracks\n", "Rated Tracks\n", "Settings\n"); my $action = backend_call(\@action_items, "1,2,3", "cancel"); if ($action eq "Album\n") { random_album(); @@ -276,6 +277,16 @@ sub random { system(@queue_cmd); $mpd->play(); } + if ($action eq "Rated Tracks\n") { + my @result; + my @action_items = ("1\n", "2\n", "3\n", "4\n", "5\n", "6\n", "7\n", "8\n", "9\n", "10\n"); + my $minimal_rating = backend_call(\@action_items, "1,2,3", "cancel"); + chomp $minimal_rating; + $minimal = "$minimal_rating"; + my $rdb = unpack_msgpack(); + my @rating_rdb = grep { ($_->{rating} // 0) >= $minimal } @$rdb; + $mpd->add($_->{uri}) for (splice(@rating_rdb, -min($#rating_rdb, $songs))); + } if ($action eq "Settings\n") { my @action_items = ("5\n", "10\n", "15\n", "20\n", "25\n", "30\n"); my $action = backend_call(\@action_items); @@ -413,7 +424,7 @@ sub formatted_tracks { sub formatted_rating { my ($rdb) = @_; - my @rating_rdb = grep { ($_->{rating} // 0) > $minimal } @$rdb; + my @rating_rdb = grep { ($_->{rating} // 0) >= $minimal } @$rdb; $minimal = ""; my $fmtstr = join "", map {"%-${_}.${_}s\t"} ($track_l, $title_l, $artist_l, $date_l, $album_l, $rating_l); my @tracks = map { |