From d9dde458c07d3b2f32356692eea4fd353b2b6c79 Mon Sep 17 00:00:00 2001 From: Rasmus Steinke Date: Thu, 3 Aug 2017 20:44:39 +0200 Subject: unify adding of tracks for both album and track --- clerk.pl | 56 +++++++++++++++++++++++--------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) mode change 100644 => 100755 clerk.pl (limited to 'clerk.pl') diff --git a/clerk.pl b/clerk.pl old mode 100644 new mode 100755 index d54d815..b77dd9c --- a/clerk.pl +++ b/clerk.pl @@ -125,6 +125,17 @@ sub unpack_msgpack { return $rdb; } +sub do_action { + my $input; + my ($in, $action) = @_; + foreach my $line (split /\n/, $in) { + print "${line}x\n"; + my $uri = (split /[\t\n]/, $line)[-1]; + print "${uri}x\n"; + $mpd->add($uri); + } +} + # read messagepack file and output strings sub list_albums { my ($rdb) = @_; @@ -145,24 +156,13 @@ sub list_albums { my $out = backend_call(\@output, "1,2,3"); print $out; # call rofi function to display possible actions - my @action_items = ("Add\n", "Insert\n", "Replace\n"); + my @action_items = ("Add\n", "Replace\n"); my $action = backend_call(\@action_items); - - # split output into tag variables and remove possible whitespace - if ($action eq "Add\n") { - my $line; - foreach my $line (split /\n/, $out) { - my $uri = (split /[\t\n]/, $line)[-1]; - $mpd->add($uri); - } - } - elsif ($action eq "Replace\n") { + if ($action eq "Replace\n") { $mpd->clear(); - my $line; - foreach my $line (split /\n/, $out) { - my $uri = (split /[\t\n]/, $line)[-1]; - $mpd->add($uri); - } + } + do_action($out); + if ($action eq "Replace\n") { $mpd->play(); } list_albums($rdb); @@ -179,24 +179,14 @@ sub list_tracks { } my $out = backend_call(\@output, "1,2,3,4"); - my @action_items = ("Add\n", "Insert\n", "Replace\n"); - my $action = backend_call(\@action_items); - - if ($action eq "Add\n") { - my $line; - foreach my $line (split /\n/, $out) { - my $uri = (split /[\t\n]/, $line)[-1]; - $mpd->add($uri); - } - } - elsif ($action eq "Replace\n") { + my @action_items = ("Add\n", "Replace\n"); + my $action = backend_call(\@action_items); + if ($action eq "Replace\n") { $mpd->clear(); - my $line; - foreach my $line (split /\n/, $out) { - my $uri = (split /[\t\n]/, $line)[-1]; - $mpd->add($uri); - } - $mpd->play(); + } + do_action($out); + if ($action eq "Replace\n") { + $mpd->play(); } list_tracks($rdb) } -- cgit v1.2.3-24-g4f1b