]> git.draconx.ca Git - mpdhacks.git/commitdiff
Factor out mpd_exec from some of the perl scripts.
authorNick Bowler <nbowler@draconx.ca>
Tue, 5 May 2020 04:41:14 +0000 (00:41 -0400)
committerNick Bowler <nbowler@draconx.ca>
Wed, 6 May 2020 01:27:34 +0000 (21:27 -0400)
The simple mpd_exec function can be easily moved into the MPDHacks
module.  Leave out the one in mpdexec.pl as it is more sophisticated
to handle things like binary downloads and probably not needed for
common code.

MPDHacks.pm
mpdmenu.pl
mpdreload.pl

index 94c0acc518dbad5067eb1c4456c4877ee169955d..0f5026eb237e7d9f60f3861cbbbc9d0cc6e268b9 100644 (file)
@@ -107,4 +107,12 @@ sub escape {
        return $s;
 }
 
+# Submit a command to the MPD server; each argument to this function
+# is quoted and sent as a single argument to MPD.
+sub exec {
+       my $cmd = join(' ', map { MPD::escape } @_);
+
+       print $sock "$cmd\n";
+}
+
 1;
index 4916d2a4ac09f0d25c8184226a5e7e30a50cd0b1..526772a92e6c13fe41c2b4c3e2739d07d16f5634 100755 (executable)
@@ -42,14 +42,6 @@ my ($topmenu, $menu);
 my $mode = "top";
 my %artistids;
 
-# Submit a command to the MPD server; each argument to this function
-# is quoted and sent as a single argument to MPD.
-sub mpd_exec {
-       my $cmd = join(' ', map { MPD::escape } @_);
-
-       print $sock "$cmd\n";
-}
-
 sub fvwm_cmd_unquoted {
        print join(' ', @_), "\n";
 }
@@ -281,7 +273,7 @@ sub get_tracks_by_work_mbid {
        my $entry;
 
        foreach my $mbid (@_) {
-               mpd_exec("search", "(MUSICBRAINZ_WORKID == \"$mbid\")");
+               MPD::exec("search", "(MUSICBRAINZ_WORKID == \"$mbid\")");
                while (<$sock>) {
                        last if (/^OK/);
                        die($_) if (/^ACK/);
@@ -310,13 +302,13 @@ sub get_tracks_by_work_mbid {
 # Currently tracks are considered "related" if their associated recordings
 # have at least one work in common.
 sub get_tracks_by_track_mbid {
-       my ($mbid) = @_;
+       my ($mbid, $tagname) = (@_, "MUSICBRAINZ_RELEASETRACKID");
        my %source;
        my %matches;
        my $entry;
 
        return \%matches unless ($mbid);
-       mpd_exec("search", "(MUSICBRAINZ_RELEASETRACKID == \"$mbid\")");
+       MPD::exec("search", "(MUSICBRAINZ_RELEASETRACKID == \"$mbid\")");
        while (<$sock>) {
                last if (/^OK/);
                die($_) if (/^ACK/);
@@ -348,7 +340,7 @@ sub get_tracks_by_release_mbid {
        my $entry;
 
        return \%matches unless ($mbid);
-       mpd_exec("search", "(MUSICBRAINZ_ALBUMID == \"$mbid\")");
+       MPD::exec("search", "(MUSICBRAINZ_ALBUMID == \"$mbid\")");
        while (<$sock>) {
                last if (/^OK/);
                die($_) if (/^ACK/);
@@ -380,7 +372,7 @@ sub get_releases_by_artist_mbid {
        my $entry;
 
        foreach my $mbid (@_) {
-               mpd_exec("search", "(MUSICBRAINZ_ARTISTID == \"$mbid\")");
+               MPD::exec("search", "(MUSICBRAINZ_ARTISTID == \"$mbid\")");
                while (<$sock>) {
                        last if (/^OK/);
                        die($_) if (/^ACK/);
@@ -406,7 +398,7 @@ sub get_ids_by_filename {
        my ($file) = @_;
        my @results = ();
 
-       mpd_exec("playlistfind", "file", $file);
+       MPD::exec("playlistfind", "file", $file);
        while (<$sock>) {
                last if (/^OK/);
                die($_) if (/^ACK/);
@@ -516,7 +508,7 @@ if ($mode eq "top") {
 
        $menu //= "MenuMPD";
 
-       mpd_exec("status");
+       MPD::exec("status");
        while (<$sock>) {
                last if (/^OK/);
                die($_) if (/^ACK/);
@@ -526,7 +518,7 @@ if ($mode eq "top") {
                }
        }
 
-       mpd_exec("currentsong");
+       MPD::exec("currentsong");
        while (<$sock>) {
                last if (/^OK/);
                die($_) if (/^ACK/);
index ba822ae9de8cf05946038d43472726e59b5bc4d5..6305783947fe63e1fe33499e119647c50c8b0fee 100755 (executable)
@@ -26,21 +26,13 @@ use MPDHacks;
 
 my $sock;
 
-# Submit a command to the MPD server; each argument to this function
-# is quoted and sent as a single argument to MPD.
-sub mpd_exec {
-       my $cmd = join(' ', map { MPD::escape } @_);
-
-       print $sock "$cmd\n";
-}
-
 # Returns a hash reference containing all tracks in the current play queue.
 # The hash keys are filenames.
 sub get_tracks_in_play_queue {
        my %matches;
        my $entry;
 
-       mpd_exec("playlistinfo");
+       MPD::exec("playlistinfo");
        while (<$sock>) {
                last if /^OK/;
                die($_) if /^ACK/;
@@ -72,7 +64,7 @@ sub get_playlist_files {
        my ($plname) = @_;
        my @files;
 
-       mpd_exec("listplaylist", $plname);
+       MPD::exec("listplaylist", $plname);
        while (<$sock>) {
                last if /^OK/;
                die($_) if /^ACK/;
@@ -140,7 +132,7 @@ $sock = MPD::connect();
 my $current = get_tracks_in_play_queue();
 my $target = get_playlist_files($ARGV[0]);
 
-mpd_exec("command_list_begin");
+MPD::exec("command_list_begin");
 for (my $i = 0; $i < @$target; $i++) {
        my $f = $target->[$i];
        my $ids = $current->{$f}->{Id};
@@ -152,9 +144,9 @@ for (my $i = 0; $i < @$target; $i++) {
        delete $current->{$f} unless (keys %$ids > 0);
 
        if (defined $id) {
-               mpd_exec("moveid", $id, $i);
+               MPD::exec("moveid", $id, $i);
        } else {
-               mpd_exec("addid", $f, $i);
+               MPD::exec("addid", $f, $i);
        }
 }
 
@@ -162,11 +154,11 @@ for (my $i = 0; $i < @$target; $i++) {
 foreach (keys %$current) {
        my $ids = $current->{$_}->{Id};
        foreach (keys %$ids) {
-               mpd_exec("deleteid", $_);
+               MPD::exec("deleteid", $_);
        }
 }
 
-mpd_exec("command_list_end");
+MPD::exec("command_list_end");
 while (<$sock>) {
        last if /^OK$/;
        die($_) if /^ACK/;