summaryrefslogtreecommitdiffstats
path: root/clerk.pl
diff options
context:
space:
mode:
authorRasmus Steinke <rasi@xssn.at>2017-08-03 20:44:39 +0200
committerRasmus Steinke <rasi@xssn.at>2017-08-03 20:44:39 +0200
commitd9dde458c07d3b2f32356692eea4fd353b2b6c79 (patch)
treedf43b9e3a83b234b018a96f8dc1ecd817cb9a573 /clerk.pl
parentdbbaf8a82ad4a24591fb2273a8a27d324e86cd80 (diff)
downloadperl-app-clerk-d9dde458c07d3b2f32356692eea4fd353b2b6c79.tar.gz
perl-app-clerk-d9dde458c07d3b2f32356692eea4fd353b2b6c79.tar.xz
unify adding of tracks for both album and track
Diffstat (limited to 'clerk.pl')
-rwxr-xr-x[-rw-r--r--]clerk.pl56
1 files changed, 23 insertions, 33 deletions
diff --git a/clerk.pl b/clerk.pl
index d54d815..b77dd9c 100644..100755
--- 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)
}