]> git.draconx.ca Git - mpdhacks.git/blobdiff - mpdreload.pl
Factor out mpd_exec from some of the perl scripts.
[mpdhacks.git] / mpdreload.pl
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/;